Skip to content

Commit 2e1e02e

Browse files
committed
test(profiles/athletes): add tests for model Category
1 parent 4b3a801 commit 2e1e02e

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

profiles/models/athletes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Meta:
4848
# ordering = ["code"]
4949

5050
def __str__(self):
51-
return f"{self.code} - {self.name}"
51+
return f"{self.code} - {self.description}"
5252

5353
def __repr__(self):
54-
return f"Category(code={self.code}, name={self.name}, age_range={self.age_range})"
54+
return f"Category(code={self.code}, description={self.description}, age_range={self.age_range})"

profiles/tests/athletes/test_models.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class AthleteModelTest(TestCase):
7-
87
@classmethod
98
def setUpTestData(cls):
109
"""Create a valid instance of Category and Trainer shared by all tests."""
@@ -50,7 +49,6 @@ def test_athlete_with_trainer(self):
5049
self.assertEqual(self.athlete.trainer.last_name, 'Bianchi')
5150
self.assertEqual(self.athlete.trainer.fiscal_code, 'BNCPLO80A01H211B')
5251

53-
5452
def test_athlete_string_representation(self):
5553
"""Test __str__ method."""
5654
self.assertEqual(
@@ -72,3 +70,56 @@ def test__athlete_fiscal_code_uniqueness(self):
7270
def test__athlete_required_fields(self):
7371
"""Test that required fields cannot be left empty."""
7472
pass
73+
74+
75+
class CategoryModelTest(TestCase):
76+
@classmethod
77+
def setUpTestData(cls):
78+
"""Create a valid instance of Category shared by all tests."""
79+
cls.category = Category.objects.create(
80+
code='AF',
81+
description='Allieve Femminili',
82+
age_range='Under 18',
83+
)
84+
85+
def test_category_creation(self):
86+
"""Test creating a new category."""
87+
self.assertEqual(self.category.code, 'AF')
88+
self.assertEqual(self.category.description, 'Allieve Femminili')
89+
self.assertEqual(self.category.age_range, 'Under 18')
90+
91+
def test_category_required_fields(self):
92+
"""Test that required fields cannot be left empty."""
93+
pass
94+
95+
def test_category_code_uniqueness(self):
96+
"""Test that the code must be unique."""
97+
pass
98+
99+
def test_category_optional_age_range(self):
100+
"""Test that the age range can be left empty."""
101+
category = Category.objects.create(
102+
code='SN',
103+
description='Senior',
104+
age_range=None
105+
)
106+
self.assertIsNone(category.age_range)
107+
108+
def test_category_string_representation(self):
109+
"""Test __str__ method."""
110+
self.assertEqual(
111+
str(self.category),
112+
'AF - Allieve Femminili'
113+
)
114+
115+
def test_category_repr_representation(self):
116+
"""Test __repr__ method."""
117+
self.assertEqual(
118+
repr(self.category),
119+
'Category(code=AF, description=Allieve Femminili, age_range=Under 18)'
120+
)
121+
122+
def test_category_ordering(self):
123+
"""Test ordering by code."""
124+
pass
125+

0 commit comments

Comments
 (0)