1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00

Compare commits

..

No commits in common. "106e97f5df198ea2ac21cb59e4a4f5cd6add3e35" and "25e26fe8cf25dd71f56ec65c2a144014bed83437" have entirely different histories.

6 changed files with 37 additions and 232 deletions

View File

@ -5,7 +5,6 @@ from django import template
def pretty_money(value): def pretty_money(value):
try:
if value % 100 == 0: if value % 100 == 0:
return "{:s}{:d}".format( return "{:s}{:d}".format(
"- " if value < 0 else "", "- " if value < 0 else "",
@ -17,8 +16,6 @@ def pretty_money(value):
abs(value) // 100, abs(value) // 100,
abs(value) % 100, abs(value) % 100,
) )
except (ValueError, TypeError):
return "0 €"
register = template.Library() register = template.Library()

View File

@ -82,3 +82,5 @@ 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")

View File

@ -1,8 +1,6 @@
# 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
@ -17,27 +15,6 @@ 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
@ -66,11 +43,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) + "-01-01", membership_start=str(self.year) + "-08-01",
membership_end=str(self.year) + "-12-31", membership_end=str(self.year) + "-12-31",
year=self.year, year=self.year,
date_start=timezone.now().date() + timedelta(days=2), date_start=str(self.year) + "-09-01",
date_end=str(self.year) + "-12-31", date_end=str(self.year) + "-09-03",
) )
NoteClub.objects.create(club=self.wei) NoteClub.objects.create(club=self.wei)
self.bus = Bus.objects.create( self.bus = Bus.objects.create(
@ -155,12 +132,6 @@ 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.
@ -179,9 +150,6 @@ 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",
@ -192,12 +160,6 @@ 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.
@ -209,9 +171,6 @@ 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.",
@ -220,19 +179,10 @@ 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",
@ -244,12 +194,6 @@ 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.
@ -261,9 +205,6 @@ 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",
@ -273,42 +214,11 @@ 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["membership_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,
@ -327,42 +237,12 @@ 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", kwargs=dict(wei_pk=self.wei.pk)), dict( response = self.client.post(reverse("wei:wei_register_1A_myself", 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',
@ -393,57 +273,6 @@ 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&#39;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.
@ -452,12 +281,6 @@ 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=[],
@ -487,12 +310,6 @@ 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:validate_registration", kwargs=dict(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.
@ -504,9 +321,6 @@ 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,
@ -545,34 +359,27 @@ class TestWEIRegistration(TestCase):
def test_registrations_list(self): def test_registrations_list(self):
""" """
Test display the registration list, with or without a research Test display the registration list
""" """
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, with or without a research Test display the memberships list
""" """
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.
""" """
with open("/dev/null", "wb") as devnull:
return subprocess.call( return subprocess.call(
["which", "pdflatex"], ["which", "pdflatex"],
stdout=devnull, stdout=open('/dev/null', 'wb'),
stderr=devnull, stderr=open('/dev/null', 'wb'),
) == 0 ) == 0
def test_memberships_pdf_list(self): def test_memberships_pdf_list(self):

View File

@ -235,7 +235,7 @@ class WEIRegistrationsView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTable
pattern = self.request.GET.get("search", "") pattern = self.request.GET.get("search", "")
if pattern: if not 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.date_start: if today > wei.membership_end:
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"
" participated to a WEI.")) " participed to a WEI."))
return self.form_invalid(form) return self.form_invalid(form)
return super().form_valid(form) return super().form_valid(form)
@ -1046,20 +1046,19 @@ class MemberListRenderView(LoginRequiredMixin, View):
f.write(tex.encode("UTF-8")) f.write(tex.encode("UTF-8"))
del tex del tex
with open(os.devnull, "wb") as devnull:
error = subprocess.Popen( error = subprocess.Popen(
["pdflatex", "{}/wei-list.tex".format(tmp_dir)], ["pdflatex", "{}/wei-list.tex".format(tmp_dir)],
cwd=tmp_dir, cwd=tmp_dir,
stderr=devnull, stdin=open(os.devnull, "r"),
stdout=devnull, stderr=open(os.devnull, "wb"),
stdout=open(os.devnull, "wb"),
).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
with open("{}/wei-list.pdf".format(tmp_dir), 'rb') as f: pdf = open("{}/wei-list.pdf".format(tmp_dir), 'rb').read()
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:

View File

@ -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 participated " "This user can't be in her/his first year since he/she has already participed "
"to a WEI." "to a WEI."
msgstr "" msgstr ""

View File

@ -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 participated " "This user can't be in her/his first year since he/she has already participed "
"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à "