From d9bdc394a4b9cdc3cf757b74def98fa278882d8e Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Tue, 13 Aug 2024 21:54:18 +0200 Subject: [PATCH] Bugfix broken event change list, if no events exists --- README.md | 1 + for_runners/admin/event.py | 4 +-- for_runners_project/tests/test_admin_event.py | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 for_runners_project/tests/test_admin_event.py diff --git a/README.md b/README.md index dddd962..82b93df 100644 --- a/README.md +++ b/README.md @@ -223,6 +223,7 @@ Because this is a project and not really a reuse-able-app ;) [comment]: <> (✂✂✂ auto generated history start ✂✂✂) * [v0.20.0.dev0](https://github.com/jedie/django-for-runners/compare/v0.19.0...v0.20.0.dev0) + * 2024-08-13 - Bugfix broken event change list, if no events exists * 2024-08-13 - Allow facets in GPX change list * 2024-08-13 - Dump Version * 2024-08-13 - Update README diff --git a/for_runners/admin/event.py b/for_runners/admin/event.py index 775646b..d1f873b 100644 --- a/for_runners/admin/event.py +++ b/for_runners/admin/event.py @@ -85,7 +85,7 @@ def get(self, events): # turn defaultdict and counter to normal dict and convert some values: - total_costs = collections.Counter() + total_costs = collections.Counter(total=0) # pprint(raw_person_data) person_data = {} @@ -106,7 +106,7 @@ def get(self, events): else: # costs item # collect total costs: - total_costs += collections.Counter({"total": value, key: value}) + total_costs.update({"total": value, key: value}) # convert decimal field: value = convert_cash_values(value) diff --git a/for_runners_project/tests/test_admin_event.py b/for_runners_project/tests/test_admin_event.py new file mode 100644 index 0000000..56d3ef2 --- /dev/null +++ b/for_runners_project/tests/test_admin_event.py @@ -0,0 +1,25 @@ +from bx_django_utils.test_utils.html_assertion import HtmlAssertionMixin +from django.contrib.auth.models import User +from django.test import TestCase +from model_bakery import baker + + +class AdminEventParticipationTests(HtmlAssertionMixin, TestCase): + @classmethod + def setUpTestData(cls): + cls.superuser = baker.make(User, username='superuser', is_staff=True, is_active=True, is_superuser=True) + + def test_event_change_list(self): + self.client.force_login(self.superuser) + response = self.client.get("/en/admin/for_runners/eventmodel/", HTTP_ACCEPT_LANGUAGE="en") + self.assertEqual(response.status_code, 200) + self.assert_html_parts( + response, + parts=( + "superuser", + 'ForRunners', + '

0 Events

', + ), + ) + self.assertTemplateUsed(response, template_name="admin/for_runners/eventmodel/statistics.html") + self.assertTemplateUsed(response, template_name="admin/for_runners/eventmodel/change_list.html")