108 lines
4.3 KiB
Python
108 lines
4.3 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 datetime import date
|
|
|
|
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):
|
|
"""Test the timeline_representation method to ensure it returns the correct HTML string."""
|
|
gymnast = Gymnast.objects.get(last_name="Pauchou")
|
|
chrono = Chrono.objects.get(gymnast=gymnast)
|
|
today = pendulum.now().date()
|
|
|
|
expected_html = f"<li>{today:%d %b %Y} - New personel best 10 |: 15.000' (13.000')</li>"
|
|
self.assertEqual(chrono.timeline_representation(), expected_html, "The timeline_representation method does not return the expected HTML string.")
|
|
|
|
def test_chrono_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_wellbeing_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_wellbeing_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_wellbeing_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")
|
|
|
|
def test_heightweight_bmi_calculation(self):
|
|
"""Test the bmi method to ensure it correctly calculates the BMI."""
|
|
gymnast = Gymnast.objects.get(last_name="Pauchou")
|
|
heightweight = HeightWeight(
|
|
gymnast=gymnast,
|
|
height=180,
|
|
weight=75
|
|
)
|
|
heightweight.save()
|
|
|
|
expected_bmi = 75 / (1.8 ** 2)
|
|
self.assertAlmostEqual(heightweight.bmi, expected_bmi, places=2, msg="The bmi method does not return the expected BMI.")
|
|
|
|
|