Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
joefong-nhs committed Jun 10, 2024
1 parent 7026fb4 commit 1f770ea
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion lambdas/tests/unit/services/test_statistical_report_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ def test_summarise_record_store_data_larger_mock_data(mock_service):
assert_frame_equal(actual, expected, check_row_order=False, check_dtype=False)


def test_summarise_record_store_data_can_handle_empty_input(mock_service):
empty_input = []
actual = mock_service.summarise_record_store_data(empty_input)

assert isinstance(actual, pl.DataFrame)
assert actual.is_empty()


def test_summarise_organisation_data(mock_service):
actual = mock_service.summarise_organisation_data(
[MOCK_ORGANISATION_DATA_1, MOCK_ORGANISATION_DATA_2, MOCK_ORGANISATION_DATA_3]
Expand Down Expand Up @@ -225,6 +233,14 @@ def assert_number_of_patient_correct(mock_data, row_in_actual_data):
assert actual_number_of_patient == expected_number_of_patients


def test_summarise_organisation_data_can_handle_empty_input(mock_service):
empty_input = []
actual = mock_service.summarise_organisation_data(empty_input)

assert isinstance(actual, pl.DataFrame)
assert actual.is_empty()


def test_summarise_application_data(mock_service):
mock_data = [
MOCK_APPLICATION_DATA_1,
Expand Down Expand Up @@ -268,6 +284,14 @@ def count_unique_user_ids(mock_data: list[ApplicationData]) -> int:
return len(unique_active_users_for_whole_week)


def test_summarise_application_data_can_handle_empty_input(mock_service):
empty_input = []
actual = mock_service.summarise_application_data(empty_input)

assert isinstance(actual, pl.DataFrame)
assert actual.is_empty()


def test_join_dataframes_by_ods_code(mock_service):
mock_data_1 = pl.DataFrame([{"ods_code": "Y12345", "field1": "apple"}])
mock_data_2 = pl.DataFrame(
Expand All @@ -276,14 +300,34 @@ def test_join_dataframes_by_ods_code(mock_service):
{"ods_code": "Z56789", "field2": "cherry"},
]
)
mock_data_3 = pl.DataFrame([])

expected = pl.DataFrame(
[
{"ods_code": "Y12345", "field1": "apple", "field2": "banana"},
{"ods_code": "Z56789", "field2": "cherry"},
]
)
actual = mock_service.join_dataframes_by_ods_code([mock_data_1, mock_data_2])

assert_frame_equal(actual, expected, check_dtype=False, check_row_order=False)


def test_join_dataframes_by_ods_code_can_handle_empty_dataframe(mock_service):
mock_data_1 = pl.DataFrame([{"ods_code": "Y12345", "field1": "cat"}])
mock_data_2 = pl.DataFrame()
mock_data_3 = pl.DataFrame(
[
{"ods_code": "Y12345", "field2": "dog"},
{"ods_code": "Z56789", "field3": "lizard"},
]
)

expected = pl.DataFrame(
[
{"ods_code": "Y12345", "field1": "cat", "field2": "dog"},
{"ods_code": "Z56789", "field3": "lizard"},
]
)
actual = mock_service.join_dataframes_by_ods_code(
[mock_data_1, mock_data_2, mock_data_3]
)
Expand Down

0 comments on commit 1f770ea

Please sign in to comment.