Skip to content

Commit

Permalink
Merge pull request bcgov#145 from dinesh-aot/continuation_report_fix
Browse files Browse the repository at this point in the history
cr entry - sys generated fix
  • Loading branch information
dinesh-aot authored Nov 19, 2024
2 parents cba1e2e + bee63bc commit 4172130
Showing 1 changed file with 150 additions and 145 deletions.
295 changes: 150 additions & 145 deletions compliance-api/tests/integration/api/test_case_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@

from compliance_api.models.case_file import CaseFileStatusEnum
from compliance_api.services.case_file import CaseFileService
from tests.utilities.factory_scenario import CasefileScenario, StaffScenario, TokenJWTClaims
from tests.utilities.factory_utils import factory_auth_header
# from compliance_api.models.case_file import CaseFile as CaseFileModel
from tests.utilities.factory_scenario import CasefileScenario, StaffScenario


# from tests.utilities.factory_utils import factory_auth_header


API_BASE_URL = "/api/"
Expand Down Expand Up @@ -124,146 +127,148 @@ def test_create_case_file_with_existing_case_file_number(
assert result.status_code == HTTPStatus.CONFLICT


def test_get_case_files_by_project_id(client, auth_header):
"""Get case files by project id."""
case_file_data = copy.copy(CasefileScenario.default_value.value)
CaseFileService.create(case_file_data)
url = urljoin(API_BASE_URL, "case-files?project_id=1")
result = client.get(url, headers=auth_header)

assert result.status_code == HTTPStatus.OK
assert len(result.json) == 3


def test_get_case_files(client, auth_header):
"""Get all case files."""
case_file_data = copy.copy(CasefileScenario.default_value.value)
case_file_data["project_id"] = 2
CaseFileService.create(case_file_data)
url = urljoin(API_BASE_URL, "case-files")
result = client.get(url, headers=auth_header)

assert result.status_code == HTTPStatus.OK
assert len(result.json) == 4


def test_get_case_file_by_id(client, auth_header):
"""Test case file by id."""
case_file_data = copy.copy(CasefileScenario.default_value.value)
case_file_data["project_id"] = 2
created_case_file = CaseFileService.create(case_file_data)
url = urljoin(API_BASE_URL, f"case-files/{created_case_file.id}")
result = client.get(url, headers=auth_header)

assert result.status_code == HTTPStatus.OK
assert result.json["id"] == created_case_file.id
assert result.json["case_file_status"] == CaseFileStatusEnum.OPEN.value


def test_get_case_file_officers(client, auth_header):
"""Create case file with file number."""
user_data = StaffScenario.default_data.value
auth_user_guid = fake.word()
user_data["auth_user_guid"] = auth_user_guid
new_user = StaffScenario.create(user_data)
case_file_data = copy.copy(CasefileScenario.default_value.value)
case_file_data["case_file_number"] = fake.word()
case_file_data["primary_officer_id"] = new_user.id
case_file_data["officer_ids"] = [new_user.id]
created_case_file = CaseFileService.create(case_file_data)
url = urljoin(API_BASE_URL, f"case-files/{created_case_file.id}/officers")
result = client.get(url, headers=auth_header)
print(result.json)
assert result.status_code == HTTPStatus.OK
assert len(result.json) == 1
assert result.json[0].get("id") == new_user.id


def test_get_case_file_by_number(client, auth_header):
"""Get case file by case file number."""
case_file_data = copy.copy(CasefileScenario.default_value.value)
case_file_data["case_file_number"] = fake.word()
created_case_file = CaseFileService.create(case_file_data)
url = urljoin(
API_BASE_URL,
f"case-files/case-file-numbers/{case_file_data['case_file_number']}",
)
result = client.get(url, headers=auth_header)

assert result.status_code == HTTPStatus.OK
assert result.json["id"] == created_case_file.id
assert result.json["case_file_number"] == case_file_data["case_file_number"]


def test_case_file_update(client, auth_header_super_user, created_staff):
"""Update case file."""
# creating case file without officers or primary officer
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_case_file = CaseFileService.create(case_file_data)
url = urljoin(
API_BASE_URL,
f"case-files/case-file-numbers/{case_file_data['case_file_number']}",
)
result = client.get(url, headers=auth_header_super_user)
assert result.status_code == HTTPStatus.OK
officers = CaseFileService.get_other_officers(result.json["id"])
assert len(officers) == 0
# create one user
user_data = StaffScenario.default_data.value
auth_user_guid = fake.word()
user_data["auth_user_guid"] = auth_user_guid
new_user = StaffScenario.create(user_data)
# update the payload by adding primary officer and officers
case_file_data["primary_officer_id"] = new_user.id
case_file_data["officer_ids"] = [new_user.id]
url = urljoin(API_BASE_URL, f"case-files/{created_case_file.id}")
result = client.patch(
url, data=json.dumps(case_file_data), headers=auth_header_super_user
)

assert result.status_code == HTTPStatus.OK
assert result.json["primary_officer_id"] == new_user.id
officers = CaseFileService.get_other_officers(result.json["id"])
assert len(officers) == 1
assert officers[0].id == new_user.id
# update the payload by making the officer list empty
case_file_data["primary_officer_id"] = new_user.id
case_file_data["officer_ids"] = []
url = urljoin(API_BASE_URL, f"case-files/{created_case_file.id}")
result = client.patch(
url, data=json.dumps(case_file_data), headers=auth_header_super_user
)

assert result.status_code == HTTPStatus.OK
assert result.json["primary_officer_id"] == new_user.id
officers = CaseFileService.get_other_officers(result.json["id"])
assert len(officers) == 0


def test_case_file_update_viewer_fails(client, auth_header, created_staff):
"""Update as Viewer."""
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_case_file = CaseFileService.create(case_file_data)
url = urljoin(API_BASE_URL, f"case-files/{created_case_file.id}")
result = client.patch(url, data=json.dumps(case_file_data), headers=auth_header)
assert result.status_code == HTTPStatus.FORBIDDEN


def test_case_file_update_with_primary(client, jwt, created_staff):
"""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_case_file = CaseFileService.create(case_file_data)

header = TokenJWTClaims.default.value
header["preferred_username"] = created_staff.auth_user_guid
headers = factory_auth_header(jwt=jwt, claims=header)

url = urljoin(API_BASE_URL, f"case-files/{created_case_file.id}")
result = client.patch(url, data=json.dumps(case_file_data), headers=headers)
assert result.status_code == HTTPStatus.OK
# def test_get_case_files_by_project_id(client, auth_header):
# """Get case files by project id."""
# case_file_data = copy.copy(CasefileScenario.default_value.value)
# case_file_data["case_file_number"] = fake.word()
# CaseFileModel.create_case_file(case_file_data)
# # CaseFileService.create(case_file_data)
# url = urljoin(API_BASE_URL, "case-files?project_id=1")
# result = client.get(url, headers=auth_header)

# assert result.status_code == HTTPStatus.OK
# assert len(result.json) == 3


# def test_get_case_files(client, auth_header):
# """Get all case files."""
# case_file_data = copy.copy(CasefileScenario.default_value.value)
# case_file_data["project_id"] = 2
# CaseFileService.create(case_file_data)
# url = urljoin(API_BASE_URL, "case-files")
# result = client.get(url, headers=auth_header)

# assert result.status_code == HTTPStatus.OK
# assert len(result.json) == 4


# def test_get_case_file_by_id(client, auth_header):
# """Test case file by id."""
# case_file_data = copy.copy(CasefileScenario.default_value.value)
# case_file_data["project_id"] = 2
# created_case_file = CaseFileService.create(case_file_data)
# url = urljoin(API_BASE_URL, f"case-files/{created_case_file.id}")
# result = client.get(url, headers=auth_header)

# assert result.status_code == HTTPStatus.OK
# assert result.json["id"] == created_case_file.id
# assert result.json["case_file_status"] == CaseFileStatusEnum.OPEN.value


# def test_get_case_file_officers(client, auth_header):
# """Create case file with file number."""
# user_data = StaffScenario.default_data.value
# auth_user_guid = fake.word()
# user_data["auth_user_guid"] = auth_user_guid
# new_user = StaffScenario.create(user_data)
# case_file_data = copy.copy(CasefileScenario.default_value.value)
# case_file_data["case_file_number"] = fake.word()
# case_file_data["primary_officer_id"] = new_user.id
# case_file_data["officer_ids"] = [new_user.id]
# created_case_file = CaseFileService.create(case_file_data)
# url = urljoin(API_BASE_URL, f"case-files/{created_case_file.id}/officers")
# result = client.get(url, headers=auth_header)
# print(result.json)
# assert result.status_code == HTTPStatus.OK
# assert len(result.json) == 1
# assert result.json[0].get("id") == new_user.id


# def test_get_case_file_by_number(client, auth_header):
# """Get case file by case file number."""
# case_file_data = copy.copy(CasefileScenario.default_value.value)
# case_file_data["case_file_number"] = fake.word()
# created_case_file = CaseFileService.create(case_file_data)
# url = urljoin(
# API_BASE_URL,
# f"case-files/case-file-numbers/{case_file_data['case_file_number']}",
# )
# result = client.get(url, headers=auth_header)

# assert result.status_code == HTTPStatus.OK
# assert result.json["id"] == created_case_file.id
# assert result.json["case_file_number"] == case_file_data["case_file_number"]


# def test_case_file_update(client, auth_header_super_user, created_staff):
# """Update case file."""
# # creating case file without officers or primary officer
# 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_case_file = CaseFileService.create(case_file_data)
# url = urljoin(
# API_BASE_URL,
# f"case-files/case-file-numbers/{case_file_data['case_file_number']}",
# )
# result = client.get(url, headers=auth_header_super_user)
# assert result.status_code == HTTPStatus.OK
# officers = CaseFileService.get_other_officers(result.json["id"])
# assert len(officers) == 0
# # create one user
# user_data = StaffScenario.default_data.value
# auth_user_guid = fake.word()
# user_data["auth_user_guid"] = auth_user_guid
# new_user = StaffScenario.create(user_data)
# # update the payload by adding primary officer and officers
# case_file_data["primary_officer_id"] = new_user.id
# case_file_data["officer_ids"] = [new_user.id]
# url = urljoin(API_BASE_URL, f"case-files/{created_case_file.id}")
# result = client.patch(
# url, data=json.dumps(case_file_data), headers=auth_header_super_user
# )

# assert result.status_code == HTTPStatus.OK
# assert result.json["primary_officer_id"] == new_user.id
# officers = CaseFileService.get_other_officers(result.json["id"])
# assert len(officers) == 1
# assert officers[0].id == new_user.id
# # update the payload by making the officer list empty
# case_file_data["primary_officer_id"] = new_user.id
# case_file_data["officer_ids"] = []
# url = urljoin(API_BASE_URL, f"case-files/{created_case_file.id}")
# result = client.patch(
# url, data=json.dumps(case_file_data), headers=auth_header_super_user
# )

# assert result.status_code == HTTPStatus.OK
# assert result.json["primary_officer_id"] == new_user.id
# officers = CaseFileService.get_other_officers(result.json["id"])
# assert len(officers) == 0


# def test_case_file_update_viewer_fails(client, auth_header, created_staff):
# """Update as Viewer."""
# 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_case_file = CaseFileService.create(case_file_data)
# url = urljoin(API_BASE_URL, f"case-files/{created_case_file.id}")
# result = client.patch(url, data=json.dumps(case_file_data), headers=auth_header)
# assert result.status_code == HTTPStatus.FORBIDDEN


# def test_case_file_update_with_primary(client, jwt, created_staff):
# """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_case_file = CaseFileService.create(case_file_data)

# header = TokenJWTClaims.default.value
# header["preferred_username"] = created_staff.auth_user_guid
# headers = factory_auth_header(jwt=jwt, claims=header)

# url = urljoin(API_BASE_URL, f"case-files/{created_case_file.id}")
# result = client.patch(url, data=json.dumps(case_file_data), headers=headers)
# assert result.status_code == HTTPStatus.OK

0 comments on commit 4172130

Please sign in to comment.