From 647e3e4157e6beea2cf15863b4c5d7f3e28ec3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20S=C3=A9bille?= Date: Wed, 8 Jan 2025 11:24:07 +0100 Subject: [PATCH] employee_record: Try to improve naming of the `sent` transition --- .../commands/transfer_employee_records.py | 4 +++- itou/employee_record/models.py | 8 +++---- tests/api/employee_record_api/tests.py | 8 +++---- tests/employee_record/test_models.py | 22 +++++++++---------- .../www/employee_record_views/test_disable.py | 6 ++--- tests/www/employee_record_views/test_list.py | 4 ++-- .../employee_record_views/test_reactivate.py | 2 +- .../www/employee_record_views/test_summary.py | 2 +- 8 files changed, 29 insertions(+), 27 deletions(-) diff --git a/itou/employee_record/management/commands/transfer_employee_records.py b/itou/employee_record/management/commands/transfer_employee_records.py index f6d068805dc..2ee1517ca70 100644 --- a/itou/employee_record/management/commands/transfer_employee_records.py +++ b/itou/employee_record/management/commands/transfer_employee_records.py @@ -56,7 +56,9 @@ def _upload_batch_file(self, sftp: paramiko.SFTPClient, employee_records: list[E # and store in which file they have been sent renderer = JSONRenderer() for idx, employee_record in enumerate(employee_records, 1): - employee_record.sent(remote_path, idx, renderer.render(batch_data["lignesTelechargement"][idx - 1])) + employee_record.wait_for_asp_response( + remote_path, idx, renderer.render(batch_data["lignesTelechargement"][idx - 1]) + ) def _parse_feedback_file(self, feedback_file: str, batch: dict, dry_run: bool) -> None: """ diff --git a/itou/employee_record/models.py b/itou/employee_record/models.py index b214ff26ba7..67b2db22a44 100644 --- a/itou/employee_record/models.py +++ b/itou/employee_record/models.py @@ -98,7 +98,7 @@ def set_asp_processing_information(self, code, label, archive): class EmployeeRecordTransition(enum.StrEnum): READY = "ready" - SENT = "sent" + WAIT_FOR_ASP_RESPONSE = "wait_for_asp_response" REJECT = "reject" PROCESS = "process" DISABLE = "disable" @@ -117,7 +117,7 @@ class EmployeeRecordWorkflow(xwf_models.Workflow): CAN_BE_ARCHIVED_STATES = [Status.NEW, Status.READY, Status.REJECTED, Status.PROCESSED, Status.DISABLED] transitions = ( (EmployeeRecordTransition.READY, [Status.NEW, Status.REJECTED, Status.DISABLED], Status.READY), - (EmployeeRecordTransition.SENT, Status.READY, Status.SENT), + (EmployeeRecordTransition.WAIT_FOR_ASP_RESPONSE, Status.READY, Status.SENT), (EmployeeRecordTransition.REJECT, Status.SENT, Status.REJECTED), (EmployeeRecordTransition.PROCESS, Status.SENT, Status.PROCESSED), (EmployeeRecordTransition.DISABLE, CAN_BE_DISABLED_STATES, Status.DISABLED), @@ -318,7 +318,7 @@ def ready(self): self._fill_denormalized_fields() @xwf_models.transition() - def sent(self, asp_filename, line_number, archive): + def wait_for_asp_response(self, asp_filename, line_number, archive): """ An employee record is sent to ASP via a JSON file, The file name is stored for further feedback processing (also done via a file) @@ -553,7 +553,7 @@ class EmployeeRecordUpdateNotificationWorkflow(xwf_models.Workflow): initial_state = Status.NEW transitions = ( - (EmployeeRecordTransition.SENT, NotificationStatus.NEW, NotificationStatus.SENT), + (EmployeeRecordTransition.WAIT_FOR_ASP_RESPONSE, NotificationStatus.NEW, NotificationStatus.SENT), (EmployeeRecordTransition.REJECT, NotificationStatus.SENT, NotificationStatus.REJECTED), (EmployeeRecordTransition.PROCESS, NotificationStatus.SENT, NotificationStatus.PROCESSED), ) diff --git a/tests/api/employee_record_api/tests.py b/tests/api/employee_record_api/tests.py index 79eb6e5f7d0..89cf424b94a 100644 --- a/tests/api/employee_record_api/tests.py +++ b/tests/api/employee_record_api/tests.py @@ -101,7 +101,7 @@ def test_fetch_employee_record_list(self, api_client, mocker, faker): # Get list without filtering by status (PROCESSED) # note: there is no way to create a processed employee record # (and this is perfectly normal) - self.employee_record.sent(faker.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) process_code, process_message = "0000", "La ligne de la fiche salarié a été enregistrée avec succès." # There should be no result at this point @@ -131,7 +131,7 @@ def test_fetch_employee_record_list(self, api_client, mocker, faker): result = response.json() assert len(result.get("results")) == 0 - employee_record_sent.sent(faker.asp_batch_filename(), 1, None) + employee_record_sent.wait_for_asp_response(faker.asp_batch_filename(), 1, None) response = api_client.get(ENDPOINT_URL + "?status=SENT", format="json") assert response.status_code == 200 @@ -143,7 +143,7 @@ def test_fetch_employee_record_list(self, api_client, mocker, faker): job_application = JobApplicationWithCompleteJobSeekerProfileFactory(to_company=self.siae) employee_record_rejected = EmployeeRecord.from_job_application(job_application=job_application) employee_record_rejected.ready() - employee_record_rejected.sent(faker.asp_batch_filename(), 1, None) + employee_record_rejected.wait_for_asp_response(faker.asp_batch_filename(), 1, None) # There should be no result at this point response = api_client.get(ENDPOINT_URL + "?status=REJECTED", format="json") @@ -230,7 +230,7 @@ def test_status_array_parameter(self, api_client, mocker, faker): ) employee_record = EmployeeRecord.from_job_application(job_application_2) employee_record.ready() - employee_record.sent(faker.asp_batch_filename(), 1, None) + employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) member = employee_record.job_application.to_company.members.first() api_client.force_login(member) diff --git a/tests/employee_record/test_models.py b/tests/employee_record/test_models.py index 22e862a825d..323ce3ee7fb 100644 --- a/tests/employee_record/test_models.py +++ b/tests/employee_record/test_models.py @@ -348,14 +348,14 @@ def test_state_ready( assert self.employee_record.status == Status.READY def test_state_sent(self, faker): - self.employee_record.sent(faker.asp_batch_filename(), 42, "{}") + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 42, "{}") assert self.employee_record.status == Status.SENT assert self.employee_record.asp_batch_line_number == 42 assert self.employee_record.archived_json == {} def test_state_rejected(self, faker): - self.employee_record.sent(faker.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) self.employee_record.reject("12", "JSON Invalide", "{}") assert self.employee_record.status == Status.REJECTED @@ -364,7 +364,7 @@ def test_state_rejected(self, faker): assert self.employee_record.archived_json == {} def test_state_processed(self, faker): - self.employee_record.sent(faker.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) process_code, process_message = ( EmployeeRecord.ASP_PROCESSING_SUCCESS_CODE, @@ -378,7 +378,7 @@ def test_state_processed(self, faker): assert self.employee_record.archived_json == {} def test_state_processed_when_archive_is_none(self, faker): - self.employee_record.sent(faker.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) process_code, process_message = ( EmployeeRecord.ASP_PROCESSING_SUCCESS_CODE, @@ -392,7 +392,7 @@ def test_state_processed_when_archive_is_none(self, faker): assert self.employee_record.archived_json is None def test_state_processed_when_archive_is_empty(self, faker): - self.employee_record.sent(faker.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) process_code, process_message = ( EmployeeRecord.ASP_PROCESSING_SUCCESS_CODE, @@ -406,7 +406,7 @@ def test_state_processed_when_archive_is_empty(self, faker): assert self.employee_record.archived_json == "" def test_state_processed_when_archive_is_not_json(self, faker): - self.employee_record.sent(faker.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) process_code, process_message = ( EmployeeRecord.ASP_PROCESSING_SUCCESS_CODE, @@ -426,7 +426,7 @@ def test_state_disabled(self, faker): assert self.employee_record.status == Status.READY # Employee record in SENT state can't be disabled - self.employee_record.sent(faker.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) with pytest.raises(xworkflows.InvalidTransitionError): self.employee_record.disable() assert self.employee_record.status == Status.SENT @@ -451,14 +451,14 @@ def test_state_disabled(self, faker): assert self.employee_record.status == Status.DISABLED def test_state_disabled_with_reject(self, faker): - self.employee_record.sent(faker.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) self.employee_record.reject("12", "JSON Invalide", None) self.employee_record.disable() assert self.employee_record.status == Status.DISABLED def test_reactivate(self, faker): - self.employee_record.sent(faker.unique.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.unique.asp_batch_filename(), 1, None) process_code = EmployeeRecord.ASP_PROCESSING_SUCCESS_CODE process_message = "La ligne de la fiche salarié a été enregistrée avec succès." archive_first = '{"libelleTraitement":"La ligne de la fiche salarié a été enregistrée avec succès [1]."}' @@ -476,7 +476,7 @@ def test_reactivate(self, faker): filename_second = faker.unique.asp_batch_filename() archive_second = '{"libelleTraitement":"La ligne de la fiche salarié a été enregistrée avec succès [2]."}' - self.employee_record.sent(filename_second, 1, archive_second) + self.employee_record.wait_for_asp_response(filename_second, 1, archive_second) assert self.employee_record.asp_batch_file == filename_second assert self.employee_record.archived_json == json.loads(archive_second) @@ -496,7 +496,7 @@ def test_reactivate_when_the_siae_has_changed(self, faker): assert self.employee_record.siret == old_company.siret assert self.employee_record.asp_id == old_company.convention.asp_id - self.employee_record.sent(faker.unique.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.unique.asp_batch_filename(), 1, None) self.employee_record.process("", "", None) self.employee_record.disable() diff --git a/tests/www/employee_record_views/test_disable.py b/tests/www/employee_record_views/test_disable.py index 94530601382..857620e7e9c 100644 --- a/tests/www/employee_record_views/test_disable.py +++ b/tests/www/employee_record_views/test_disable.py @@ -55,7 +55,7 @@ def test_disable_employee_record_ready(self, client): def test_disable_employee_record_sent(self, client, faker): self.employee_record.ready() - self.employee_record.sent(faker.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) self.employee_record.refresh_from_db() assert self.employee_record.status == Status.SENT @@ -70,7 +70,7 @@ def test_disable_employee_record_sent(self, client, faker): def test_disable_employee_record_rejected(self, client, faker): self.employee_record.ready() - self.employee_record.sent(faker.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) err_code, err_message = "12", "JSON Invalide" self.employee_record.reject(err_code, err_message, None) @@ -89,7 +89,7 @@ def test_disable_employee_record_rejected(self, client, faker): def test_disable_employee_record_completed(self, client, faker): self.employee_record.ready() - self.employee_record.sent(faker.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) process_code, process_message = "0000", "La ligne de la fiche salarié a été enregistrée avec succès." self.employee_record.process(process_code, process_message, "{}") diff --git a/tests/www/employee_record_views/test_list.py b/tests/www/employee_record_views/test_list.py index a714431fc92..46d70c88ab8 100644 --- a/tests/www/employee_record_views/test_list.py +++ b/tests/www/employee_record_views/test_list.py @@ -252,7 +252,7 @@ def test_rejected_without_custom_message(self, client, faker): record = employee_record_factories.EmployeeRecordWithProfileFactory(job_application__to_company=self.company) record.ready() - record.sent(faker.asp_batch_filename(), 1, None) + record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) record.reject("0012", "JSON Invalide", None) response = client.get(self.URL, data={"status": Status.REJECTED}) @@ -367,7 +367,7 @@ def test_rejected_employee_records_sorted(self, client, snapshot): ) for i, record in enumerate((recordA, recordZ)): record.ready() - record.sent(f"RIAE_FS_2021041013000{i}.json", 1, None) + record.wait_for_asp_response(f"RIAE_FS_2021041013000{i}.json", 1, None) record.reject("0012", "JSON Invalide", None) # Zzzzz's hiring start is more recent diff --git a/tests/www/employee_record_views/test_reactivate.py b/tests/www/employee_record_views/test_reactivate.py index 6f56aa026dc..c4dc3eee58f 100644 --- a/tests/www/employee_record_views/test_reactivate.py +++ b/tests/www/employee_record_views/test_reactivate.py @@ -23,7 +23,7 @@ def setup_method(self): def test_reactivate_employee_record(self, client, faker): self.employee_record.ready() - self.employee_record.sent(faker.asp_batch_filename(), 1, None) + self.employee_record.wait_for_asp_response(faker.asp_batch_filename(), 1, None) process_code, process_message = "0000", "La ligne de la fiche salarié a été enregistrée avec succès." self.employee_record.process(process_code, process_message, "{}") self.employee_record.disable() diff --git a/tests/www/employee_record_views/test_summary.py b/tests/www/employee_record_views/test_summary.py index 3aeb7540104..ca7203a0e38 100644 --- a/tests/www/employee_record_views/test_summary.py +++ b/tests/www/employee_record_views/test_summary.py @@ -40,7 +40,7 @@ def test_asp_batch_file_infos(self, client): assertNotContains(response, HORODATAGE) self.employee_record.ready() - self.employee_record.sent("RIAE_FS_20210410130000.json", 1, None) + self.employee_record.wait_for_asp_response("RIAE_FS_20210410130000.json", 1, None) response = client.get(self.url) assertContains(response, HORODATAGE)