diff --git a/gestioncof/tests/test_views.py b/gestioncof/tests/test_views.py index 7a21fafe..37f105fd 100644 --- a/gestioncof/tests/test_views.py +++ b/gestioncof/tests/test_views.py @@ -16,7 +16,7 @@ from django.urls import reverse from bda.models import Salle, Tirage from gestioncof.models import CalendarSubscription, Club, Event, Survey, SurveyAnswer -from gestioncof.tests.testcases import ViewTestCaseMixin +from gestioncof.tests.testcases import MegaHelperMixin, ViewTestCaseMixin from shared.tests.testcases import ICalMixin, MockLDAPMixin from shared.views.autocomplete import Clipper @@ -505,48 +505,7 @@ class ExportMembersViewTests(ViewTestCaseMixin, TestCase): self.assertListEqual(data, expected) -class MegaHelpers: - def setUp(self): - super().setUp() - - u1 = create_user("u1") - u1.first_name = "first" - u1.last_name = "last" - u1.email = "user@mail.net" - u1.save() - u1.profile.phone = "0123456789" - u1.profile.departement = "Dept" - u1.profile.comments = "profile.comments" - u1.profile.save() - - u2 = create_user("u2") - u2.profile.save() - - m = Event.objects.create(title="MEGA 2018") - - cf1 = m.commentfields.create(name="Commentaires") - cf2 = m.commentfields.create(name="Comment Field 2", fieldtype="char") - - option_type = m.options.create(name="Orga ? Conscrit ?") - choice_orga = option_type.choices.create(value="Orga") - choice_conscrit = option_type.choices.create(value="Conscrit") - - mr1 = m.eventregistration_set.create(user=u1) - mr1.options.add(choice_orga) - mr1.comments.create(commentfield=cf1, content="Comment 1") - mr1.comments.create(commentfield=cf2, content="Comment 2") - - mr2 = m.eventregistration_set.create(user=u2) - mr2.options.add(choice_conscrit) - - self.u1 = u1 - self.u2 = u2 - self.m = m - self.choice_orga = choice_orga - self.choice_conscrit = choice_conscrit - - -class ExportMegaViewTests(MegaHelpers, ViewTestCaseMixin, TestCase): +class ExportMegaViewTests(MegaHelperMixin, ViewTestCaseMixin, TestCase): url_name = "cof.mega_export" url_expected = "/export/mega" @@ -575,7 +534,7 @@ class ExportMegaViewTests(MegaHelpers, ViewTestCaseMixin, TestCase): ) -class ExportMegaOrgasViewTests(MegaHelpers, ViewTestCaseMixin, TestCase): +class ExportMegaOrgasViewTests(MegaHelperMixin, ViewTestCaseMixin, TestCase): url_name = "cof.mega_export_orgas" url_expected = "/export/mega/orgas" @@ -604,7 +563,7 @@ class ExportMegaOrgasViewTests(MegaHelpers, ViewTestCaseMixin, TestCase): ) -class ExportMegaParticipantsViewTests(MegaHelpers, ViewTestCaseMixin, TestCase): +class ExportMegaParticipantsViewTests(MegaHelperMixin, ViewTestCaseMixin, TestCase): url_name = "cof.mega_export_participants" url_expected = "/export/mega/participants" @@ -621,7 +580,7 @@ class ExportMegaParticipantsViewTests(MegaHelpers, ViewTestCaseMixin, TestCase): ) -class ExportMegaRemarksViewTests(MegaHelpers, ViewTestCaseMixin, TestCase): +class ExportMegaRemarksViewTests(MegaHelperMixin, ViewTestCaseMixin, TestCase): url_name = "cof.mega_export_remarks" url_expected = "/export/mega/avecremarques" diff --git a/gestioncof/tests/testcases.py b/gestioncof/tests/testcases.py index 6da8a28f..2c6cbb9d 100644 --- a/gestioncof/tests/testcases.py +++ b/gestioncof/tests/testcases.py @@ -1,3 +1,4 @@ +from gestioncof.models import Event from shared.tests.testcases import ( CSVResponseMixin, ViewTestCaseMixin as BaseViewTestCaseMixin, @@ -6,6 +7,52 @@ from shared.tests.testcases import ( from .utils import create_member, create_staff, create_user +class MegaHelperMixin(CSVResponseMixin): + """ + Mixin pour aider aux tests du MEGA: création de l'event et de plusieurs + inscriptions, avec options et commentaires. + """ + + def setUp(self): + super().setUp() + + u1 = create_user("u1") + u1.first_name = "first" + u1.last_name = "last" + u1.email = "user@mail.net" + u1.save() + u1.profile.phone = "0123456789" + u1.profile.departement = "Dept" + u1.profile.comments = "profile.comments" + u1.profile.save() + + u2 = create_user("u2") + u2.profile.save() + + m = Event.objects.create(title="MEGA 2018") + + cf1 = m.commentfields.create(name="Commentaires") + cf2 = m.commentfields.create(name="Comment Field 2", fieldtype="char") + + option_type = m.options.create(name="Orga ? Conscrit ?") + choice_orga = option_type.choices.create(value="Orga") + choice_conscrit = option_type.choices.create(value="Conscrit") + + mr1 = m.eventregistration_set.create(user=u1) + mr1.options.add(choice_orga) + mr1.comments.create(commentfield=cf1, content="Comment 1") + mr1.comments.create(commentfield=cf2, content="Comment 2") + + mr2 = m.eventregistration_set.create(user=u2) + mr2.options.add(choice_conscrit) + + self.u1 = u1 + self.u2 = u2 + self.m = m + self.choice_orga = choice_orga + self.choice_conscrit = choice_conscrit + + class ViewTestCaseMixin(BaseViewTestCaseMixin): """ TestCase extension to ease testing of cof views.