diff --git a/tests/cloud_functions/test_deliver_mi_hub_processor.py b/tests/cloud_functions/test_deliver_mi_hub_processor.py index 59ce481..d9f804d 100644 --- a/tests/cloud_functions/test_deliver_mi_hub_processor.py +++ b/tests/cloud_functions/test_deliver_mi_hub_processor.py @@ -8,7 +8,6 @@ from cloud_functions.deliver_mi_hub_reports import ( deliver_mi_hub_reports_cloud_function_processor, ) -from models.mi_hub_respondent_data_model import MiHubRespondentData QUESTIONNAIRE_NAME = "LMS2222Z" QUESTIONNAIRE_ID = "s0me-r7nd0m-gu1d" @@ -44,7 +43,7 @@ def test_deliver_mi_hub_reports_cloud_function_processor_raises_exception_when_t assert ( str(err.value) - == "deliver_mi_hub_reports_cloud_function_processor was not triggered due to an invalid request" + == '400 Bad Request: The browser (or proxy) sent a request that this server ''could not understand.' ) @@ -156,215 +155,3 @@ def test_deliver_mi_hub_reports_cloud_function_processor_calls_upload_mi_hub_rep mock_mi_hub_respondent_data, fake_google_storage, ) - - -@pytest.fixture -def mock_mi_hub_respondent_data_complete(): - return [ - MiHubRespondentData( - serial_number="900002", - outcome_code="310", - date_completed="2-11-2022_9:20", - interviewer="testuser", - mode="testmode", - postcode="PO57 2OD", - gender="Male", - date_of_birth="2-11-2022_3:08", - age="2", - ), - ] - - -@mock.patch("cloud_functions.deliver_mi_hub_reports.init_google_storage") -@mock.patch("cloud_functions.deliver_mi_hub_reports.get_mi_hub_call_history") -@mock.patch("cloud_functions.deliver_mi_hub_reports.get_mi_hub_respondent_data") -@mock.patch( - "cloud_functions.deliver_mi_hub_reports.DeliverMiHubReportsService.upload_mi_hub_reports_to_gcp" -) -def test_deliver_mi_hub_reports_cloud_function_processor_calls_upload_mi_hub_reports_to_gcp_with_complete_data( - _mock_upload_mi_hub_reports_to_gcp, - _mock_get_mi_hub_respondent_data, - _mock_get_mi_hub_call_history, - _mock_init_google_storage, - mock_request_values, - config, - fake_google_storage, - mock_mi_hub_call_history, - mock_mi_hub_respondent_data_complete, -): - # arrange - mock_request = flask.Request.from_values(json=mock_request_values) - fake_google_storage.bucket = "not-none" - _mock_init_google_storage.return_value = fake_google_storage - _mock_get_mi_hub_call_history.return_value = mock_mi_hub_call_history - _mock_get_mi_hub_respondent_data.return_value = mock_mi_hub_respondent_data_complete - - # act - deliver_mi_hub_reports_cloud_function_processor(mock_request, config) - - # assert - _mock_upload_mi_hub_reports_to_gcp.assert_called_with( - QUESTIONNAIRE_NAME, - mock_mi_hub_call_history, - mock_mi_hub_respondent_data_complete, - fake_google_storage, - ) - - -@pytest.fixture -def mock_mi_hub_respondent_data_empty(): - return [ - MiHubRespondentData( - serial_number="", - outcome_code="", - date_completed="", - interviewer="", - mode="", - postcode="", - gender="", - date_of_birth="", - age="", - ), - ] - - -@mock.patch("cloud_functions.deliver_mi_hub_reports.init_google_storage") -@mock.patch("cloud_functions.deliver_mi_hub_reports.get_mi_hub_call_history") -@mock.patch("cloud_functions.deliver_mi_hub_reports.get_mi_hub_respondent_data") -@mock.patch( - "cloud_functions.deliver_mi_hub_reports.DeliverMiHubReportsService.upload_mi_hub_reports_to_gcp" -) -def test_deliver_mi_hub_reports_cloud_function_processor_calls_upload_mi_hub_reports_to_gcp_with_empty_data( - _mock_upload_mi_hub_reports_to_gcp, - _mock_get_mi_hub_respondent_data, - _mock_get_mi_hub_call_history, - _mock_init_google_storage, - mock_request_values, - config, - fake_google_storage, - mock_mi_hub_call_history, - mock_mi_hub_respondent_data_empty, -): - # arrange - mock_request = flask.Request.from_values(json=mock_request_values) - fake_google_storage.bucket = "not-none" - _mock_init_google_storage.return_value = fake_google_storage - _mock_get_mi_hub_call_history.return_value = mock_mi_hub_call_history - _mock_get_mi_hub_respondent_data.return_value = mock_mi_hub_respondent_data_empty - - # act - deliver_mi_hub_reports_cloud_function_processor(mock_request, config) - - # assert - _mock_upload_mi_hub_reports_to_gcp.assert_called_with( - QUESTIONNAIRE_NAME, - mock_mi_hub_call_history, - mock_mi_hub_respondent_data_empty, - fake_google_storage, - ) - - -@pytest.fixture -def mock_mi_hub_respondent_data_partially_complete(): - return [ - MiHubRespondentData( - serial_number="01210", - outcome_code="310", - date_completed="2-11-2022_9:20", - interviewer="testuser", - mode="testmode", - postcode="", - gender="Female", - date_of_birth="", - age="22", - ), - ] - - -@mock.patch("cloud_functions.deliver_mi_hub_reports.init_google_storage") -@mock.patch("cloud_functions.deliver_mi_hub_reports.get_mi_hub_call_history") -@mock.patch("cloud_functions.deliver_mi_hub_reports.get_mi_hub_respondent_data") -@mock.patch( - "cloud_functions.deliver_mi_hub_reports.DeliverMiHubReportsService.upload_mi_hub_reports_to_gcp" -) -def test_deliver_mi_hub_reports_cloud_function_processor_calls_upload_mi_hub_reports_to_gcp_partially_complete( - _mock_upload_mi_hub_reports_to_gcp, - _mock_get_mi_hub_respondent_data, - _mock_get_mi_hub_call_history, - _mock_init_google_storage, - mock_request_values, - config, - fake_google_storage, - mock_mi_hub_call_history, - mock_mi_hub_respondent_data_partially_complete, -): - # arrange - mock_request = flask.Request.from_values(json=mock_request_values) - fake_google_storage.bucket = "not-none" - _mock_init_google_storage.return_value = fake_google_storage - _mock_get_mi_hub_call_history.return_value = mock_mi_hub_call_history - _mock_get_mi_hub_respondent_data.return_value = mock_mi_hub_respondent_data_partially_complete - - # act - deliver_mi_hub_reports_cloud_function_processor(mock_request, config) - - # assert - _mock_upload_mi_hub_reports_to_gcp.assert_called_with( - QUESTIONNAIRE_NAME, - mock_mi_hub_call_history, - mock_mi_hub_respondent_data_partially_complete, - fake_google_storage, - ) - - -@pytest.fixture -def mock_mi_hub_respondent_data_missing(): - return [ - MiHubRespondentData( - serial_number="01210", - outcome_code="310", - date_completed="2-11-2022_9:20", - interviewer="testuser", - mode="testmode", - postcode=None, - gender=None, - date_of_birth="", - age=None, - ), - ] - - -@mock.patch("cloud_functions.deliver_mi_hub_reports.init_google_storage") -@mock.patch("cloud_functions.deliver_mi_hub_reports.get_mi_hub_call_history") -@mock.patch("cloud_functions.deliver_mi_hub_reports.get_mi_hub_respondent_data") -@mock.patch( - "cloud_functions.deliver_mi_hub_reports.DeliverMiHubReportsService.upload_mi_hub_reports_to_gcp" -) -def test_deliver_mi_hub_reports_cloud_function_processor_calls_upload_mi_hub_reports_to_gcp_with_missing_data( - _mock_upload_mi_hub_reports_to_gcp, - _mock_get_mi_hub_respondent_data, - _mock_get_mi_hub_call_history, - _mock_init_google_storage, - mock_request_values, - config, - fake_google_storage, - mock_mi_hub_call_history, - mock_mi_hub_respondent_data_missing, -): - # arrange - mock_request = flask.Request.from_values(json=mock_request_values) - fake_google_storage.bucket = "not-none" - _mock_init_google_storage.return_value = fake_google_storage - _mock_get_mi_hub_call_history.return_value = mock_mi_hub_call_history - _mock_get_mi_hub_respondent_data.return_value = mock_mi_hub_respondent_data_missing - - # act - deliver_mi_hub_reports_cloud_function_processor(mock_request, config) - - # assert - _mock_upload_mi_hub_reports_to_gcp.assert_called_with( - QUESTIONNAIRE_NAME, - mock_mi_hub_call_history, - mock_mi_hub_respondent_data_missing, - fake_google_storage, - ) diff --git a/tests/services/test_mi_hub_reports_service.py b/tests/services/test_mi_hub_reports_service.py index dcd8bb9..99b062a 100644 --- a/tests/services/test_mi_hub_reports_service.py +++ b/tests/services/test_mi_hub_reports_service.py @@ -27,198 +27,3 @@ def test_deliver_mi_hub_reports_returns_expected_string( # assert assert result == f"Done - {QUESTIONNAIRE_NAME}" - - - -@pytest.fixture -def mock_mi_hub_respondent_data_no_missing_data(): - return [ - MiHubRespondentData( - serial_number="900001", - outcome_code="310", - date_completed="2-11-2022_9:20", - interviewer="testuser", - mode="default", - postcode="PO57 2OD", - gender="Male", - date_of_birth="21-10-2022", - age="18", - ), - ] - - -def test_deliver_mi_hub_reports_with_no_missing_data_returns_expected_string( - mock_mi_hub_call_history, mock_mi_hub_respondent_data_no_missing_data -): - # arrange - mock_google_storage = create_autospec(GoogleStorage) - - # act - result = DeliverMiHubReportsService.upload_mi_hub_reports_to_gcp( - questionnaire_name=QUESTIONNAIRE_NAME, - mi_hub_call_history=mock_mi_hub_call_history, - mi_hub_respondent_data=mock_mi_hub_respondent_data_no_missing_data, - google_storage=mock_google_storage, - ) - - # assert - assert result == f"Done - {QUESTIONNAIRE_NAME}" - - -@pytest.fixture -def mock_mi_hub_respondent_data_missing_serial_number_data(): - return [ - MiHubRespondentData( - serial_number="", - outcome_code="310", - date_completed="2-11-2022_9:20", - interviewer="testuser", - mode="default", - postcode="PO57 2OD", - gender="Male", - date_of_birth="21-10-2022", - age="18", - ), - ] - - -def test_deliver_mi_hub_reports_with_missing_serial_number_returns_expected_string( - mock_mi_hub_call_history, mock_mi_hub_respondent_data_missing_serial_number_data -): - # arrange - mock_google_storage = create_autospec(GoogleStorage) - - # act - result = DeliverMiHubReportsService.upload_mi_hub_reports_to_gcp( - questionnaire_name=QUESTIONNAIRE_NAME, - mi_hub_call_history=mock_mi_hub_call_history, - mi_hub_respondent_data=mock_mi_hub_respondent_data_missing_serial_number_data, - google_storage=mock_google_storage, - ) - - # assert - assert result == f"Done - {QUESTIONNAIRE_NAME}" - - -@pytest.fixture -def mock_mi_hub_respondent_data_missing_all_data(): - return [ - MiHubRespondentData( - serial_number="", - outcome_code="", - date_completed="", - interviewer="", - mode="", - postcode="", - gender="", - date_of_birth="", - age="", - ), - ] - - -def test_deliver_mi_hub_reports_with_missing_all_data_returns_expected_string( - mock_mi_hub_call_history, mock_mi_hub_respondent_data_missing_all_data -): - # arrange - mock_google_storage = create_autospec(GoogleStorage) - - # act - result = DeliverMiHubReportsService.upload_mi_hub_reports_to_gcp( - questionnaire_name=QUESTIONNAIRE_NAME, - mi_hub_call_history=mock_mi_hub_call_history, - mi_hub_respondent_data=mock_mi_hub_respondent_data_missing_all_data, - google_storage=mock_google_storage, - ) - - # assert - assert result == f"Done - {QUESTIONNAIRE_NAME}" - - -def test_deliver_mi_hub_reports_with_no_data_returns_expected_string( - mock_mi_hub_call_history, mock_mi_hub_respondent_data_missing_all_data -): - # arrange - mock_google_storage = create_autospec(GoogleStorage) - - # act - result = DeliverMiHubReportsService.upload_mi_hub_reports_to_gcp( - questionnaire_name=QUESTIONNAIRE_NAME, - mi_hub_call_history=mock_mi_hub_call_history, - mi_hub_respondent_data=None, - google_storage=mock_google_storage, - ) - - # assert - assert result == f"Done - {QUESTIONNAIRE_NAME}" - - -@pytest.fixture -def mock_mi_hub_respondent_data_empty_data(): - return [ - MiHubRespondentData( - serial_number=None, - outcome_code="310", - date_completed="2-11-2022_9:20", - interviewer="testuser", - mode="default", - postcode="PO57 2OD", - gender=None, - date_of_birth=None, - age=None, - ), - ] - - -def test_deliver_mi_hub_reports_with_some_data_empty_returns_expected_string( - mock_mi_hub_call_history, mock_mi_hub_respondent_data_empty_data -): - # arrange - mock_google_storage = create_autospec(GoogleStorage) - - # act - result = DeliverMiHubReportsService.upload_mi_hub_reports_to_gcp( - questionnaire_name=QUESTIONNAIRE_NAME, - mi_hub_call_history=mock_mi_hub_call_history, - mi_hub_respondent_data=mock_mi_hub_respondent_data_empty_data, - google_storage=mock_google_storage, - ) - - # assert - assert result == f"Done - {QUESTIONNAIRE_NAME}" - - - -@pytest.fixture -def mock_mi_hub_respondent_data_missing(): - return [ - MiHubRespondentData( - serial_number=None, - outcome_code=None, - date_completed=None, - interviewer=None, - mode=None, - postcode=None, - gender=None, - date_of_birth=None, - age=None, - ), - ] - - -def test_deliver_mi_hub_reports_with_no_respondent_data( - mock_mi_hub_call_history, mock_mi_hub_respondent_data_missing -): - # arrange - mock_google_storage = create_autospec(GoogleStorage) - - # act - result = DeliverMiHubReportsService.upload_mi_hub_reports_to_gcp( - questionnaire_name=QUESTIONNAIRE_NAME, - mi_hub_call_history=mock_mi_hub_call_history, - mi_hub_respondent_data=mock_mi_hub_respondent_data_missing, - google_storage=mock_google_storage, - ) - - # assert - assert result == f"Done - {QUESTIONNAIRE_NAME}"