Fix event tests
This commit is contained in:
parent
3b43ad84b5
commit
65171d1276
1 changed files with 37 additions and 17 deletions
|
@ -1,4 +1,3 @@
|
|||
import csv
|
||||
from unittest import mock
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
|
@ -14,6 +13,7 @@ from events.models import (
|
|||
OptionChoice,
|
||||
Registration,
|
||||
)
|
||||
from shared.tests.mixins import CSVResponseMixin
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
@ -70,7 +70,7 @@ class CSVExportAccessTest(MessagePatch, TestCase):
|
|||
self.assertEqual(r.status_code, 403)
|
||||
|
||||
|
||||
class CSVExportContentTest(MessagePatch, TestCase):
|
||||
class CSVExportContentTest(MessagePatch, CSVResponseMixin, TestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
|
@ -90,13 +90,26 @@ class CSVExportContentTest(MessagePatch, TestCase):
|
|||
def test_simple_event(self):
|
||||
self.event.subscribers.set([self.u1, self.u2])
|
||||
|
||||
participants = self.client.get(self.url).content.decode("utf-8")
|
||||
participants = [
|
||||
line for line in csv.reader(participants.split("\n")) if line != []
|
||||
]
|
||||
self.assertEqual(len(participants), 3)
|
||||
self.assertEqual(participants[1], ["toto_foo", "toto@a.b", "toto", "foo"])
|
||||
self.assertEqual(participants[2], ["titi_bar", "titi@a.b", "titi", "bar"])
|
||||
response = self.client.get(self.url)
|
||||
|
||||
content = self.load_from_csv_response(response, as_dict=True)
|
||||
self.assertListEqual(
|
||||
content,
|
||||
[
|
||||
{
|
||||
"username": "toto_foo",
|
||||
"prénom": "toto",
|
||||
"nom de famille": "foo",
|
||||
"email": "toto@a.b",
|
||||
},
|
||||
{
|
||||
"username": "titi_bar",
|
||||
"prénom": "titi",
|
||||
"nom de famille": "bar",
|
||||
"email": "titi@a.b",
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
def test_complex_event(self):
|
||||
registration = Registration.objects.create(event=self.event, user=self.u1)
|
||||
|
@ -127,15 +140,22 @@ class CSVExportContentTest(MessagePatch, TestCase):
|
|||
field=field, registration=registration, content="hello"
|
||||
)
|
||||
|
||||
participants = self.client.get(self.url).content.decode("utf-8")
|
||||
participants = list(csv.reader(participants.split("\n")))
|
||||
toto_registration = participants[1]
|
||||
response = self.client.get(self.url)
|
||||
content = self.load_from_csv_response(response, as_dict=True)
|
||||
toto_dict = content[0]
|
||||
|
||||
# This is not super nice, but it makes the test deterministic.
|
||||
if toto_registration[5] == "f & d":
|
||||
toto_registration[5] = "d & f"
|
||||
toto_dict["def"] = [x.strip() for x in toto_dict["def"].split("&")]
|
||||
|
||||
self.assertEqual(
|
||||
["toto_foo", "toto@a.b", "toto", "foo", "a", "d & f", "hello"],
|
||||
toto_registration,
|
||||
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",
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue