forked from GithubBackups/healthchecks
Merge pull request #27 from BetterWorks/optimization
fix tests and optimize authentication and fix some unclosed markup
This commit is contained in:
commit
7f2aa9e97c
@ -3,7 +3,7 @@ from django.contrib.auth.models import User
|
||||
from hc.accounts.models import Profile
|
||||
|
||||
|
||||
class BasicBackend:
|
||||
class BasicBackend(object):
|
||||
|
||||
def get_user(self, user_id):
|
||||
try:
|
||||
@ -17,7 +17,8 @@ class ProfileBackend(BasicBackend):
|
||||
|
||||
def authenticate(self, username=None, token=None):
|
||||
try:
|
||||
profile = Profile.objects.get(user__username=username)
|
||||
profile = (Profile.objects
|
||||
.select_related("user").get(user__username=username))
|
||||
except Profile.DoesNotExist:
|
||||
return None
|
||||
|
||||
@ -27,10 +28,7 @@ class ProfileBackend(BasicBackend):
|
||||
return profile.user
|
||||
|
||||
def get_user(self, user_id):
|
||||
try:
|
||||
return User.objects.get(pk=user_id)
|
||||
except User.DoesNotExist:
|
||||
return None
|
||||
return User.objects.filter(pk=user_id).first()
|
||||
|
||||
|
||||
class EmailBackend(BasicBackend):
|
||||
|
@ -16,7 +16,7 @@ class Command(BaseCommand):
|
||||
|
||||
def handle_many(self):
|
||||
""" Send alerts for many checks simultaneously. """
|
||||
query = Check.objects.filter(user__isnull=False)
|
||||
query = Check.objects.filter(user__isnull=False).select_related("user")
|
||||
|
||||
now = timezone.now()
|
||||
going_down = query.filter(alert_after__lt=now, status="up")
|
||||
|
@ -7,6 +7,7 @@ from hc.api.models import Channel
|
||||
class AddChannelTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(AddChannelTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -6,6 +6,7 @@ from hc.api.models import Check
|
||||
class AddCheckTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(AddCheckTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -6,6 +6,7 @@ from hc.api.models import Channel
|
||||
class ChannelChecksTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ChannelChecksTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -6,6 +6,7 @@ from hc.api.models import Check, Ping
|
||||
class LogTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(LogTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -6,6 +6,7 @@ from hc.api.models import Check
|
||||
class MyChecksTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(MyChecksTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -6,6 +6,7 @@ from hc.api.models import Channel
|
||||
class RemoveChannelTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(RemoveChannelTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -6,6 +6,7 @@ from hc.api.models import Check
|
||||
class RemoveCheckTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(RemoveCheckTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -6,6 +6,7 @@ from hc.api.models import Channel, Check
|
||||
class UpdateChannelTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(UpdateChannelTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -6,6 +6,7 @@ from hc.api.models import Check
|
||||
class UpdateNameTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(UpdateNameTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -6,6 +6,7 @@ from hc.api.models import Check
|
||||
class UpdateTimeoutTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(UpdateTimeoutTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -6,6 +6,7 @@ from hc.api.models import Channel
|
||||
class VerifyEmailTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(VerifyEmailTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -30,7 +30,7 @@ def my_checks(request):
|
||||
|
||||
counter = Counter()
|
||||
down_tags, grace_tags = set(), set()
|
||||
for check in checks:
|
||||
for check in checks.iterator():
|
||||
status = check.get_status()
|
||||
for tag in check.tags_list():
|
||||
if tag == "":
|
||||
@ -196,7 +196,7 @@ def log(request, code):
|
||||
limit = profile.ping_log_limit
|
||||
pings = Ping.objects.filter(owner=check).order_by("-id")[:limit]
|
||||
|
||||
pings = list(pings)
|
||||
pings = list(pings.iterator())
|
||||
# oldest-to-newest order will be more convenient for adding
|
||||
# "not received" placeholders:
|
||||
pings.reverse()
|
||||
|
@ -7,6 +7,7 @@ from mock import Mock, patch
|
||||
class BillingTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(BillingTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -7,6 +7,7 @@ from mock import patch
|
||||
class CancelPlanTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(CancelPlanTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -8,6 +8,7 @@ from mock import patch
|
||||
class CreatePlanTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(CreatePlanTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -7,6 +7,7 @@ from mock import patch
|
||||
class GetClientTokenTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(GetClientTokenTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -7,6 +7,7 @@ from mock import Mock, patch
|
||||
class InvoiceTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(InvoiceTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -6,6 +6,7 @@ from hc.payments.models import Subscription
|
||||
class PricingTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(PricingTestCase, self).setUp()
|
||||
self.alice = User(username="alice", email="alice@example.org")
|
||||
self.alice.set_password("password")
|
||||
self.alice.save()
|
||||
|
@ -4,7 +4,7 @@
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</span></button>
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="update-timeout-title">Assign Checks to Channel {% if channel.kind == "po" %}{{ channel.po_value|join:" / " }}{% else %}{{ channel.value }}{% endif %}</h4>
|
||||
</div>
|
||||
|
||||
|
@ -149,8 +149,8 @@
|
||||
{% csrf_token %}
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</span></button>
|
||||
<h4 class="remove-check-title">Remove Channel <span class="remove-channel-name"></h4>
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="remove-check-title">Remove Channel <span class="remove-channel-name"></span></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>You are about to remove channel
|
||||
@ -177,4 +177,4 @@
|
||||
<script src="{% static 'js/bootstrap.min.js' %}"></script>
|
||||
<script src="{% static 'js/channels.js' %}"></script>
|
||||
{% endcompress %}
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
@ -52,7 +52,7 @@
|
||||
{% csrf_token %}
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</span></button>
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="update-timeout-title">Name and Tags</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@ -172,7 +172,7 @@
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</span></button>
|
||||
<h4 class="remove-check-title">Remove Check <span class="remove-check-name"></h4>
|
||||
<h4 class="remove-check-title">Remove Check <span class="remove-check-name"></span></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>You are about to remove check
|
||||
|
@ -208,7 +208,7 @@
|
||||
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</span></button>
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4>Set Up Subscription</h4>
|
||||
</div>
|
||||
<div class="modal-body" id="payment-method-body">
|
||||
|
Loading…
x
Reference in New Issue
Block a user