MegaHelpers devient un mixin

This commit is contained in:
Ludovic Stephan 2020-05-10 23:56:45 +02:00
parent bbe831a226
commit 88c9187e2e
2 changed files with 52 additions and 46 deletions

View file

@ -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"

View file

@ -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.