From a8acdf57be1043cc1dcda679500437580ab7176f Mon Sep 17 00:00:00 2001 From: dinesh Date: Mon, 2 Dec 2024 11:02:38 -0800 Subject: [PATCH] case file test cases --- .../src/compliance_api/services/case_file.py | 16 ++++--------- .../tests/integration/api/test_case_file.py | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/compliance-api/src/compliance_api/services/case_file.py b/compliance-api/src/compliance_api/services/case_file.py index 50782292..79738616 100644 --- a/compliance-api/src/compliance_api/services/case_file.py +++ b/compliance-api/src/compliance_api/services/case_file.py @@ -78,7 +78,7 @@ def update(cls, case_file_id: int, case_file_data: dict, ho_session=None): _access_check_for_update(case_file_id) case_file_obj = { "primary_officer_id": case_file_data.get("primary_officer_id", None), - "project_description": case_file_data.get("project_description", None) + "project_description": case_file_data.get("project_description", None), } with session_scope() as session: updated_case_file = CaseFileModel.update_case_file( @@ -154,16 +154,10 @@ def change_case_file_status(cls, case_file_id, status_data): if not case_file: raise ResourceNotFoundError("Case file not found.") status_enum = CaseFileStatusEnum(status_data.get("status")) - if ( - case_file.case_file_status == CaseFileStatusEnum.OPEN - and status_enum == CaseFileStatusEnum.OPEN - ): - raise UnprocessableEntityError("The case file is already in Open status.") - if ( - case_file.case_file_status == CaseFileStatusEnum.CLOSED - and status_enum == CaseFileStatusEnum.CLOSED - ): - raise UnprocessableEntityError("The case file is already in Open status.") + if status_enum == case_file.case_file_status: + raise UnprocessableEntityError( + f"The case file is already in {status_enum.value} status." + ) CaseFileModel.change_status(case_file_id, status_enum) diff --git a/compliance-api/tests/integration/api/test_case_file.py b/compliance-api/tests/integration/api/test_case_file.py index 537fc0ae..8094c2f2 100644 --- a/compliance-api/tests/integration/api/test_case_file.py +++ b/compliance-api/tests/integration/api/test_case_file.py @@ -341,3 +341,26 @@ def test_case_file_update_with_primary(client, jwt, created_staff, auth_header_s url = urljoin(API_BASE_URL, f"case-files/{created_result.json.get('id')}") result = client.patch(url, data=json.dumps(case_file_data), headers=headers) assert result.status_code == HTTPStatus.OK + +def test_case_file_close(client, jwt, created_staff, auth_header_super_user): + """Update as primary.""" + case_file_data = copy.copy(CasefileScenario.default_value.value) + case_file_data["case_file_number"] = fake.word() + case_file_data["primary_officer_id"] = created_staff.id + created_result = client.post( + urljoin(API_BASE_URL, "case-files"), + data=json.dumps(case_file_data), + headers=auth_header_super_user, + ) + + header = TokenJWTClaims.default.value + header["preferred_username"] = created_staff.auth_user_guid + headers = factory_auth_header(jwt=jwt, claims=header) + print(created_result) + url = urljoin(API_BASE_URL, f"case-files/{created_result.json.get('id')}/status") + result = client.patch(url, data=json.dumps({"status": "OPEN"}), headers=headers) + assert result.status_code == HTTPStatus.UNPROCESSABLE_ENTITY + result = client.patch(url, data=json.dumps({"status": "CLOSED"}), headers=headers) + assert result.status_code == HTTPStatus.NO_CONTENT + result = client.patch(url, data=json.dumps({"status": "CLOSED"}), headers=headers) + assert result.status_code == HTTPStatus.UNPROCESSABLE_ENTITY \ No newline at end of file