forked from DGNum/gestioCOF
160 lines
4.7 KiB
Python
160 lines
4.7 KiB
Python
import csv
|
|
|
|
from django.test import TestCase
|
|
|
|
from gestioncof.models import Event
|
|
from gestioncof.tests.testcases import ViewTestCaseMixin
|
|
|
|
from .utils import create_user
|
|
|
|
|
|
class ExportMembersViewTests(ViewTestCaseMixin, TestCase):
|
|
url_name = 'gestioncof.views.export_members'
|
|
url_expected = '/export/members'
|
|
|
|
auth_user = 'staff'
|
|
auth_forbidden = [None, 'user', 'member']
|
|
|
|
def test(self):
|
|
u1, u2 = self.users['member'], self.users['staff']
|
|
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.save()
|
|
|
|
r = self.client.get(self.url)
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
data = list(csv.reader(r.content.decode('utf-8').split('\n')[:-1]))
|
|
self.assertListEqual(data, [
|
|
[
|
|
str(u1.pk), 'member', 'first', 'last', 'user@mail.net',
|
|
'0123456789', '1A', 'Dept', 'normalien',
|
|
],
|
|
[str(u2.pk), 'staff', '', '', '', '', '1A', '', 'normalien'],
|
|
])
|
|
|
|
|
|
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 2017')
|
|
|
|
cf1 = m.commentfields.create(name='Commentaire')
|
|
cf2 = m.commentfields.create(
|
|
name='Comment Field 2', fieldtype='char',
|
|
)
|
|
|
|
option_type = m.options.create(name='Conscrit/Orga ?')
|
|
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):
|
|
url_name = 'gestioncof.views.export_mega'
|
|
url_expected = '/export/mega'
|
|
|
|
auth_user = 'staff'
|
|
auth_forbidden = [None, 'user', 'member']
|
|
|
|
def test(self):
|
|
r = self.client.get(self.url)
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
self.assertListEqual(self.load_from_csv_response(r), [
|
|
[
|
|
'u1', 'first', 'last', 'user@mail.net', '0123456789',
|
|
str(self.u1.pk), 'profile.comments', 'Comment 1---Comment 2',
|
|
],
|
|
['u2', '', '', '', '', str(self.u2.pk), '', ''],
|
|
])
|
|
|
|
|
|
class ExportMegaOrgasViewTests(MegaHelpers, ViewTestCaseMixin, TestCase):
|
|
url_name = 'gestioncof.views.export_mega_orgas'
|
|
url_expected = '/export/mega/orgas'
|
|
|
|
auth_user = 'staff'
|
|
auth_forbidden = [None, 'user', 'member']
|
|
|
|
def test(self):
|
|
|
|
r = self.client.get(self.url)
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
self.assertListEqual(self.load_from_csv_response(r), [
|
|
[
|
|
'u1', 'first', 'last', 'user@mail.net', '0123456789',
|
|
str(self.u1.pk), 'profile.comments', 'Comment 1---Comment 2',
|
|
],
|
|
])
|
|
|
|
|
|
class ExportMegaParticipantsViewTests(
|
|
MegaHelpers, ViewTestCaseMixin, TestCase):
|
|
url_name = 'gestioncof.views.export_mega_participants'
|
|
url_expected = '/export/mega/participants'
|
|
|
|
auth_user = 'staff'
|
|
auth_forbidden = [None, 'user', 'member']
|
|
|
|
def test(self):
|
|
r = self.client.get(self.url)
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
self.assertListEqual(self.load_from_csv_response(r), [
|
|
['u2', '', '', '', '', str(self.u2.pk), '', ''],
|
|
])
|
|
|
|
|
|
class ExportMegaRemarksViewTests(
|
|
MegaHelpers, ViewTestCaseMixin, TestCase):
|
|
url_name = 'gestioncof.views.export_mega_remarksonly'
|
|
url_expected = '/export/mega/avecremarques'
|
|
|
|
auth_user = 'staff'
|
|
auth_forbidden = [None, 'user', 'member']
|
|
|
|
def test(self):
|
|
r = self.client.get(self.url)
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
self.assertListEqual(self.load_from_csv_response(r), [
|
|
[
|
|
'u1', 'first', 'last', 'user@mail.net', '0123456789',
|
|
str(self.u1.pk), 'profile.comments', 'Comment 1',
|
|
],
|
|
])
|