Skip to content

Commit

Permalink
update kind during c1 sync if it is known
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Dec 5, 2024
1 parent d69ae37 commit aac2960
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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):
Expand Down
62 changes: 62 additions & 0 deletions lemarche/siaes/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,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):
Expand Down

0 comments on commit aac2960

Please sign in to comment.