Skip to content

Commit

Permalink
employee_record: Try to improve naming of the sent transition
Browse files Browse the repository at this point in the history
  • Loading branch information
rsebille committed Jan 8, 2025
1 parent 33b19c5 commit 647e3e4
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
8 changes: 4 additions & 4 deletions itou/employee_record/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
)
Expand Down
8 changes: 4 additions & 4 deletions tests/api/employee_record_api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions tests/employee_record/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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]."}'
Expand All @@ -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)

Expand All @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions tests/www/employee_record_views/test_disable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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, "{}")

Expand Down
4 changes: 2 additions & 2 deletions tests/www/employee_record_views/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/www/employee_record_views/test_reactivate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/www/employee_record_views/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 647e3e4

Please sign in to comment.