From ba6995198b159b832c631146632941dcd1c7e745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 26 Feb 2018 12:49:25 +0200 Subject: [PATCH] Fix tests, lazy-load user's teams. --- hc/accounts/middleware.py | 2 +- hc/front/tests/test_my_checks.py | 6 +++--- hc/front/views.py | 2 +- templates/base.html | 6 ++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/hc/accounts/middleware.py b/hc/accounts/middleware.py index 857f6871..b40308b7 100644 --- a/hc/accounts/middleware.py +++ b/hc/accounts/middleware.py @@ -11,7 +11,7 @@ class TeamAccessMiddleware(object): teams_q = Profile.objects.filter(member__user_id=request.user.id) teams_q = teams_q.select_related("user") - request.teams = list(teams_q) + request.get_teams = lambda: list(teams_q) request.profile = Profile.objects.for_user(request.user) request.team = request.profile.team() diff --git a/hc/front/tests/test_my_checks.py b/hc/front/tests/test_my_checks.py index a5c1a780..24d2dde9 100644 --- a/hc/front/tests/test_my_checks.py +++ b/hc/front/tests/test_my_checks.py @@ -29,7 +29,7 @@ class MyChecksTestCase(BaseTestCase): self.assertContains(r, "icon-up") # Mobile - self.assertContains(r, "label-success") + self.assertContains(r, "label-up") def test_it_shows_red_check(self): self.check.last_ping = timezone.now() - td(days=3) @@ -43,7 +43,7 @@ class MyChecksTestCase(BaseTestCase): self.assertContains(r, "icon-down") # Mobile - self.assertContains(r, "label-danger") + self.assertContains(r, "label-down") def test_it_shows_amber_check(self): self.check.last_ping = timezone.now() - td(days=1, minutes=30) @@ -57,7 +57,7 @@ class MyChecksTestCase(BaseTestCase): self.assertContains(r, "icon-grace") # Mobile - self.assertContains(r, "label-warning") + self.assertContains(r, "label-grace") def test_it_hides_add_check_button(self): self.profile.check_limit = 0 diff --git a/hc/front/views.py b/hc/front/views.py index 62d7cf55..18b6b86e 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -79,7 +79,7 @@ def my_checks(request): @login_required def status(request): - checks = list(Check.objects.filter(user=request.team.user)) + checks = list(Check.objects.filter(user_id=request.team.user_id)) details = [] for check in checks: diff --git a/templates/base.html b/templates/base.html index 4d9cf4e9..84f29f02 100644 --- a/templates/base.html +++ b/templates/base.html @@ -122,7 +122,8 @@ {{ request.team }}