mirror of https://gitlab.crans.org/bde/nk20
More tests in WEI app, but we can still go further
This commit is contained in:
parent
25e26fe8cf
commit
b7a88a387c
|
@ -5,17 +5,20 @@ from django import template
|
||||||
|
|
||||||
|
|
||||||
def pretty_money(value):
|
def pretty_money(value):
|
||||||
if value % 100 == 0:
|
try:
|
||||||
return "{:s}{:d} €".format(
|
if value % 100 == 0:
|
||||||
"- " if value < 0 else "",
|
return "{:s}{:d} €".format(
|
||||||
abs(value) // 100,
|
"- " if value < 0 else "",
|
||||||
)
|
abs(value) // 100,
|
||||||
else:
|
)
|
||||||
return "{:s}{:d}.{:02d} €".format(
|
else:
|
||||||
"- " if value < 0 else "",
|
return "{:s}{:d}.{:02d} €".format(
|
||||||
abs(value) // 100,
|
"- " if value < 0 else "",
|
||||||
abs(value) % 100,
|
abs(value) // 100,
|
||||||
)
|
abs(value) % 100,
|
||||||
|
)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return "0 €"
|
||||||
|
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
|
@ -82,5 +82,3 @@ class PermissionQueryTestCase(TestCase):
|
||||||
if instanced.query:
|
if instanced.query:
|
||||||
print("Compiled query:", instanced.query)
|
print("Compiled query:", instanced.query)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
print("All permission queries are well formed")
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
@ -15,6 +17,27 @@ from ..forms import CurrentSurvey
|
||||||
from ..models import WEIClub, Bus, BusTeam, WEIRole, WEIRegistration, WEIMembership
|
from ..models import WEIClub, Bus, BusTeam, WEIRole, WEIRegistration, WEIMembership
|
||||||
|
|
||||||
|
|
||||||
|
class TestWEIList(TestCase):
|
||||||
|
fixtures = ('initial',)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.user = User.objects.create_superuser(
|
||||||
|
username="weiadmin",
|
||||||
|
password="admin",
|
||||||
|
email="admin@example.com",
|
||||||
|
)
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
sess = self.client.session
|
||||||
|
sess["permission_mask"] = 42
|
||||||
|
sess.save()
|
||||||
|
|
||||||
|
def test_current_wei_detail(self):
|
||||||
|
"""
|
||||||
|
Test that when no WEI is created, the WEI button redirect to the WEI list
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("wei:current_wei_detail"))
|
||||||
|
self.assertRedirects(response, reverse("wei:wei_list"), 302, 200)
|
||||||
|
|
||||||
class TestWEIRegistration(TestCase):
|
class TestWEIRegistration(TestCase):
|
||||||
"""
|
"""
|
||||||
Test the whole WEI app
|
Test the whole WEI app
|
||||||
|
@ -43,11 +66,11 @@ class TestWEIRegistration(TestCase):
|
||||||
parent_club_id=2,
|
parent_club_id=2,
|
||||||
membership_fee_paid=12500,
|
membership_fee_paid=12500,
|
||||||
membership_fee_unpaid=5500,
|
membership_fee_unpaid=5500,
|
||||||
membership_start=str(self.year) + "-08-01",
|
membership_start=str(self.year) + "-01-01",
|
||||||
membership_end=str(self.year) + "-12-31",
|
membership_end=str(self.year) + "-12-31",
|
||||||
year=self.year,
|
year=self.year,
|
||||||
date_start=str(self.year) + "-09-01",
|
date_start=timezone.now().date() + timedelta(days=2),
|
||||||
date_end=str(self.year) + "-09-03",
|
date_end=str(self.year) + "-12-31",
|
||||||
)
|
)
|
||||||
NoteClub.objects.create(club=self.wei)
|
NoteClub.objects.create(club=self.wei)
|
||||||
self.bus = Bus.objects.create(
|
self.bus = Bus.objects.create(
|
||||||
|
@ -132,6 +155,12 @@ class TestWEIRegistration(TestCase):
|
||||||
self.assertRedirects(response, reverse("wei:wei_detail", kwargs=dict(pk=self.wei.pk)), 302, 200)
|
self.assertRedirects(response, reverse("wei:wei_detail", kwargs=dict(pk=self.wei.pk)), 302, 200)
|
||||||
self.assertTrue(qs.exists())
|
self.assertTrue(qs.exists())
|
||||||
|
|
||||||
|
# Check that if the WEI is started, we can't update a wei
|
||||||
|
self.wei.date_start = '2000-01-01'
|
||||||
|
self.wei.save()
|
||||||
|
response = self.client.get(reverse("wei:wei_update", kwargs=dict(pk=self.wei.pk)))
|
||||||
|
self.assertRedirects(response, reverse("wei:wei_closed", kwargs=dict(pk=self.wei.pk)), 302, 200)
|
||||||
|
|
||||||
def test_wei_closed(self):
|
def test_wei_closed(self):
|
||||||
"""
|
"""
|
||||||
Test display the page when a WEI is closed.
|
Test display the page when a WEI is closed.
|
||||||
|
@ -150,6 +179,9 @@ class TestWEIRegistration(TestCase):
|
||||||
"""
|
"""
|
||||||
Test create a new bus.
|
Test create a new bus.
|
||||||
"""
|
"""
|
||||||
|
response = self.client.get(reverse("wei:add_bus", kwargs=dict(pk=self.wei.pk)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
response = self.client.post(reverse("wei:add_bus", kwargs=dict(pk=self.wei.pk)), dict(
|
response = self.client.post(reverse("wei:add_bus", kwargs=dict(pk=self.wei.pk)), dict(
|
||||||
wei=self.wei.id,
|
wei=self.wei.id,
|
||||||
name="Create Bus Test",
|
name="Create Bus Test",
|
||||||
|
@ -160,6 +192,12 @@ class TestWEIRegistration(TestCase):
|
||||||
bus = qs.get()
|
bus = qs.get()
|
||||||
self.assertRedirects(response, reverse("wei:manage_bus", kwargs=dict(pk=bus.pk)), 302, 200)
|
self.assertRedirects(response, reverse("wei:manage_bus", kwargs=dict(pk=bus.pk)), 302, 200)
|
||||||
|
|
||||||
|
# Check that if the WEI is started, we can't create a bus
|
||||||
|
self.wei.date_start = '2000-01-01'
|
||||||
|
self.wei.save()
|
||||||
|
response = self.client.get(reverse("wei:add_bus", kwargs=dict(pk=self.wei.pk)))
|
||||||
|
self.assertRedirects(response, reverse("wei:wei_closed", kwargs=dict(pk=self.wei.pk)), 302, 200)
|
||||||
|
|
||||||
def test_detail_bus(self):
|
def test_detail_bus(self):
|
||||||
"""
|
"""
|
||||||
Test display the information about a bus.
|
Test display the information about a bus.
|
||||||
|
@ -171,6 +209,9 @@ class TestWEIRegistration(TestCase):
|
||||||
"""
|
"""
|
||||||
Test update a bus.
|
Test update a bus.
|
||||||
"""
|
"""
|
||||||
|
response = self.client.get(reverse("wei:update_bus", kwargs=dict(pk=self.bus.pk)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
response = self.client.post(reverse("wei:update_bus", kwargs=dict(pk=self.bus.pk)), dict(
|
response = self.client.post(reverse("wei:update_bus", kwargs=dict(pk=self.bus.pk)), dict(
|
||||||
name="Update Bus Test",
|
name="Update Bus Test",
|
||||||
description="This bus was updated.",
|
description="This bus was updated.",
|
||||||
|
@ -179,10 +220,19 @@ class TestWEIRegistration(TestCase):
|
||||||
self.assertRedirects(response, reverse("wei:manage_bus", kwargs=dict(pk=self.bus.pk)), 302, 200)
|
self.assertRedirects(response, reverse("wei:manage_bus", kwargs=dict(pk=self.bus.pk)), 302, 200)
|
||||||
self.assertTrue(qs.exists())
|
self.assertTrue(qs.exists())
|
||||||
|
|
||||||
|
# Check that if the WEI is started, we can't update a bus
|
||||||
|
self.wei.date_start = '2000-01-01'
|
||||||
|
self.wei.save()
|
||||||
|
response = self.client.get(reverse("wei:update_bus", kwargs=dict(pk=self.bus.pk)))
|
||||||
|
self.assertRedirects(response, reverse("wei:wei_closed", kwargs=dict(pk=self.wei.pk)), 302, 200)
|
||||||
|
|
||||||
def test_add_team(self):
|
def test_add_team(self):
|
||||||
"""
|
"""
|
||||||
Test create a new team.
|
Test create a new team.
|
||||||
"""
|
"""
|
||||||
|
response = self.client.get(reverse("wei:add_team", kwargs=dict(pk=self.bus.pk)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
response = self.client.post(reverse("wei:add_team", kwargs=dict(pk=self.bus.pk)), dict(
|
response = self.client.post(reverse("wei:add_team", kwargs=dict(pk=self.bus.pk)), dict(
|
||||||
bus=self.bus.id,
|
bus=self.bus.id,
|
||||||
name="Create Team Test",
|
name="Create Team Test",
|
||||||
|
@ -194,6 +244,12 @@ class TestWEIRegistration(TestCase):
|
||||||
team = qs.get()
|
team = qs.get()
|
||||||
self.assertRedirects(response, reverse("wei:manage_bus_team", kwargs=dict(pk=team.pk)), 302, 200)
|
self.assertRedirects(response, reverse("wei:manage_bus_team", kwargs=dict(pk=team.pk)), 302, 200)
|
||||||
|
|
||||||
|
# Check that if the WEI is started, we can't create a team
|
||||||
|
self.wei.date_start = '2000-01-01'
|
||||||
|
self.wei.save()
|
||||||
|
response = self.client.get(reverse("wei:add_team", kwargs=dict(pk=self.bus.pk)))
|
||||||
|
self.assertRedirects(response, reverse("wei:wei_closed", kwargs=dict(pk=self.wei.pk)), 302, 200)
|
||||||
|
|
||||||
def test_detail_team(self):
|
def test_detail_team(self):
|
||||||
"""
|
"""
|
||||||
Test display the detail about a team.
|
Test display the detail about a team.
|
||||||
|
@ -205,6 +261,9 @@ class TestWEIRegistration(TestCase):
|
||||||
"""
|
"""
|
||||||
Test update a team.
|
Test update a team.
|
||||||
"""
|
"""
|
||||||
|
response = self.client.get(reverse("wei:update_bus_team", kwargs=dict(pk=self.team.pk)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
response = self.client.post(reverse("wei:update_bus_team", kwargs=dict(pk=self.team.pk)), dict(
|
response = self.client.post(reverse("wei:update_bus_team", kwargs=dict(pk=self.team.pk)), dict(
|
||||||
name="Update Team Test",
|
name="Update Team Test",
|
||||||
color="#A6AA",
|
color="#A6AA",
|
||||||
|
@ -214,11 +273,42 @@ class TestWEIRegistration(TestCase):
|
||||||
self.assertRedirects(response, reverse("wei:manage_bus_team", kwargs=dict(pk=self.team.pk)), 302, 200)
|
self.assertRedirects(response, reverse("wei:manage_bus_team", kwargs=dict(pk=self.team.pk)), 302, 200)
|
||||||
self.assertTrue(qs.exists())
|
self.assertTrue(qs.exists())
|
||||||
|
|
||||||
|
# Check that if the WEI is started, we can't update a team
|
||||||
|
self.wei.date_start = '2000-01-01'
|
||||||
|
self.wei.save()
|
||||||
|
response = self.client.get(reverse("wei:update_bus_team", kwargs=dict(pk=self.team.pk)))
|
||||||
|
self.assertRedirects(response, reverse("wei:wei_closed", kwargs=dict(pk=self.wei.pk)), 302, 200)
|
||||||
|
|
||||||
def test_register_2a(self):
|
def test_register_2a(self):
|
||||||
"""
|
"""
|
||||||
Test register a new 2A+ to the WEI.
|
Test register a new 2A+ to the WEI.
|
||||||
"""
|
"""
|
||||||
|
response = self.client.get(reverse("wei:wei_register_2A", kwargs=dict(wei_pk=self.wei.pk)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("wei:wei_register_2A_myself", kwargs=dict(wei_pk=self.wei.pk)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
user = User.objects.create(username="toto", email="toto@example.com")
|
user = User.objects.create(username="toto", email="toto@example.com")
|
||||||
|
|
||||||
|
# Try with an invalid form
|
||||||
|
response = self.client.post(reverse("wei:wei_register_2A", kwargs=dict(wei_pk=self.wei.pk)), dict(
|
||||||
|
user=user.id,
|
||||||
|
soge_credit=True,
|
||||||
|
birth_date='2000-01-01',
|
||||||
|
gender='nonbinary',
|
||||||
|
clothing_cut='female',
|
||||||
|
clothing_size='XS',
|
||||||
|
health_issues='I am a bot',
|
||||||
|
emergency_contact_name='NoteKfet2020',
|
||||||
|
emergency_contact_phone='+33123456789',
|
||||||
|
bus=[],
|
||||||
|
team=[],
|
||||||
|
roles=[],
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertFalse(response.context["form"].is_valid())
|
||||||
|
|
||||||
response = self.client.post(reverse("wei:wei_register_2A", kwargs=dict(wei_pk=self.wei.pk)), dict(
|
response = self.client.post(reverse("wei:wei_register_2A", kwargs=dict(wei_pk=self.wei.pk)), dict(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
soge_credit=True,
|
soge_credit=True,
|
||||||
|
@ -237,12 +327,42 @@ class TestWEIRegistration(TestCase):
|
||||||
self.assertTrue(qs.exists())
|
self.assertTrue(qs.exists())
|
||||||
self.assertRedirects(response, reverse("wei:wei_survey", kwargs=dict(pk=qs.get().pk)), 302, 302)
|
self.assertRedirects(response, reverse("wei:wei_survey", kwargs=dict(pk=qs.get().pk)), 302, 302)
|
||||||
|
|
||||||
|
# Check that the user can't be registered twice
|
||||||
|
response = self.client.post(reverse("wei:wei_register_2A", kwargs=dict(wei_pk=self.wei.pk)), dict(
|
||||||
|
user=user.id,
|
||||||
|
soge_credit=True,
|
||||||
|
birth_date='2000-01-01',
|
||||||
|
gender='nonbinary',
|
||||||
|
clothing_cut='female',
|
||||||
|
clothing_size='XS',
|
||||||
|
health_issues='I am a bot',
|
||||||
|
emergency_contact_name='NoteKfet2020',
|
||||||
|
emergency_contact_phone='+33123456789',
|
||||||
|
bus=[self.bus.id],
|
||||||
|
team=[self.team.id],
|
||||||
|
roles=[role.id for role in WEIRole.objects.filter(~Q(name="1A")).all()],
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue("This user is already registered to this WEI." in str(response.context["form"].errors))
|
||||||
|
|
||||||
|
# Check that if the WEI is started, we can't register anyone
|
||||||
|
self.wei.date_start = '2000-01-01'
|
||||||
|
self.wei.save()
|
||||||
|
response = self.client.get(reverse("wei:wei_register_2A", kwargs=dict(wei_pk=self.wei.pk)))
|
||||||
|
self.assertRedirects(response, reverse("wei:wei_closed", kwargs=dict(pk=self.wei.pk)), 302, 200)
|
||||||
|
|
||||||
def test_register_1a(self):
|
def test_register_1a(self):
|
||||||
"""
|
"""
|
||||||
Test register a first year member to the WEI and complete the survey.
|
Test register a first year member to the WEI and complete the survey.
|
||||||
"""
|
"""
|
||||||
|
response = self.client.get(reverse("wei:wei_register_1A", kwargs=dict(wei_pk=self.wei.pk)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("wei:wei_register_1A_myself", kwargs=dict(wei_pk=self.wei.pk)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
user = User.objects.create(username="toto", email="toto@example.com")
|
user = User.objects.create(username="toto", email="toto@example.com")
|
||||||
response = self.client.post(reverse("wei:wei_register_1A_myself", kwargs=dict(wei_pk=self.wei.pk)), dict(
|
response = self.client.post(reverse("wei:wei_register_1A", kwargs=dict(wei_pk=self.wei.pk)), dict(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
soge_credit=True,
|
soge_credit=True,
|
||||||
birth_date='2000-01-01',
|
birth_date='2000-01-01',
|
||||||
|
@ -273,6 +393,57 @@ class TestWEIRegistration(TestCase):
|
||||||
survey = CurrentSurvey(registration)
|
survey = CurrentSurvey(registration)
|
||||||
self.assertTrue(survey.is_complete())
|
self.assertTrue(survey.is_complete())
|
||||||
|
|
||||||
|
# Check that the user can't be registered twice
|
||||||
|
response = self.client.post(reverse("wei:wei_register_1A", kwargs=dict(wei_pk=self.wei.pk)), dict(
|
||||||
|
user=user.id,
|
||||||
|
soge_credit=True,
|
||||||
|
birth_date='2000-01-01',
|
||||||
|
gender='nonbinary',
|
||||||
|
clothing_cut='female',
|
||||||
|
clothing_size='XS',
|
||||||
|
health_issues='I am a bot',
|
||||||
|
emergency_contact_name='NoteKfet2020',
|
||||||
|
emergency_contact_phone='+33123456789',
|
||||||
|
ml_events_registration=True,
|
||||||
|
ml_sport_registration=False,
|
||||||
|
ml_art_registration=False,
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue("This user is already registered to this WEI." in str(response.context["form"].errors))
|
||||||
|
|
||||||
|
# Check that the user can't be registered twice as a first year member
|
||||||
|
second_wei = WEIClub.objects.create(
|
||||||
|
name="Second WEI",
|
||||||
|
year=self.year + 1,
|
||||||
|
date_start=str(self.year + 1) + "-01-01",
|
||||||
|
date_end=str(self.year + 1) + "-12-31",
|
||||||
|
membership_start=str(self.year) + "-01-01",
|
||||||
|
membership_end=str(self.year + 1) + "-12-31",
|
||||||
|
)
|
||||||
|
response = self.client.post(reverse("wei:wei_register_1A", kwargs=dict(wei_pk=second_wei.pk)), dict(
|
||||||
|
user=user.id,
|
||||||
|
soge_credit=True,
|
||||||
|
birth_date='2000-01-01',
|
||||||
|
gender='nonbinary',
|
||||||
|
clothing_cut='female',
|
||||||
|
clothing_size='XS',
|
||||||
|
health_issues='I am a bot',
|
||||||
|
emergency_contact_name='NoteKfet2020',
|
||||||
|
emergency_contact_phone='+33123456789',
|
||||||
|
ml_events_registration=True,
|
||||||
|
ml_sport_registration=False,
|
||||||
|
ml_art_registration=False,
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue("This user can't be in her/his first year since he/she has already participated to a WEI."
|
||||||
|
in str(response.context["form"].errors))
|
||||||
|
|
||||||
|
# Check that if the WEI is started, we can't register anyone
|
||||||
|
self.wei.date_start = '2000-01-01'
|
||||||
|
self.wei.save()
|
||||||
|
response = self.client.get(reverse("wei:wei_register_1A", kwargs=dict(wei_pk=self.wei.pk)))
|
||||||
|
self.assertRedirects(response, reverse("wei:wei_closed", kwargs=dict(pk=self.wei.pk)), 302, 200)
|
||||||
|
|
||||||
def test_wei_survey_ended(self):
|
def test_wei_survey_ended(self):
|
||||||
"""
|
"""
|
||||||
Test display the end page of a survey.
|
Test display the end page of a survey.
|
||||||
|
@ -281,6 +452,12 @@ class TestWEIRegistration(TestCase):
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_update_registration(self):
|
def test_update_registration(self):
|
||||||
|
"""
|
||||||
|
Test update a registration.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("wei:wei_update_registration", kwargs=dict(pk=self.registration.pk)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
self.registration.information = dict(
|
self.registration.information = dict(
|
||||||
preferred_bus_pk=[],
|
preferred_bus_pk=[],
|
||||||
preferred_team_pk=[],
|
preferred_team_pk=[],
|
||||||
|
@ -310,6 +487,12 @@ class TestWEIRegistration(TestCase):
|
||||||
self.assertTrue(qs.exists())
|
self.assertTrue(qs.exists())
|
||||||
self.assertRedirects(response, reverse("wei:validate_registration", kwargs=dict(pk=qs.get().pk)), 302, 200)
|
self.assertRedirects(response, reverse("wei:validate_registration", kwargs=dict(pk=qs.get().pk)), 302, 200)
|
||||||
|
|
||||||
|
# Check that if the WEI is started, we can't update a registration
|
||||||
|
self.wei.date_start = '2000-01-01'
|
||||||
|
self.wei.save()
|
||||||
|
response = self.client.get(reverse("wei:wei_update_registration", kwargs=dict(wei_pk=self.registration.pk)))
|
||||||
|
self.assertRedirects(response, reverse("wei:wei_closed", kwargs=dict(pk=self.wei.pk)), 302, 200)
|
||||||
|
|
||||||
def test_delete_registration(self):
|
def test_delete_registration(self):
|
||||||
"""
|
"""
|
||||||
Test delete a WEI registration.
|
Test delete a WEI registration.
|
||||||
|
@ -321,6 +504,9 @@ class TestWEIRegistration(TestCase):
|
||||||
"""
|
"""
|
||||||
Test validate a membership.
|
Test validate a membership.
|
||||||
"""
|
"""
|
||||||
|
response = self.client.get(reverse("wei:validate_registration", kwargs=dict(pk=self.registration.pk)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
response = self.client.post(reverse("wei:validate_registration", kwargs=dict(pk=self.registration.pk)), dict(
|
response = self.client.post(reverse("wei:validate_registration", kwargs=dict(pk=self.registration.pk)), dict(
|
||||||
roles=[WEIRole.objects.get(name="GC WEI").id],
|
roles=[WEIRole.objects.get(name="GC WEI").id],
|
||||||
bus=self.bus.pk,
|
bus=self.bus.pk,
|
||||||
|
@ -359,28 +545,35 @@ class TestWEIRegistration(TestCase):
|
||||||
|
|
||||||
def test_registrations_list(self):
|
def test_registrations_list(self):
|
||||||
"""
|
"""
|
||||||
Test display the registration list
|
Test display the registration list, with or without a research
|
||||||
"""
|
"""
|
||||||
response = self.client.get(reverse("wei:wei_registrations", kwargs=dict(pk=self.wei.pk)))
|
response = self.client.get(reverse("wei:wei_registrations", kwargs=dict(pk=self.wei.pk)))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("wei:wei_registrations", kwargs=dict(pk=self.wei.pk)) + "?search=.")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_memberships_list(self):
|
def test_memberships_list(self):
|
||||||
"""
|
"""
|
||||||
Test display the memberships list
|
Test display the memberships list, with or without a research
|
||||||
"""
|
"""
|
||||||
response = self.client.get(reverse("wei:wei_memberships", kwargs=dict(pk=self.wei.pk)))
|
response = self.client.get(reverse("wei:wei_memberships", kwargs=dict(pk=self.wei.pk)))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("wei:wei_memberships", kwargs=dict(pk=self.wei.pk)) + "?search=.")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def is_latex_installed(self):
|
def is_latex_installed(self):
|
||||||
"""
|
"""
|
||||||
Check if LaTeX is installed in the machine. Don't check pages that generate a PDF file if LaTeX is not
|
Check if LaTeX is installed in the machine. Don't check pages that generate a PDF file if LaTeX is not
|
||||||
installed, like in Gitlab.
|
installed, like in Gitlab.
|
||||||
"""
|
"""
|
||||||
return subprocess.call(
|
with open("/dev/null", "wb") as devnull:
|
||||||
["which", "pdflatex"],
|
return subprocess.call(
|
||||||
stdout=open('/dev/null', 'wb'),
|
["which", "pdflatex"],
|
||||||
stderr=open('/dev/null', 'wb'),
|
stdout=devnull,
|
||||||
) == 0
|
stderr=devnull,
|
||||||
|
) == 0
|
||||||
|
|
||||||
def test_memberships_pdf_list(self):
|
def test_memberships_pdf_list(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -235,7 +235,7 @@ class WEIRegistrationsView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTable
|
||||||
|
|
||||||
pattern = self.request.GET.get("search", "")
|
pattern = self.request.GET.get("search", "")
|
||||||
|
|
||||||
if not pattern:
|
if pattern:
|
||||||
qs = qs.filter(
|
qs = qs.filter(
|
||||||
Q(user__first_name__iregex=pattern)
|
Q(user__first_name__iregex=pattern)
|
||||||
| Q(user__last_name__iregex=pattern)
|
| Q(user__last_name__iregex=pattern)
|
||||||
|
@ -266,7 +266,7 @@ class WEIUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
||||||
today = date.today()
|
today = date.today()
|
||||||
# We can't update a past WEI
|
# We can't update a past WEI
|
||||||
# But we can update it while it is not officially opened
|
# But we can update it while it is not officially opened
|
||||||
if today > wei.membership_end:
|
if today > wei.date_start:
|
||||||
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
|
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -492,7 +492,7 @@ class WEIRegister1AView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
|
||||||
# Check if the user can be in her/his first year (yeah, no cheat)
|
# Check if the user can be in her/his first year (yeah, no cheat)
|
||||||
if WEIRegistration.objects.filter(user=form.instance.user).exists():
|
if WEIRegistration.objects.filter(user=form.instance.user).exists():
|
||||||
form.add_error('user', _("This user can't be in her/his first year since he/she has already"
|
form.add_error('user', _("This user can't be in her/his first year since he/she has already"
|
||||||
" participed to a WEI."))
|
" participated to a WEI."))
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
@ -1046,19 +1046,20 @@ class MemberListRenderView(LoginRequiredMixin, View):
|
||||||
f.write(tex.encode("UTF-8"))
|
f.write(tex.encode("UTF-8"))
|
||||||
del tex
|
del tex
|
||||||
|
|
||||||
error = subprocess.Popen(
|
with open(os.devnull, "wb") as devnull:
|
||||||
["pdflatex", "{}/wei-list.tex".format(tmp_dir)],
|
error = subprocess.Popen(
|
||||||
cwd=tmp_dir,
|
["pdflatex", "{}/wei-list.tex".format(tmp_dir)],
|
||||||
stdin=open(os.devnull, "r"),
|
cwd=tmp_dir,
|
||||||
stderr=open(os.devnull, "wb"),
|
stderr=devnull,
|
||||||
stdout=open(os.devnull, "wb"),
|
stdout=devnull,
|
||||||
).wait()
|
).wait()
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
raise IOError("An error attempted while generating a WEI list (code=" + str(error) + ")")
|
raise IOError("An error attempted while generating a WEI list (code=" + str(error) + ")")
|
||||||
|
|
||||||
# Display the generated pdf as a HTTP Response
|
# Display the generated pdf as a HTTP Response
|
||||||
pdf = open("{}/wei-list.pdf".format(tmp_dir), 'rb').read()
|
with open("{}/wei-list.pdf".format(tmp_dir), 'rb') as f:
|
||||||
|
pdf = f.read()
|
||||||
response = HttpResponse(pdf, content_type="application/pdf")
|
response = HttpResponse(pdf, content_type="application/pdf")
|
||||||
response['Content-Disposition'] = "inline;filename=Liste%20des%20participants%20au%20WEI.pdf"
|
response['Content-Disposition'] = "inline;filename=Liste%20des%20participants%20au%20WEI.pdf"
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
|
|
|
@ -2547,7 +2547,7 @@ msgstr ""
|
||||||
|
|
||||||
#: apps/wei/views.py:494
|
#: apps/wei/views.py:494
|
||||||
msgid ""
|
msgid ""
|
||||||
"This user can't be in her/his first year since he/she has already participed "
|
"This user can't be in her/his first year since he/she has already participated "
|
||||||
"to a WEI."
|
"to a WEI."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
|
@ -2642,7 +2642,7 @@ msgstr "Cette personne est déjà inscrite au WEI."
|
||||||
|
|
||||||
#: apps/wei/views.py:494
|
#: apps/wei/views.py:494
|
||||||
msgid ""
|
msgid ""
|
||||||
"This user can't be in her/his first year since he/she has already participed "
|
"This user can't be in her/his first year since he/she has already participated "
|
||||||
"to a WEI."
|
"to a WEI."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Cet utilisateur ne peut pas être en première année puisqu'iel a déjà "
|
"Cet utilisateur ne peut pas être en première année puisqu'iel a déjà "
|
||||||
|
|
Loading…
Reference in New Issue