Skip to content

Commit

Permalink
add tests for siae with several activities
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Oct 15, 2024
1 parent 16798c7 commit 731d938
Showing 1 changed file with 73 additions and 2 deletions.
75 changes: 73 additions & 2 deletions lemarche/tenders/tests/test_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 731d938

Please sign in to comment.