Browse Source

Fix tests, lazy-load user's teams.

pull/163/head
Pēteris Caune 7 years ago
parent
commit
ba6995198b
4 changed files with 9 additions and 7 deletions
  1. +1
    -1
      hc/accounts/middleware.py
  2. +3
    -3
      hc/front/tests/test_my_checks.py
  3. +1
    -1
      hc/front/views.py
  4. +4
    -2
      templates/base.html

+ 1
- 1
hc/accounts/middleware.py View File

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


+ 3
- 3
hc/front/tests/test_my_checks.py View File

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


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

@ -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:


+ 4
- 2
templates/base.html View File

@ -122,7 +122,8 @@
{{ request.team }} <span class="caret"></span>
</a>
<ul class="dropdown-menu">
{% if request.teams %}
{% with teams=request.get_teams %}
{% if teams %}
<li class="dropdown-header">{{ request.user.profile }}</li>
<li>
<a href="{% url 'hc-switch-team' request.user.username %}" class="active">Checks</a>
@ -132,7 +133,7 @@
<li><a href="{% url 'hc-profile' %}">Account Settings</a></li>
<li role="separator" class="divider"></li>
{% for team in request.teams %}
{% for team in teams %}
<li class="dropdown-header">{{ team }}</li>
<li>
<a href="{% url 'hc-switch-team' team.user.username %}">Checks</a>
@ -141,6 +142,7 @@
{% endfor %}
<li><a href="{% url 'hc-logout' %}">Log Out</a></li>
{% endwith %}
</ul>
</li>
</ul>


Loading…
Cancel
Save