mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-11-26 18:37:12 +00:00
more tests
This commit is contained in:
parent
13b9b6edea
commit
1760196578
@ -1,14 +1,11 @@
|
|||||||
# Copyright (C) 2018-2023 by BDE ENS Paris-Saclay
|
# Copyright (C) 2018-2023 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
# import time
|
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
# from random import Random
|
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
# from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
from .base import WEISurvey, WEISurveyInformation, WEISurveyAlgorithm, WEIBusInformation
|
from .base import WEISurvey, WEISurveyInformation, WEISurveyAlgorithm, WEIBusInformation
|
||||||
from ...models import WEIMembership
|
from ...models import WEIMembership
|
||||||
@ -48,12 +45,6 @@ class WEISurveyForm2023(forms.Form):
|
|||||||
"""
|
"""
|
||||||
information = WEISurveyInformation2023(registration)
|
information = WEISurveyInformation2023(registration)
|
||||||
|
|
||||||
# if self.data:
|
|
||||||
# for question in WORDS:
|
|
||||||
# self.fields[question].choices = [answer for answer in WORDS[question][1]]
|
|
||||||
# if self.is_valid():
|
|
||||||
# return
|
|
||||||
|
|
||||||
question = information.questions[information.step]
|
question = information.questions[information.step]
|
||||||
self.fields[question] = forms.ChoiceField(
|
self.fields[question] = forms.ChoiceField(
|
||||||
label=WORDS[question][0] + question,
|
label=WORDS[question][0] + question,
|
||||||
@ -86,14 +77,6 @@ class WEISurveyInformation2023(WEISurveyInformation):
|
|||||||
questions = list(WORDS.keys())
|
questions = list(WORDS.keys())
|
||||||
|
|
||||||
def __init__(self, registration):
|
def __init__(self, registration):
|
||||||
# print(hasattr(self,"questions"))
|
|
||||||
# if not hasattr(self, "questions"):
|
|
||||||
# rng = Random(int(1000 * time.time()))
|
|
||||||
# questions = list(WORDS.keys())
|
|
||||||
# rng.shuffle(questions)
|
|
||||||
# setattr(self, "questions", questions)
|
|
||||||
# print(questions)
|
|
||||||
|
|
||||||
for question in WORDS:
|
for question in WORDS:
|
||||||
setattr(self, str(question), None)
|
setattr(self, str(question), None)
|
||||||
super().__init__(registration)
|
super().__init__(registration)
|
||||||
@ -143,15 +126,6 @@ class WEISurvey2023(WEISurvey):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# @classmethod
|
|
||||||
# @lru_cache()
|
|
||||||
# def word_mean(cls, word):
|
|
||||||
# """
|
|
||||||
# Calculate the mid-score given by all buses.
|
|
||||||
# """
|
|
||||||
# buses = cls.get_algorithm_class().get_buses()
|
|
||||||
# return sum([cls.get_algorithm_class().get_bus_information(bus).scores[word] for bus in buses]) / buses.count()
|
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache()
|
||||||
def score(self, bus):
|
def score(self, bus):
|
||||||
if not self.is_complete():
|
if not self.is_complete():
|
||||||
@ -176,7 +150,6 @@ class WEISurvey2023(WEISurvey):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def clear_cache(cls):
|
def clear_cache(cls):
|
||||||
# cls.word_mean.cache_clear()
|
|
||||||
return super().clear_cache()
|
return super().clear_cache()
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,9 +2,12 @@
|
|||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
from note.models import NoteUser
|
||||||
|
|
||||||
from ..forms.surveys.wei2023 import WEIBusInformation2023, WEISurvey2023, WORDS, WEISurveyInformation2023
|
from ..forms.surveys.wei2023 import WEIBusInformation2023, WEISurvey2023, WORDS, WEISurveyInformation2023
|
||||||
from ..models import Bus, WEIClub, WEIRegistration
|
from ..models import Bus, WEIClub, WEIRegistration
|
||||||
@ -20,9 +23,25 @@ class TestWEIAlgorithm(TestCase):
|
|||||||
"""
|
"""
|
||||||
Create some test data, with one WEI and 10 buses with random score attributions.
|
Create some test data, with one WEI and 10 buses with random score attributions.
|
||||||
"""
|
"""
|
||||||
|
self.user = User.objects.create_superuser(
|
||||||
|
username="weiadmin",
|
||||||
|
password="admin",
|
||||||
|
email="admin@example.com",
|
||||||
|
)
|
||||||
|
self.user.save()
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
sess = self.client.session
|
||||||
|
sess["permission_mask"] = 42
|
||||||
|
sess.save()
|
||||||
|
|
||||||
self.wei = WEIClub.objects.create(
|
self.wei = WEIClub.objects.create(
|
||||||
name="WEI 2023",
|
name="WEI 2023",
|
||||||
email="wei2023@example.com",
|
email="wei2023@example.com",
|
||||||
|
parent_club_id=2,
|
||||||
|
membership_fee_paid=12500,
|
||||||
|
membership_fee_unpaid=5500,
|
||||||
|
membership_start='2023-08-26',
|
||||||
|
membership_end='2023-09-15',
|
||||||
date_start='2023-09-16',
|
date_start='2023-09-16',
|
||||||
date_end='2023-09-18',
|
date_end='2023-09-18',
|
||||||
year=2023,
|
year=2023,
|
||||||
@ -108,3 +127,44 @@ class TestWEIAlgorithm(TestCase):
|
|||||||
self.assertLessEqual(max_score - score, 25) # Always less than 25 % of tolerance
|
self.assertLessEqual(max_score - score, 25) # Always less than 25 % of tolerance
|
||||||
|
|
||||||
self.assertLessEqual(penalty / 100, 25) # Tolerance of 5 %
|
self.assertLessEqual(penalty / 100, 25) # Tolerance of 5 %
|
||||||
|
|
||||||
|
def test_register_1a(self):
|
||||||
|
"""
|
||||||
|
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)
|
||||||
|
|
||||||
|
user = User.objects.create(username="toto", email="toto@example.com")
|
||||||
|
NoteUser.objects.create(user=user)
|
||||||
|
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=date(2000, 1, 1),
|
||||||
|
gender='nonbinary',
|
||||||
|
clothing_cut='female',
|
||||||
|
clothing_size='XS',
|
||||||
|
health_issues='I am a bot',
|
||||||
|
emergency_contact_name='NoteKfet2020',
|
||||||
|
emergency_contact_phone='+33123456789',
|
||||||
|
))
|
||||||
|
qs = WEIRegistration.objects.filter(user_id=user.id)
|
||||||
|
self.assertTrue(qs.exists())
|
||||||
|
registration = qs.get()
|
||||||
|
self.assertRedirects(response, reverse("wei:wei_survey", kwargs=dict(pk=registration.pk)), 302, 200)
|
||||||
|
for question in WORDS:
|
||||||
|
# Fill 1A Survey, 20 pages
|
||||||
|
# be careful if questionnary form change (number of page, type of answer...)
|
||||||
|
response = self.client.post(reverse("wei:wei_survey", kwargs=dict(pk=registration.pk)), {
|
||||||
|
question: "1"
|
||||||
|
})
|
||||||
|
registration.refresh_from_db()
|
||||||
|
survey = WEISurvey2023(registration)
|
||||||
|
self.assertRedirects(response, reverse("wei:wei_survey", kwargs=dict(pk=registration.pk)), 302,
|
||||||
|
302 if survey.is_complete() else 200)
|
||||||
|
self.assertIsNotNone(getattr(survey.information, question), "Survey page " + question + " failed")
|
||||||
|
survey = WEISurvey2023(registration)
|
||||||
|
self.assertTrue(survey.is_complete())
|
||||||
|
survey.select_bus(self.buses[0])
|
||||||
|
survey.save()
|
||||||
|
self.assertIsNotNone(survey.information.get_selected_bus())
|
||||||
|
@ -380,7 +380,7 @@ class TestWEIRegistration(TestCase):
|
|||||||
|
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
response = self.client.get(reverse("wei:wei_register_1A", kwargs=dict(wei_pk=self.wei.pk)))
|
response = self.client.get(reverse("wei:wei_register_1A", kwargs=dict(wei_pk=self.wei.pk)))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
@ -402,22 +402,6 @@ class TestWEIRegistration(TestCase):
|
|||||||
self.assertTrue(qs.exists())
|
self.assertTrue(qs.exists())
|
||||||
registration = qs.get()
|
registration = qs.get()
|
||||||
self.assertRedirects(response, reverse("wei:wei_survey", kwargs=dict(pk=registration.pk)), 302, 200)
|
self.assertRedirects(response, reverse("wei:wei_survey", kwargs=dict(pk=registration.pk)), 302, 200)
|
||||||
# for i in range(1, 21):
|
|
||||||
# # Fill 1A Survey, 20 pages
|
|
||||||
# # be careful if questionnary form change (number of page, type of answer...)
|
|
||||||
# response = self.client.post(reverse("wei:wei_survey", kwargs=dict(pk=registration.pk)), dict(
|
|
||||||
# word=1,
|
|
||||||
# ))
|
|
||||||
# registration.refresh_from_db()
|
|
||||||
# survey = CurrentSurvey(registration)
|
|
||||||
# self.assertRedirects(response, reverse("wei:wei_survey", kwargs=dict(pk=registration.pk)), 302,
|
|
||||||
# 302 if survey.is_complete() else 200)
|
|
||||||
# self.assertIsNotNone(getattr(survey.information, "word" + str(i)), "Survey page #" + str(i) + " failed")
|
|
||||||
# survey = CurrentSurvey(registration)
|
|
||||||
# self.assertTrue(survey.is_complete())
|
|
||||||
# survey.select_bus(self.bus)
|
|
||||||
# survey.save()
|
|
||||||
# self.assertIsNotNone(survey.information.get_selected_bus())
|
|
||||||
|
|
||||||
# Check that the user can't be registered twice
|
# 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(
|
response = self.client.post(reverse("wei:wei_register_1A", kwargs=dict(wei_pk=self.wei.pk)), dict(
|
||||||
|
Loading…
Reference in New Issue
Block a user