def setup(self): self.create_help_request = FakeCreateHelpRequest() self.test_case_note = "CEV: Dec 2020 Tier 4 NSSS Submitted on: 2021-02-05T03:10:31Z. Do you want supermarket deliveries? " \ "No. Do you have someone to go shopping for you? No. Do you need someone to contact you about local " \ "support? yes." self.here_to_help_api = FakeHereToHelpGateway(test_case_note=self.test_case_note) data_frame = pd.DataFrame({ 'ID': ['123123'], 'nhs_number': ['1234567890'], 'first_name': ['Fred'], 'last_name': ['Flintstone'], 'date_of_birth': ['22/02/1963'], 'address_line1': ['45 Cave Stone Road'], 'address_line2': [''], 'address_town_city': ['Bedrock'], 'address_postcode': ['BR2 9FF'], 'address_uprn': [''], 'contact_number_calls': ['07344211233'], 'contact_number_texts': ['02344211233'], 'contact_email': ['*****@*****.**'], 'do_you_want_supermarket_deliveries': ['No'], 'submission_datetime': ['2021-02-05T03:10:31Z'], 'do_you_need_someone_to_contact_you_about_local_support': ['yes'], 'do_you_have_someone_to_go_shopping_for_you': ['No'] }) use_case = AddCEVRequests(self.create_help_request, self.here_to_help_api) self.processed_data_frame = use_case.execute(data_frame=data_frame) self.created_test_help_request_id = self.create_help_request.get_returned_id()
def test_la_support_letter_received_creates_cev_record(): create_help_request = FakeCreateHelpRequest() test_resident_id = 121233 here_to_help_api = FakeHereToHelpGateway(test_resident_id=test_resident_id, cev_exists=False) data_frame = get_data_frame() use_case = AddSelfIsolationRequests(create_help_request, here_to_help_api) processed_data_frame = use_case.execute(data_frame=data_frame) assert (processed_data_frame.at[0, 'cev_case_added_id'] == 1) assert (processed_data_frame.at[1, 'cev_case_added_id'] == '') assert (processed_data_frame.at[2, 'cev_case_added_id'] == 1) assert len(here_to_help_api.get_multiple_help_requests_called_with) == 2 assert len(here_to_help_api.create_resident_help_request_called_with) == 2 assert here_to_help_api.create_case_note_called_with[1] == { 'resident_id': 121233, 'help_request_id': 1, 'case_note': { "author": "Data Ingestion: Self Isolation", "note": "--- self-reported CEV resident identified through self-isolation support " "process ---" } }
def test_day_outcome_columns_become_case_notes(): create_help_request = FakeCreateHelpRequest() test_resident_id = 121231 here_to_help_api = FakeHereToHelpGateway(test_resident_id=test_resident_id) data_frame = get_data_frame(case_note_1=['1', '', ''], case_note_2=['case_note2', '', ''], case_note_3=['case_note3', '', ''], case_note_4=['case_note4', '', '']) use_case = AddGenericIngestionRequests(create_help_request, here_to_help_api) use_case.execute(data_frame=data_frame) assert len(here_to_help_api.create_case_note_called_with) == 4 assert here_to_help_api.create_case_note_called_with[0] == { 'resident_id': 121231, 'help_request_id': 1, 'case_note': { "author": "Data Ingestion: Generic Ingestion", "note": "Note from Data Ingestion: 1" } }
def test_only_rows_newer_than_seven_days_get_processed(): create_help_request = FakeCreateHelpRequest() test_resident_id = 121231 here_to_help_api = FakeHereToHelpGateway(test_resident_id=test_resident_id) la_support_letter_received = ['', '', ''] la_support_required = ['1', '1', '1'] invalid_date = datetime.date.today() - datetime.timedelta(days=80) invalid_edge_date = datetime.date.today() - datetime.timedelta(days=7) valid_edge_date = datetime.date.today() - datetime.timedelta(days=6) data_frame = get_data_frame( la_support_letter_received=la_support_letter_received, la_support_required=la_support_required, date_tested=[ invalid_date.strftime("%d/%m/%Y %H:%M:%S"), invalid_edge_date.strftime("%d/%m/%Y"), valid_edge_date.strftime("%d-%m-%Y") ]) use_case = AddSelfIsolationRequests(create_help_request, here_to_help_api) processed_data_frame = use_case.execute(data_frame=data_frame) assert (processed_data_frame.at[0, 'help_request_id'] is not None) assert len(create_help_request.received_help_requests) == 1
def test_day_outcome_columns_become_case_notes(): create_help_request = FakeCreateHelpRequest() test_resident_id = 121231 here_to_help_api = FakeHereToHelpGateway( test_resident_id=test_resident_id, test_case_note="Day 13 Outcome: day13") data_frame = get_data_frame(la_support_letter_received=['0', '', '0'], la_support_required=['1', '', ''], day_7_outcome=['day7', '', ''], day_13_outcome=['day13', '', '']) use_case = AddSelfIsolationRequests(create_help_request, here_to_help_api) use_case.execute(data_frame) assert len(here_to_help_api.create_case_note_called_with) == 1 assert here_to_help_api.create_case_note_called_with[0] == { 'resident_id': 121231, 'help_request_id': 1, 'case_note': { "author": "Data Ingestion: Self Isolation", "note": "Day 7 Outcome: day7" } }
def test_create_help_request_with_error(): gateway = FakeHereToHelpGateway(error=True) help_requests = [{ "FirstName": "James", "LastName": "Smith", "NhsNumber": "123" }, { "FirstName": "Jane", "LastName": "Doe", "NhsNumber": "321" }, { "LastName": "Jones", "FirstName": "Smith", "EmailAddress": "*****@*****.**" }] use_case = CreateHelpRequest(gateway=gateway) initial_help_requests = [] for help_request in help_requests: initial_help_requests.append(help_request.copy()) for help_request in initial_help_requests: help_request["Error"] = "message" result = use_case.execute(help_requests) assert result == { "created_help_request_ids": [], "unsuccessful_help_requests": [], "exceptions": initial_help_requests }
def test_callback_not_required_rows_ignored(): create_help_request = FakeCreateHelpRequest() test_resident_id = 121231 here_to_help_api = FakeHereToHelpGateway(test_resident_id=test_resident_id) data_frame = get_data_frame(la_support_letter_received=['0', '', '0'], la_support_required=['0', '', '']) use_case = AddSelfIsolationRequests(create_help_request, here_to_help_api) use_case.execute(data_frame=data_frame) assert len(create_help_request.received_help_requests) == 0
def test_only_known_help_request_subtype_rows_processed(): create_help_request = FakeCreateHelpRequest() test_resident_id = 121231 here_to_help_api = FakeHereToHelpGateway(test_resident_id=test_resident_id) data_frame = get_data_frame( help_request_type=['EUSS', 'Link Work', 'Link Work'], help_request_subtype=['Repairs', '', 'Repairs']) use_case = AddGenericIngestionRequests(create_help_request, here_to_help_api) use_case.execute(data_frame=data_frame) assert len(create_help_request.received_help_requests) == 3
def test_only_known_help_request_type_rows_processed(): create_help_request = FakeCreateHelpRequest() test_resident_id = 121231 here_to_help_api = FakeHereToHelpGateway(test_resident_id=test_resident_id) data_frame = get_data_frame() use_case = AddGenericIngestionRequests(create_help_request, here_to_help_api) processed_data_frame = use_case.execute(data_frame=data_frame) assert (processed_data_frame.at[0, 'help_request_id'] is not None) assert len(create_help_request.received_help_requests) == 2
def test_la_support_letter_received_does_not_create_cev_record_if_one_exists(): create_help_request = FakeCreateHelpRequest() test_resident_id = 121233 here_to_help_api = FakeHereToHelpGateway(test_resident_id=test_resident_id) data_frame = get_data_frame() use_case = AddSelfIsolationRequests(create_help_request, here_to_help_api) processed_data_frame = use_case.execute(data_frame=data_frame) assert (processed_data_frame.at[0, 'cev_case_added_id'] == '') assert (processed_data_frame.at[1, 'cev_case_added_id'] == '') assert (processed_data_frame.at[2, 'cev_case_added_id'] == '') assert len(here_to_help_api.get_multiple_help_requests_called_with) == 2 assert len(here_to_help_api.create_resident_help_request_called_with) == 0
def test_only_callback_required_rows_processed(): create_help_request = FakeCreateHelpRequest() test_resident_id = 121231 here_to_help_api = FakeHereToHelpGateway(test_resident_id=test_resident_id) data_frame = get_data_frame() use_case = AddSelfIsolationRequests(create_help_request, here_to_help_api) processed_data_frame = use_case.execute(data_frame=data_frame) assert (processed_data_frame.at[0, 'help_request_id'] is not None) assert create_help_request.received_help_requests[1]['Metadata'] == { "LA_support_required": '1', "LA_support_letter_received": '' } assert len(create_help_request.received_help_requests) == 3
def test_ignore_rows_with_no_date_tested_processed(): create_help_request = FakeCreateHelpRequest() test_resident_id = 121231 here_to_help_api = FakeHereToHelpGateway(test_resident_id=test_resident_id) la_support_letter_received = ['', '', ''] la_support_required = ['1', '1', '1'] valid_date = datetime.date.today() data_frame = get_data_frame( la_support_letter_received=la_support_letter_received, la_support_required=la_support_required, date_tested=[valid_date.strftime("%d/%m/%Y"), '', '']) use_case = AddSelfIsolationRequests(create_help_request, here_to_help_api) processed_data_frame = use_case.execute(data_frame=data_frame) assert (processed_data_frame.at[0, 'help_request_id'] is not None) assert len(create_help_request.received_help_requests) == 1
def test_create_help_request(): gateway = FakeHereToHelpGateway() requests = [{ "FirstName": "James", "LastName": "Smith", "NhsNumber": "123" }, { "FirstName": "Jane", "LastName": "Doe", "NhsNumber": "321" }, { "LastName": "Jones", "EmailAddress": "*****@*****.**" }] use_case = CreateHelpRequest(gateway=gateway) result = use_case.execute(help_requests=requests) assert result["created_help_request_ids"] == [1, 2] assert result["unsuccessful_help_requests"][0][ "EmailAddress"] == "*****@*****.**" assert gateway.count == 2
def test_rows_only_get_processed_when_status_report_is_completed(): create_help_request = FakeCreateHelpRequest() test_resident_id = 125551 here_to_help_api = FakeHereToHelpGateway(test_resident_id=test_resident_id) data_frame = get_data_frame( la_support_letter_received=['1', '1', '1'], la_support_required=['1', '1', '1'], status_report=['completed', 'failed', 'completed']) use_case = AddSelfIsolationRequests(create_help_request, here_to_help_api) processed_data_frame = use_case.execute(data_frame=data_frame) # check whether the correct help request got imported assert any( help_request.get("NhsNumber") == "123412345" for help_request in create_help_request.received_help_requests) assert any( help_request.get("NhsNumber") == "24359e43" for help_request in create_help_request.received_help_requests) # check whether the correct quantity of help request has gotten imported assert len(create_help_request.received_help_requests) == 2
def test_a_new_help_request_and_no_new_case_note_is_added(): create_help_request = FakeCreateHelpRequest() test_resident_id = 312 test_case_note = 'SPL Category: Deceased. Date of death: 21-02-2021' here_to_help_api = FakeHereToHelpGateway(test_resident_id=test_resident_id, test_case_note=test_case_note) data_frame = pd.DataFrame({ 'Traced_NHSNUMBER': ['1234567890'], 'PatientFirstName': ['Shaco'], 'PatientOtherName': [''], 'PatientSurname': ['N00b'], 'DateOfBirth': ['19930329'], 'PatientAddress_Line1': ['404 Summoner rf'], 'PatientAddress_Line2': [''], 'PatientAddress_Line3': ['Black Hole'], 'PatientAddress_Line4': [''], 'PatientAddress_Line5': [''], 'PatientAddress_PostCode': ['CH5 5AP'], 'PatientEmailAddress': ['*****@*****.**'], 'mobile': ['07123456789'], 'landline': ['021234567890'], 'DateOfDeath': ['21-02-2021'], 'Flag_PDSInformallyDeceased': ['0'], 'oslaua': [''], 'oscty': [''], 'Data_Source': ['Initial'], 'category': ['Deceased'], 'InceptionDate': ['2020-04-22'], 'SPL_Version': [''], 'uprn': ['02938372719'] }) use_case = AddSPLRequests(create_help_request, here_to_help_api) processed_data_frame = use_case.execute(data_frame=data_frame) assert len(create_help_request.received_help_requests) == 1 assert create_help_request.received_help_requests[0] == { 'Metadata': { 'spl_id': '1234567890' }, 'Uprn': '02938372719', 'Postcode': 'CH5 5AP', 'AddressFirstLine': '404 Summoner rf', 'AddressSecondLine': '', 'AddressThirdLine': 'Black Hole', 'HelpWithSomethingElse': True, 'FirstName': 'Shaco', 'LastName': 'N00b', 'DobDay': '29', 'DobMonth': '3', 'DobYear': '1993', 'ContactTelephoneNumber': '021234567890', 'ContactMobileNumber': '07123456789', 'EmailAddress': '*****@*****.**', 'CallbackRequired': False, 'HelpNeeded': 'Shielding', 'NhsNumber': '1234567890' } test_help_request_id = create_help_request.get_returned_id() assert len(here_to_help_api.get_help_request_called_with) == 1 assert here_to_help_api.get_help_request_called_with[ 0] == test_help_request_id assert len(here_to_help_api.create_case_note_called_with) == 0 assert processed_data_frame.iloc[0].help_request_id == test_help_request_id assert processed_data_frame.iloc[0].resident_id == test_resident_id
def test_a_new_help_request_and_case_note_is_added(): create_help_request = FakeCreateHelpRequest() test_resident_id = 121231 here_to_help_api = FakeHereToHelpGateway(test_resident_id=test_resident_id) data_frame = pd.DataFrame({ 'Traced_NHSNUMBER': ['2649260211'], 'PatientFirstName': ['Homer'], 'PatientOtherName': ['Jay'], 'PatientSurname': ['Simpson'], 'DateOfBirth': ['19560512'], 'PatientAddress_Line1': ['742 Evergreen Terrace'], 'PatientAddress_Line2': [''], 'PatientAddress_Line3': ['Springfield'], 'PatientAddress_Line4': [''], 'PatientAddress_Line5': [''], 'PatientAddress_PostCode': ['TS1 2SP'], 'PatientEmailAddress': ['*****@*****.**'], 'mobile': ['0723083534'], 'landline': ['0278460422'], 'DateOfDeath': [''], 'Flag_PDSInformallyDeceased': ['0'], 'oslaua': ['E09000012'], 'oscty': ['E99999999'], 'Data_Source': ['COVID-19 PRA'], 'category': ['Added by COVID-19 Population Risk Assessment'], 'InceptionDate': ['44242'], 'SPL_Version': ['44'], 'uprn': ['10008326160'] }) use_case = AddSPLRequests(create_help_request, here_to_help_api) processed_data_frame = use_case.execute(data_frame=data_frame) assert len(create_help_request.received_help_requests) == 1 assert create_help_request.received_help_requests[0] == { 'Uprn': '10008326160', 'Metadata': { 'spl_id': '2649260211' }, 'Postcode': 'TS1 2SP', 'AddressFirstLine': '742 Evergreen Terrace', 'AddressSecondLine': '', 'AddressThirdLine': 'Springfield', # 'CaseNotes': f'{{"author":"Data Ingestion: Shielding Patient List","noteDate":" {note_date}","note":"{case_note}"}}', 'HelpWithSomethingElse': True, 'FirstName': 'Homer', 'LastName': 'Simpson', 'DobDay': '12', 'DobMonth': '5', 'DobYear': '1956', 'ContactTelephoneNumber': '0278460422', 'ContactMobileNumber': '0723083534', 'EmailAddress': '*****@*****.**', 'CallbackRequired': False, 'HelpNeeded': 'Shielding', 'NhsNumber': '2649260211' } test_help_request_id = create_help_request.get_returned_id() assert len(here_to_help_api.get_help_request_called_with) == 1 assert here_to_help_api.get_help_request_called_with[ 0] == test_help_request_id assert len(here_to_help_api.create_case_note_called_with) == 1 assert here_to_help_api.create_case_note_called_with[0] == { 'case_note': { 'author': 'Data Ingestion: Shielding Patient List', 'note': 'SPL Category: Added by COVID-19 Population Risk Assessment.' }, 'help_request_id': test_help_request_id, 'resident_id': test_resident_id } assert processed_data_frame.iloc[0].help_request_id == test_help_request_id assert processed_data_frame.iloc[0].resident_id == test_resident_id