92 lines
3.6 KiB
Python
92 lines
3.6 KiB
Python
import pendulum
|
|
from django.test import TestCase
|
|
from jarvis.people.models import Gymnast
|
|
from jarvis.followup.models import (
|
|
Chrono,
|
|
ChronoDetails,
|
|
Injury,
|
|
LearnedSkill,
|
|
Plan,
|
|
Point,
|
|
WellBeing,
|
|
GymnastHasRoutine,
|
|
NumberOfRoutineDone,
|
|
HeightWeight,
|
|
Note,
|
|
Intensity,
|
|
SeasonInformation,
|
|
CompetitivePointsStats,
|
|
)
|
|
|
|
from jarvis.followup.models import (
|
|
CHRONO_TYPE_CHOICE,
|
|
SCORE_TYPE_CHOICE,
|
|
)
|
|
|
|
|
|
class TestModels(TestCase):
|
|
def setUp(self):
|
|
"""Mise en place des variables pour les tests."""
|
|
gymnast = Gymnast.objects.create(
|
|
last_name="Pauchou", first_name="Fred", birthdate="1987-07-03", gender=0
|
|
)
|
|
Chrono.objects.create(
|
|
gymnast=gymnast, chrono_type=0, score_type=0, score=15, tof=13
|
|
)
|
|
Injury.objects.create(
|
|
gymnast=gymnast, location=0, injury_type=0, body_side=0, mechanism=0
|
|
)
|
|
WellBeing.objects.create(gymnast=gymnast, mindstate=9, sleep=8, stress=7, fatigue=6, muscle_soreness=5)
|
|
|
|
def test_chrono_str(self):
|
|
"""Test the __str__ method to ensure it returns the correct string representation of a Chrono instance."""
|
|
gymnast = Gymnast.objects.get(last_name="Pauchou")
|
|
chrono = Chrono.objects.get(gymnast=gymnast)
|
|
today = pendulum.now().to_date_string()
|
|
|
|
expected_str = f"{gymnast} - 13.000 ({today} - 0)"
|
|
self.assertEqual(str(chrono), expected_str, "The __str__ method does not return the expected string.")
|
|
|
|
# def test_chrono_timeline_representation(self):
|
|
# gymnast = Gymnast.objects.get(last_name="Pauchou")
|
|
# chrono = Chrono.objects.get(gymnast=gymnast)
|
|
# today = pendulum.now().date()
|
|
# self.assertEqual(
|
|
# chrono.timeline_representation,
|
|
# f"<li>{today.to_date_string()} - New personel best {CHRONO_TYPE_CHOICE[chrono.chrono_type][1]}: 15.000' (13.000')</li>", # pylint: disable=line-too-long
|
|
# )
|
|
|
|
def test_compute_tof(self):
|
|
res = Chrono.compute_tof(15)
|
|
self.assertEqual(res, 13)
|
|
|
|
def test_injury_to_string(self):
|
|
gymnast = Gymnast.objects.get(last_name="Pauchou")
|
|
injury = Injury.objects.get(gymnast=gymnast)
|
|
today = pendulum.now().date()
|
|
self.assertEqual(str(injury), f"Fred Pauchou ({today})")
|
|
|
|
def test_get_inversed_stress(self):
|
|
"""Test the get_inversed_stress method to ensure it correctly calculates the inversed stress."""
|
|
gymnast = Gymnast.objects.get(last_name="Pauchou")
|
|
well_being = WellBeing.objects.get(gymnast=gymnast)
|
|
|
|
inversed_stress = well_being.get_inversed_stress
|
|
self.assertEqual(inversed_stress, 3, "The inversed stress should be 3 for a stress value of 7")
|
|
|
|
def test_get_inversed_fatigue(self):
|
|
"""Test the get_inversed_fatigue property to ensure it correctly calculates the inversed fatigue."""
|
|
gymnast = Gymnast.objects.get(last_name="Pauchou")
|
|
well_being = WellBeing.objects.get(gymnast=gymnast)
|
|
|
|
inversed_fatigue = well_being.get_inversed_fatigue
|
|
self.assertEqual(inversed_fatigue, 4, "The inversed fatigue should be 4 for a fatigue value of 6")
|
|
|
|
def test_get_inversed_muscle_soreness(self):
|
|
"""Test the get_inversed_muscle_soreness property to ensure it correctly calculates the inversed muscle soreness."""
|
|
gymnast = Gymnast.objects.get(last_name="Pauchou")
|
|
well_being = WellBeing.objects.get(gymnast=gymnast)
|
|
|
|
inversed_muscle_soreness = well_being.get_inversed_muscle_soreness
|
|
self.assertEqual(inversed_muscle_soreness, 5, "The inversed muscle soreness should be 5 for a muscle soreness value of 5")
|