Skip to content

Commit cfc1634

Browse files
committed
Ajout de tests
1 parent 2c1974e commit cfc1634

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

data/models/canteen.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ def publicly_hidden(self):
9595
else self.exclude(publication_status=Canteen.PublicationStatus.PUBLISHED)
9696
)
9797

98+
def is_satellite(self):
99+
return self.filter(is_satellite_query())
100+
98101
def get_satellites(self, central_producer_siret):
99102
return self.filter(is_satellite_query(), central_producer_siret=central_producer_siret)
100103

@@ -124,6 +127,12 @@ def publicly_visible(self):
124127
def publicly_hidden(self):
125128
return self.get_queryset().publicly_hidden()
126129

130+
def is_satellite(self):
131+
return self.get_queryset().is_satellite()
132+
133+
def get_satellites(self, central_producer_siret):
134+
return self.get_queryset().get_satellites(central_producer_siret)
135+
127136
def has_missing_data(self):
128137
return self.get_queryset().has_missing_data()
129138

data/tests/test_canteen.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,35 @@ def test_publicly_hidden_publish_by_default(self):
8989
self.assertEqual(qs.first(), self.canteen_published_armee)
9090

9191

92+
class TestCanteenSatelliteQuerySet(TestCase):
93+
@classmethod
94+
def setUpTestData(cls):
95+
cls.canteen_central_1 = CanteenFactory(
96+
siret="75665621899905", production_type=Canteen.ProductionType.CENTRAL, satellite_canteens_count=2
97+
) # 1 missing
98+
cls.canteen_central_2 = CanteenFactory(
99+
siret="75665621899906", production_type=Canteen.ProductionType.CENTRAL, satellite_canteens_count=2
100+
)
101+
cls.canteen_on_site_central_1 = CanteenFactory(
102+
production_type=Canteen.ProductionType.ON_SITE_CENTRAL, central_producer_siret=cls.canteen_central_1.siret
103+
)
104+
cls.canteen_on_site_central_2 = CanteenFactory(
105+
production_type=Canteen.ProductionType.ON_SITE_CENTRAL, central_producer_siret=cls.canteen_central_2.siret
106+
)
107+
cls.canteen_on_site_central_2 = CanteenFactory(
108+
production_type=Canteen.ProductionType.ON_SITE_CENTRAL, central_producer_siret=cls.canteen_central_2.siret
109+
)
110+
111+
def test_is_satellite(self):
112+
self.assertEqual(Canteen.objects.count(), 5)
113+
self.assertEqual(Canteen.objects.is_satellite().count(), 3)
114+
115+
def test_get_satellites(self):
116+
self.assertEqual(Canteen.objects.count(), 5)
117+
self.assertEqual(Canteen.objects.get_satellites(self.canteen_central_1.siret).count(), 1)
118+
self.assertEqual(Canteen.objects.get_satellites(self.canteen_central_2.siret).count(), 2)
119+
120+
92121
class TestCanteenSiretOrSirenUniteLegaleQuerySet(TestCase):
93122
@classmethod
94123
def setUpTestData(cls):

0 commit comments

Comments
 (0)