Skip to content

Commit

Permalink
Razzia correct member stats (#529)
Browse files Browse the repository at this point in the history
* Add unique member count to members page

* Correct term on menu page

* Fix tests by updating expected result

* Add testing for unique members
  • Loading branch information
krestenlaust authored Nov 29, 2024
1 parent 0da7456 commit 4d76a80
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion razzia/templates/members.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{% block razzia_content %}
<p><a href="../{{razzia.pk}}">Back to razzia</a></p>
<h2>Registered members at razzia {{ razzia.start_date | date:"D d M Y" }} - {{ razzia.members.all | length }} fember(s)</h2>
<h2>Registered members at razzia {{ razzia.start_date | date:"D d M Y" }} - {{ razzia.members.all | length }} entries / {{ unique_members }} fember(s)</h2>
{% for entry in razzia.razziaentry_set.all %}
<ul>
<li>{{ entry.member.firstname }} {{ entry.member.lastname }} ({{ entry.member.username }}) at {{entry.time}}</li>
Expand Down
2 changes: 1 addition & 1 deletion razzia/templates/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h2>Previous razzias</h2>
<a href="./{{ razzia.pk }}">
<div class="searcher top rounded">
<div class="titlebar">
<h1>{{ razzia.start_date | date:"D d M Y" }} - {{razzia.members.all | length}} fember(s)</h1>
<h1>{{ razzia.start_date | date:"D d M Y" }} - {{razzia.members.all | length}} entries</h1>
</div>
</div>
</a>
Expand Down
50 changes: 48 additions & 2 deletions razzia/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def test_razzia_member_can_register_multiple_times(self):
# Note: Different interface, should be fixed later.
# self.assertNotContains(response_add_1, "last checked in at", status_code=200)
# self.assertContains(response_add_2, "last checked in at", status_code=200)
self.assertContains(response_members_0, "0 fember(s)", status_code=200)
self.assertContains(response_members_2, "2 fember(s)", status_code=200)
self.assertContains(response_members_0, "0 entr", status_code=200)
self.assertContains(response_members_2, "2 entr", status_code=200)

def test_razzia_registered_member_is_in_member_list(self):
self.client.login(username="tester", password="treotreo")
Expand All @@ -75,3 +75,49 @@ def test_razzia_registered_member_is_in_member_list(self):
self.assertEqual(response_add.status_code, 200)
self.assertTemplateUsed(response_members, "members.html")
self.assertContains(response_members, "jokke", status_code=200)

def test_razzia_unique_members_unique(self):
self.client.login(username="tester", password="treotreo")
response = self.client.get(reverse("razzia_new"), follow=True)
razzia_url, _ = response.redirect_chain[-1]

response_add = self.client.post(razzia_url, {"username": "jokke"}, follow=True)
self.assertEqual(response_add.status_code, 200)

response_members = self.client.get(razzia_url + "members", follow=True)

self.assertTemplateUsed(response_members, "members.html")
self.assertContains(response_members, "jokke", status_code=200)

response_add_2 = self.client.post(razzia_url, {"username": "jan"}, follow=True)
self.assertEqual(response_add_2.status_code, 200)

response_members_2 = self.client.get(razzia_url + "members", follow=True)
self.assertTemplateUsed(response_members, "members.html")
self.assertContains(response_members, "jan", status_code=200)

self.assertContains(response_members_2, "2 entr", status_code=200)
self.assertContains(response_members_2, "2 fember(s)", status_code=200)

def test_razzia_unique_members_same(self):
with freeze_time() as frozen_datetime:
self.client.login(username="tester", password="treotreo")
response = self.client.get(reverse("razzia_new"), follow=True)
razzia_url, _ = response.redirect_chain[-1]

response_members_0 = self.client.get(razzia_url + "members", follow=True)

response_add_1 = self.client.post(razzia_url, {"username": "jokke"}, follow=True)
frozen_datetime.tick(delta=datetime.timedelta(hours=1, minutes=1))
response_add_2 = self.client.post(razzia_url, {"username": "jokke"}, follow=True)

response_members_2 = self.client.get(razzia_url + "members", follow=True)

self.assertEqual(response_add_1.status_code, 200)
self.assertEqual(response_add_2.status_code, 200)
self.assertTemplateUsed(response_add_1, "razzia.html")
self.assertTemplateUsed(response_add_2, "razzia.html")
self.assertContains(response_members_0, "0 entr", status_code=200)
self.assertContains(response_members_0, "0 fember(s)", status_code=200)
self.assertContains(response_members_2, "2 entr", status_code=200)
self.assertContains(response_members_2, "1 fember(s)", status_code=200)
1 change: 1 addition & 0 deletions razzia/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ def new_razzia(request):
@permission_required("stregreport.host_razzia")
def razzia_members(request, razzia_id, title=None):
razzia = get_object_or_404(Razzia, pk=razzia_id)
unique_members = razzia.members.all().distinct().count()
return render(request, 'members.html', locals())

0 comments on commit 4d76a80

Please sign in to comment.