From 752e8075faf43f45d9bb1a13e83874ce49bed1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Reuiller?= Date: Wed, 4 Dec 2024 17:22:41 +0100 Subject: [PATCH] update kind during c1 sync if it is known --- .../commands/sync_with_emplois_inclusion.py | 12 ++-- lemarche/siaes/tests/test_commands.py | 62 +++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/lemarche/siaes/management/commands/sync_with_emplois_inclusion.py b/lemarche/siaes/management/commands/sync_with_emplois_inclusion.py index 8993ae7d1..8cdd26ca4 100644 --- a/lemarche/siaes/management/commands/sync_with_emplois_inclusion.py +++ b/lemarche/siaes/management/commands/sync_with_emplois_inclusion.py @@ -23,7 +23,7 @@ UPDATE_FIELDS = [ # "name", # what happens to the slug if the name is updated? # "brand", # see UPDATE_FIELDS_IF_EMPTY - # "kind" + "kind", "siret", "siret_is_valid", "naf", @@ -213,9 +213,13 @@ def filter_c1_export(self, c1_list): c1_list_filtered = [] for c1_siae in c1_list: - if c1_siae["kind"] not in ("RESERVED",): - c1_list_filtered.append(c1_siae) - + if c1_siae["kind"] not in ("RESERVED",): # do nothing if kind is filtered as reserved + if c1_siae["kind"] in siae_constants.KIND_INSERTION_LIST + siae_constants.KIND_HANDICAP_LIST: + c1_list_filtered.append(c1_siae) + else: + logger.error( + f"Kind not supported: {c1_siae['kind']}/{c1_siae['id']}/{c1_siae['name']}/{c1_siae['siret']}" + ) return c1_list_filtered def c4_update(self, c1_list, dry_run): diff --git a/lemarche/siaes/tests/test_commands.py b/lemarche/siaes/tests/test_commands.py index 987373b89..e01e7868c 100644 --- a/lemarche/siaes/tests/test_commands.py +++ b/lemarche/siaes/tests/test_commands.py @@ -242,6 +242,68 @@ def test_sync_with_emplois_inclusion_with_duplicate_brand_name_on_update(self, m self.assertEqual(Siae.objects.filter(name="Other New SIAE").count(), 1) # error logged but sync continued + @patch("lemarche.utils.apis.api_emplois_inclusion.get_siae_list") + def test_sync_with_emplois_inclusion_with_kind_not_supported(self, mock_get_siae_list): + mock_get_siae_list.return_value = [ + { + "id": 123, + "siret": "12345678901234", + "kind": "FAKE", + "name": "Fake SIAE", + "naf": "8899B", + "brand": "", + "phone": "", + "email": "", + "website": "", + "description": "", + "address_line_1": "1 rue Test", + "address_line_2": "", + "post_code": "37000", + "city": "Tours", + "department": "37", + "source": "ASP", + "latitude": 0, + "longitude": 0, + "convention_is_active": True, + "convention_asp_id": 0, + "admin_name": "", + "admin_email": "", + }, + { + "id": 124, + "siret": "12345678901235", + "naf": "8899B", + "kind": "EI", + "name": "Other SIAE", + "brand": "", + "phone": "", + "email": "", + "website": "", + "description": "", + "address_line_1": "1 rue Test", + "address_line_2": "", + "post_code": "37000", + "city": "Tours", + "department": "37", + "source": "ASP", + "latitude": 0, + "longitude": 0, + "convention_is_active": True, + "convention_asp_id": 0, + "admin_name": "", + "admin_email": "", + }, + ] + os.environ["API_EMPLOIS_INCLUSION_TOKEN"] = "test" + with self.assertLogs("lemarche.siaes.management.commands.sync_with_emplois_inclusion", level="ERROR") as log: + call_command("sync_with_emplois_inclusion") + + self.assertIn("Kind not supported: FAKE", log.output[0]) + + # Verify only one SIAE was created to check if the sync was not interrupted + self.assertEqual(Siae.objects.count(), 1) + self.assertEqual(Siae.objects.first().name, "Other SIAE") + class SiaeActivitiesCreateCommandTest(TransactionTestCase): def setUp(self):