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