From 707b7b76dbecaeca689313d39ca86b7f1ee53e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Thu, 14 May 2020 21:23:25 +0200 Subject: [PATCH] Make events tests deterministic --- events/tests/test_views.py | 30 +++++++++++++----------------- events/views.py | 2 +- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/events/tests/test_views.py b/events/tests/test_views.py index a8b4ba4a..3e13d8cd 100644 --- a/events/tests/test_views.py +++ b/events/tests/test_views.py @@ -140,21 +140,17 @@ class CSVExportContentTest(MessagePatch, CSVResponseMixin, TestCase): ) response = self.client.get(self.url) - content = self._load_from_csv_response(response, as_dict=True) - toto_dict = dict(content[0]) - - # This is not super nice, but it makes the test deterministic. - toto_dict["def"] = set(x.strip() for x in toto_dict["def"].split("&")) - - self.assertDictEqual( - toto_dict, - { - "username": "toto_foo", - "prénom": "toto", - "nom de famille": "foo", - "email": "toto@a.b", - "abc": "a", - "def": {"d", "f"}, - "remarks": "hello", - }, + self.assertCSVEqual( + response, + [ + { + "username": "toto_foo", + "prénom": "toto", + "nom de famille": "foo", + "email": "toto@a.b", + "abc": "a", + "def": "d & f", + "remarks": "hello", + } + ], ) diff --git a/events/views.py b/events/views.py index 248c4284..b47ae76f 100644 --- a/events/views.py +++ b/events/views.py @@ -38,7 +38,7 @@ def participants_csv(request, event_id): # Options all_choices = registration.options_choices.values_list("choice", flat=True) options_choices = [ - " & ".join(all_choices.filter(option__id=id)) + " & ".join(all_choices.filter(option__id=id).order_by("id")) for id in event.options.values_list("id", flat=True).order_by("id") ] row += options_choices