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