From 731d93815c8d853c594bbb4a9737e2d25eb77d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Reuiller?= Date: Tue, 15 Oct 2024 12:12:02 +0200 Subject: [PATCH] add tests for siae with several activities --- lemarche/tenders/tests/test_matching.py | 75 ++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/lemarche/tenders/tests/test_matching.py b/lemarche/tenders/tests/test_matching.py index 264af85d6..cdec15b38 100644 --- a/lemarche/tenders/tests/test_matching.py +++ b/lemarche/tenders/tests/test_matching.py @@ -2,17 +2,19 @@ from django.test import TestCase from lemarche.perimeters.factories import PerimeterFactory +from lemarche.perimeters.models import Perimeter from lemarche.sectors.factories import SectorFactory from lemarche.siaes import constants as siae_constants from lemarche.siaes.factories import SiaeActivityFactory, SiaeFactory +from lemarche.siaes.models import Siae, SiaeActivity from lemarche.tenders.factories import TenderFactory -from lemarche.tenders.models import Perimeter, Siae -class TenderMatchingTest(TestCase): +class TenderMatchingActivitiesTest(TestCase): @classmethod def setUpTestData(cls): cls.sectors = [SectorFactory() for i in range(10)] + cls.other_sector = SectorFactory() cls.perimeter_paris = PerimeterFactory(department_code="75", post_codes=["75019", "75018"]) cls.perimeter_marseille = PerimeterFactory(coords=Point(43.35101634452076, 5.379616625955892)) cls.perimeters = [cls.perimeter_paris, PerimeterFactory()] @@ -32,6 +34,13 @@ def setUpTestData(cls): geo_range_custom_distance=100, ) cls.siae_one_activity.locations.set([cls.perimeter_paris]) + cls.siae_one_other_activity = SiaeActivityFactory( + siae=cls.siae_one, + sector_group=cls.other_sector.group, + presta_type=[siae_constants.PRESTA_BUILD], + with_country_perimeter=True, + ) + cls.siae_one_other_activity.sectors.add(cls.other_sector) cls.siae_two = SiaeFactory( is_active=True, @@ -45,10 +54,24 @@ def setUpTestData(cls): geo_range=siae_constants.GEO_RANGE_CUSTOM, geo_range_custom_distance=10, ) + for i in range(5): cls.siae_one_activity.sectors.add(cls.sectors[i]) cls.siae_two_activity.sectors.add(cls.sectors[i + 5]) + cls.siae_three = SiaeFactory( + is_active=True, + kind=siae_constants.KIND_ESAT, + coords=Point(46.15926, -1.15099), # La Rochelle + ) + cls.siae_three_activity = SiaeActivityFactory( + siae=cls.siae_three, + sector_group=cls.other_sector.group, + presta_type=[siae_constants.PRESTA_BUILD], + with_country_perimeter=True, + ) + cls.siae_three_activity.sectors.add(cls.other_sector) + def test_matching_siae_presta_type(self): tender = TenderFactory(presta_type=[], sectors=self.sectors, perimeters=self.perimeters) siae_found_list = Siae.objects.filter_with_tender_through_activities(tender) @@ -237,6 +260,16 @@ def test_matching_siae_country(self): # we should have only siaes with country geo range self.assertEqual(len(siae_found_list_2), 2 + 0) + # tender other sector perimeter custom with include_country_area = True + tender_3 = TenderFactory(sectors=[self.other_sector], is_country_area=True) + siae_found_list_3 = Siae.objects.filter_with_tender_through_activities(tender_3) + self.assertEqual(len(siae_found_list_3), 2) + self.assertIn(self.siae_one, siae_found_list_3) + self.assertIn(self.siae_three, siae_found_list_3) + tender_3.perimeters.set(self.perimeters) + siae_found_list_3 = Siae.objects.filter_with_tender_through_activities(tender_3) + self.assertEqual(len(siae_found_list_3), 2 + 0) # other siae isn't in the same sector + def test_matching_siae_perimeters_custom_2(self): # add Siae with geo_range_department (75) siae_department = SiaeFactory(is_active=True) @@ -268,6 +301,44 @@ def test_matching_siae_perimeters_france(self): siae_found_list = Siae.objects.filter_with_tender_through_activities(tender) self.assertEqual(len(siae_found_list), 1) + def test_matching_siae_two_matching_activities(self): + sector1 = SectorFactory() + sector2 = SectorFactory() + siae = SiaeFactory( + is_active=True, + kind=siae_constants.KIND_AI, + coords=Point(48.86385199985207, 2.337071483848432), # Paris + ) + siae_activity1 = SiaeActivityFactory( + siae=siae, + sector_group=sector1.group, + presta_type=[siae_constants.PRESTA_PREST], + with_zones_perimeter=True, + ) + siae_activity1.sectors.add(sector1) + siae_activity1.locations.set([self.perimeter_paris]) + + siae_activity2 = SiaeActivityFactory( + siae=siae, + sector_group=sector2.group, + presta_type=[siae_constants.PRESTA_BUILD], + with_zones_perimeter=True, + ) + siae_activity2.sectors.add(sector2) + siae_activity2.locations.set([self.perimeter_paris]) + + tender = TenderFactory( + presta_type=[siae_constants.PRESTA_PREST, siae_constants.PRESTA_BUILD], + sectors=[sector1, sector2], + perimeters=[self.perimeter_paris], + ) + + activities_found_list = SiaeActivity.objects.filter_with_tender(tender) + siae_found_list = Siae.objects.filter_with_tender_through_activities(tender) + self.assertEqual(len(activities_found_list), 2) + self.assertEqual(len(siae_found_list), 1) + self.assertIn(siae, siae_found_list) + def test_no_siaes(self): # tender with empty sectors list tender = TenderFactory(sectors=[SectorFactory()], perimeters=self.perimeters)