From 3abb922b8a7051525bf01514d321122b31cdd141 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Thu, 26 Oct 2023 14:31:05 +0200 Subject: [PATCH] Structure : nouvelle property "kind_parent" (#955) * Siae: add kind_parent property * Add field to API --- lemarche/api/siaes/serializers.py | 3 +++ lemarche/api/siaes/tests.py | 10 +++++++--- lemarche/siaes/constants.py | 4 ++++ lemarche/siaes/models.py | 16 ++++++++++++---- lemarche/siaes/tests.py | 20 ++++++++++++-------- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/lemarche/api/siaes/serializers.py b/lemarche/api/siaes/serializers.py index 3c7bd4951..b2bd5dcfe 100644 --- a/lemarche/api/siaes/serializers.py +++ b/lemarche/api/siaes/serializers.py @@ -33,6 +33,7 @@ class Meta: class SiaeDetailSerializer(serializers.ModelSerializer): + kind_parent = serializers.ReadOnlyField() sectors = SectorSimpleSerializer(many=True) networks = NetworkSimpleSerializer(many=True) offers = SiaeOfferSimpleSerializer(many=True) @@ -49,6 +50,7 @@ class Meta: "siret", "nature", "kind", + "kind_parent", "presta_type", "contact_website", "contact_email", @@ -85,6 +87,7 @@ class Meta: "siret", "nature", "kind", + "kind_parent", "presta_type", "contact_website", "logo_url", diff --git a/lemarche/api/siaes/tests.py b/lemarche/api/siaes/tests.py index abfdcf433..c91117bd2 100644 --- a/lemarche/api/siaes/tests.py +++ b/lemarche/api/siaes/tests.py @@ -15,7 +15,7 @@ def setUpTestData(cls): SiaeFactory() UserFactory(api_key="admin") - def test_should_return_siae_sublist_to_anonmyous_users(self): + def test_should_return_siae_sublist_to_anonymous_users(self): url = reverse("api:siae-list") # anonymous user response = self.client.get(url) # self.assertEqual(response.data["count"], 12) @@ -25,6 +25,7 @@ def test_should_return_siae_sublist_to_anonmyous_users(self): self.assertTrue("name" in response.data[0]) self.assertTrue("siret" in response.data[0]) self.assertTrue("kind" in response.data[0]) + self.assertTrue("kind_parent" in response.data[0]) self.assertTrue("presta_type" in response.data[0]) self.assertTrue("department" in response.data[0]) self.assertTrue("created_at" in response.data[0]) @@ -38,6 +39,7 @@ def test_should_return_detailed_siae_list_with_pagination_to_authenticated_users self.assertTrue("name" in response.data["results"][0]) self.assertTrue("siret" in response.data["results"][0]) self.assertTrue("kind" in response.data["results"][0]) + self.assertTrue("kind_parent" in response.data["results"][0]) self.assertTrue("presta_type" in response.data["results"][0]) self.assertTrue("department" in response.data["results"][0]) self.assertTrue("created_at" in response.data["results"][0]) @@ -92,7 +94,7 @@ def test_should_return_siae_list(self): self.assertEqual(response.data["count"], 4 + 2 + 2) self.assertEqual(len(response.data["results"]), 4 + 2 + 2) - def test_should_not_filter_siae_list_for_anonmyous_user(self): + def test_should_not_filter_siae_list_for_anonymous_user(self): # single url = reverse("api:siae-list") + f"?kind={siae_constants.KIND_ETTI}" # anonymous user response = self.client.get(url) @@ -174,7 +176,7 @@ def setUpTestData(cls): cls.siae = SiaeFactory() UserFactory(api_key="admin") - def test_should_return_simple_siae_object_to_anonmyous_users(self): + def test_should_return_simple_siae_object_to_anonymous_users(self): url = reverse("api:siae-detail", args=[self.siae.id]) # anonymous user response = self.client.get(url) self.assertTrue("id" in response.data) @@ -182,6 +184,7 @@ def test_should_return_simple_siae_object_to_anonmyous_users(self): self.assertTrue("siret" in response.data) self.assertTrue("slug" in response.data) self.assertTrue("kind" in response.data) + self.assertTrue("kind_parent" in response.data) self.assertTrue("presta_type" in response.data) self.assertTrue("sectors" not in response.data) self.assertTrue("networks" not in response.data) @@ -197,6 +200,7 @@ def test_should_return_detailed_siae_object_to_authenticated_users(self): self.assertTrue("siret" in response.data) self.assertTrue("slug" in response.data) self.assertTrue("kind" in response.data) + self.assertTrue("kind_parent" in response.data) self.assertTrue("presta_type" in response.data) self.assertTrue("sectors" in response.data) self.assertTrue("networks" in response.data) diff --git a/lemarche/siaes/constants.py b/lemarche/siaes/constants.py index d29b44e19..e7471633a 100644 --- a/lemarche/siaes/constants.py +++ b/lemarche/siaes/constants.py @@ -40,6 +40,10 @@ ) KIND_CHOICES_WITH_EXTRA = KIND_CHOICES_WITH_EXTRA_INSERTION + KIND_CHOICES_WITH_EXTRA_HANDICAP +KIND_GROUP_INSERTION_NAME = "Insertion" +KIND_GROUP_INSERTION_LIST = [k[0] for k in KIND_CHOICES_WITH_EXTRA_INSERTION] +KIND_GROUP_HANDICAP_NAME = "Handicap" +KIND_GROUP_HANDICAP_LIST = [k[0] for k in KIND_CHOICES_WITH_EXTRA_HANDICAP] PRESTA_DISP = "DISP" PRESTA_PREST = "PREST" diff --git a/lemarche/siaes/models.py b/lemarche/siaes/models.py index 04f9c8cd3..d36d7394c 100644 --- a/lemarche/siaes/models.py +++ b/lemarche/siaes/models.py @@ -862,6 +862,18 @@ def save(self, *args, **kwargs): else: raise e + @property + def kind_is_esat_or_ea_or_eatt(self): + return self.kind in [siae_constants.KIND_ESAT, siae_constants.KIND_EA, siae_constants.KIND_EATT] + + @property + def kind_parent(self): + if self.kind in siae_constants.KIND_GROUP_INSERTION_LIST: + return siae_constants.KIND_GROUP_INSERTION_NAME + if self.kind in siae_constants.KIND_GROUP_HANDICAP_LIST: + return siae_constants.KIND_GROUP_HANDICAP_NAME + return "" + @property def latitude(self): if self.coords: @@ -1017,10 +1029,6 @@ def source_display(self): else: return "l'ASP" - @property - def kind_is_esat_or_ea_or_eatt(self): - return self.kind in [siae_constants.KIND_ESAT, siae_constants.KIND_EA, siae_constants.KIND_EATT] - @property def completion_percent(self): score, total = 0, 0 diff --git a/lemarche/siaes/tests.py b/lemarche/siaes/tests.py index 6510caa3b..6a2c804b8 100644 --- a/lemarche/siaes/tests.py +++ b/lemarche/siaes/tests.py @@ -71,8 +71,12 @@ def test_with_siae_stats(self): class SiaeModelTest(TestCase): - def setUp(self): - pass + @classmethod + def setUpTestData(cls): + cls.siae_ei = SiaeFactory(kind=siae_constants.KIND_EI) + cls.siae_ea = SiaeFactory(kind=siae_constants.KIND_EA) + cls.siae_eatt = SiaeFactory(kind=siae_constants.KIND_EATT) + cls.siae_esat = SiaeFactory(kind=siae_constants.KIND_ESAT) def test_str(self): siae = SiaeFactory(name="Ma boite") @@ -163,13 +167,13 @@ def test_is_missing_content_property(self): self.assertFalse(siae_full_2.is_missing_content) def test_kind_is_esat_or_ea_or_eatt_property(self): - siae_esat = SiaeFactory(kind=siae_constants.KIND_ESAT) - siae_ea = SiaeFactory(kind=siae_constants.KIND_EA) - siae_eatt = SiaeFactory(kind=siae_constants.KIND_EATT) - siae_ei = SiaeFactory(kind=siae_constants.KIND_EI) - for siae in [siae_esat, siae_ea, siae_eatt]: + for siae in [self.siae_esat, self.siae_ea, self.siae_eatt]: self.assertTrue(siae.kind_is_esat_or_ea_or_eatt) - self.assertFalse(siae_ei.kind_is_esat_or_ea_or_eatt) + self.assertFalse(self.siae_ei.kind_is_esat_or_ea_or_eatt) + + def test_kind_parent_property(self): + self.assertEqual(self.siae_ei.kind_parent, "Insertion") + self.assertEqual(self.siae_esat.kind_parent, "Handicap") class SiaeModelSaveTest(TestCase):