Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structure : nouvelle property "kind_parent" #955

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lemarche/api/siaes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -49,6 +50,7 @@ class Meta:
"siret",
"nature",
"kind",
"kind_parent",
"presta_type",
"contact_website",
"contact_email",
Expand Down Expand Up @@ -85,6 +87,7 @@ class Meta:
"siret",
"nature",
"kind",
"kind_parent",
"presta_type",
"contact_website",
"logo_url",
Expand Down
10 changes: 7 additions & 3 deletions lemarche/api/siaes/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand All @@ -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])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -174,14 +176,15 @@ 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)
self.assertTrue("name" in response.data)
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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions lemarche/siaes/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 12 additions & 4 deletions lemarche/siaes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,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:
Expand Down Expand Up @@ -1020,10 +1032,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
Expand Down
20 changes: 12 additions & 8 deletions lemarche/siaes/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ def test_update_last_updated_fields(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")
Expand Down Expand Up @@ -142,13 +146,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):
Expand Down