Browse Source

fix tests and optimize authentication and fix some unclosed markup

pull/27/head
Di Wu 9 years ago
parent
commit
79b7327c9e
24 changed files with 31 additions and 16 deletions
  1. +4
    -6
      hc/accounts/backends.py
  2. +1
    -1
      hc/api/management/commands/sendalerts.py
  3. +1
    -0
      hc/front/tests/test_add_channel.py
  4. +1
    -0
      hc/front/tests/test_add_check.py
  5. +1
    -0
      hc/front/tests/test_channel_checks.py
  6. +1
    -0
      hc/front/tests/test_log.py
  7. +1
    -0
      hc/front/tests/test_my_checks.py
  8. +1
    -0
      hc/front/tests/test_remove_channel.py
  9. +1
    -0
      hc/front/tests/test_remove_check.py
  10. +1
    -0
      hc/front/tests/test_update_channel.py
  11. +1
    -0
      hc/front/tests/test_update_name.py
  12. +1
    -0
      hc/front/tests/test_update_timeout.py
  13. +1
    -0
      hc/front/tests/test_verify_email.py
  14. +2
    -2
      hc/front/views.py
  15. +1
    -0
      hc/payments/tests/test_billing.py
  16. +1
    -0
      hc/payments/tests/test_cancel_plan.py
  17. +1
    -0
      hc/payments/tests/test_create_plan.py
  18. +1
    -0
      hc/payments/tests/test_get_client_token.py
  19. +1
    -0
      hc/payments/tests/test_invoice.py
  20. +1
    -0
      hc/payments/tests/test_pricing.py
  21. +1
    -1
      templates/front/channel_checks.html
  22. +3
    -3
      templates/front/channels.html
  23. +2
    -2
      templates/front/my_checks.html
  24. +1
    -1
      templates/payments/pricing.html

+ 4
- 6
hc/accounts/backends.py View File

@ -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.get(pk=user_id)
except User.DoesNotExist:
return None
return User.objects.filter(pk=user_id).first()
class EmailBackend(BasicBackend): class EmailBackend(BasicBackend):


+ 1
- 1
hc/api/management/commands/sendalerts.py View File

@ -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")


+ 1
- 0
hc/front/tests/test_add_channel.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/front/tests/test_add_check.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/front/tests/test_channel_checks.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/front/tests/test_log.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/front/tests/test_my_checks.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/front/tests/test_remove_channel.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/front/tests/test_remove_check.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/front/tests/test_update_channel.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/front/tests/test_update_name.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/front/tests/test_update_timeout.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/front/tests/test_verify_email.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 2
- 2
hc/front/views.py View File

@ -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()


+ 1
- 0
hc/payments/tests/test_billing.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/payments/tests/test_cancel_plan.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/payments/tests/test_create_plan.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/payments/tests/test_get_client_token.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/payments/tests/test_invoice.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 0
hc/payments/tests/test_pricing.py View File

@ -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="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()


+ 1
- 1
templates/front/channel_checks.html View File

@ -4,7 +4,7 @@
{% csrf_token %} {% csrf_token %}
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</span></button>
<button type="button" class="close" data-dismiss="modal">&times;</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>


+ 3
- 3
templates/front/channels.html View File

@ -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">&times;</span></button>
<h4 class="remove-check-title">Remove Channel <span class="remove-channel-name"></h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
<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
@ -177,4 +177,4 @@
<script src="{% static 'js/bootstrap.min.js' %}"></script> <script src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="{% static 'js/channels.js' %}"></script> <script src="{% static 'js/channels.js' %}"></script>
{% endcompress %} {% endcompress %}
{% endblock %}
{% endblock %}

+ 2
- 2
templates/front/my_checks.html View File

@ -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">&times;</span></button>
<button type="button" class="close" data-dismiss="modal">&times;</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">&times;</span></button> <button type="button" class="close" data-dismiss="modal">&times;</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


+ 1
- 1
templates/payments/pricing.html View File

@ -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">&times;</span></button>
<button type="button" class="close" data-dismiss="modal">&times;</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…
Cancel
Save