|
| 1 | +from django.test import TestCase |
| 2 | +from profiles.models.athletes import Athlete, Category |
| 3 | +from profiles.models.trainers import Trainer |
| 4 | + |
| 5 | + |
| 6 | +class AthleteModelTest(TestCase): |
| 7 | + |
| 8 | + @classmethod |
| 9 | + def setUpTestData(cls): |
| 10 | + """Create a valid instance of Category and Trainer shared by all tests.""" |
| 11 | + cls.category = Category.objects.create( |
| 12 | + code='JM', |
| 13 | + description='Junior Maschile', |
| 14 | + age_range='Under 20', |
| 15 | + ) |
| 16 | + cls.trainer = Trainer.objects.create( |
| 17 | + first_name='Paolo', |
| 18 | + last_name='Bianchi', |
| 19 | + fiscal_code='BNCPLO80A01H211B', |
| 20 | + ) |
| 21 | + |
| 22 | + def setUp(self): |
| 23 | + """Create a valid dinamic instance of Athlete for each test.""" |
| 24 | + self.athlete = Athlete.objects.create( |
| 25 | + first_name='Mario', |
| 26 | + last_name='Rossi', |
| 27 | + date_of_birth='1990-01-01', |
| 28 | + place_of_birth='Roma', |
| 29 | + fiscal_code='RSSMRA90A01H211B', |
| 30 | + category=self.category, |
| 31 | + ) |
| 32 | + |
| 33 | + def test_athlete_creation(self): |
| 34 | + """Test creating a new athlete without a trainer.""" |
| 35 | + self.assertEqual(self.athlete.first_name, 'Mario') |
| 36 | + self.assertEqual(self.athlete.last_name, 'Rossi') |
| 37 | + self.assertEqual(self.athlete.date_of_birth, '1990-01-01') |
| 38 | + self.assertEqual(self.athlete.place_of_birth, 'Roma') |
| 39 | + self.assertEqual(self.athlete.fiscal_code, 'RSSMRA90A01H211B') |
| 40 | + self.assertEqual(self.athlete.category, self.category) |
| 41 | + self.assertEqual(self.athlete.category.code, 'JM') |
| 42 | + self.assertIsNone(self.athlete.trainer) |
| 43 | + |
| 44 | + def test_athlete_with_trainer(self): |
| 45 | + """Test creating a new athlete with a trainer.""" |
| 46 | + self.athlete.trainer = self.trainer |
| 47 | + self.athlete.save() |
| 48 | + self.assertEqual(self.athlete.trainer, self.trainer) |
| 49 | + self.assertEqual(self.athlete.trainer.first_name, 'Paolo') |
| 50 | + self.assertEqual(self.athlete.trainer.last_name, 'Bianchi') |
| 51 | + self.assertEqual(self.athlete.trainer.fiscal_code, 'BNCPLO80A01H211B') |
| 52 | + |
| 53 | + |
| 54 | + def test_athlete_string_representation(self): |
| 55 | + """Test __str__ method.""" |
| 56 | + self.assertEqual( |
| 57 | + str(self.athlete), |
| 58 | + 'Mario Rossi (RSSMRA90A01H211B)' |
| 59 | + ) |
| 60 | + |
| 61 | + def test__athlete_repr_representation(self): |
| 62 | + """Test __repr__ method.""" |
| 63 | + self.assertEqual( |
| 64 | + repr(self.athlete), |
| 65 | + 'Athlete(first_name=Mario, last_name=Rossi, date_of_birth=1990-01-01, fiscal_code=RSSMRA90A01H211B)' |
| 66 | + ) |
| 67 | + |
| 68 | + def test__athlete_fiscal_code_uniqueness(self): |
| 69 | + """Test that the fiscal code must be unique.""" |
| 70 | + pass |
| 71 | + |
| 72 | + def test__athlete_required_fields(self): |
| 73 | + """Test that required fields cannot be left empty.""" |
| 74 | + pass |
0 commit comments