def test__extract_post_pmi_details__pmi_exception(client, faker, mock_pmi_details, mock_schedule_lookup_tasks): ERROR_MESSAGE = 'An Exception' u = login(client, faker) dth = DemographicsTestHelper(faker=faker, user=u, row_count=1, find_pre_pmi_details=False) dr = dth.get_demographics_request__post_pmi_lookup() mock_pmi_details.side_effect = PmiException(ERROR_MESSAGE) extract_post_pmi_details(dr.id) actual = DemographicsRequest.query.get(dr.id) assert actual.pmi_data_post_completed_datetime is None assert sum(1 for d in actual.data if d.pmi_post_processed_datetime is not None) == 1 assert actual.data[0].pmi_data is None assert len(actual.data[0].messages) == 1 m = actual.data[0].messages[0] assert m.type == 'error' assert m.source == 'pmi_details' assert m.scope == 'pmi_details' assert m.message == ERROR_MESSAGE mock_schedule_lookup_tasks.assert_called_once_with(dr.id) _remove_files(dr)
def test__extract_post_pmi_details__invalid_uhl_system_number( client, faker, mock_pmi_details, mock_schedule_lookup_tasks): u = login(client, faker) dth = DemographicsTestHelper(faker=faker, user=u, row_count=1, find_pre_pmi_details=False) dr = dth.get_demographics_request__post_pmi_lookup() dr.data[0].uhl_system_number = faker.invalid_uhl_system_number() db.session.add(dr.data[0]) db.session.commit() expected = PmiData(**faker.pmi_details(1)) mock_pmi_details.return_value = expected extract_post_pmi_details(dr.id) actual = DemographicsRequest.query.get(dr.id) assert actual.pmi_data_post_completed_datetime is None assert sum(1 for d in actual.data if d.pmi_post_processed_datetime is not None) == 1 assert expected == actual.data[0].pmi_data assert len(actual.data[0].messages) == 1 m = actual.data[0].messages[0] assert m.type == 'warning' assert m.source == 'pmi_details' assert m.scope == 'uhl_system_number' assert m.message == f'Invalid format {faker.invalid_uhl_system_number()}' mock_schedule_lookup_tasks.assert_called_once_with(dr.id) _remove_files(dr)
def test__extract_post_pmi_details__next_processed(client, faker, mock_pmi_details, mock_schedule_lookup_tasks): u = login(client, faker) dth = DemographicsTestHelper(faker=faker, user=u, row_count=2, find_pre_pmi_details=False) dr = dth.get_demographics_request__post_pmi_lookup() dr.data[0].pmi_post_processed_datetime = datetime.datetime.utcnow() db.session.add(dr.data[0]) db.session.commit() expected = PmiData(**faker.pmi_details(1)) mock_pmi_details.return_value = expected extract_post_pmi_details(dr.id) actual = DemographicsRequest.query.get(dr.id) assert actual.pmi_data_post_completed_datetime is None assert sum(1 for d in actual.data if d.pmi_post_processed_datetime is not None) == 2 assert expected == actual.data[1].pmi_data assert len(actual.data[0].messages) == 0 mock_schedule_lookup_tasks.assert_called_once_with(dr.id) _remove_files(dr)
def test__extract_post_pmi_details__no_data(client, faker, mock_pmi_details, mock_schedule_lookup_tasks): u = login(client, faker) dth = DemographicsTestHelper(faker=faker, user=u) dr = dth.get_demographics_request__uploaded() extract_post_pmi_details(dr.id) actual = DemographicsRequest.query.get(dr.id) assert actual.pmi_data_post_completed_datetime is not None mock_schedule_lookup_tasks.assert_called_once_with(dr.id) _remove_files(dr)
def test__extract_post_pmi_details__last_processed(client, faker, mock_pmi_details, mock_schedule_lookup_tasks): u = login(client, faker) dth = DemographicsTestHelper(faker=faker, user=u, row_count=1, find_pre_pmi_details=False) dr = dth.get_demographics_request__post_pmi_lookup() dr.data[0].pmi_post_processed_datetime = datetime.datetime.utcnow() db.session.add(dr.data[0]) db.session.commit() extract_post_pmi_details(dr.id) actual = DemographicsRequest.query.get(dr.id) assert actual.pmi_data_post_completed_datetime is not None assert len(actual.data[0].messages) == 0 mock_schedule_lookup_tasks.assert_called_once_with(dr.id) _remove_files(dr)
def test__extract_post_pmi_details__pmi_not_found(client, faker, mock_pmi_details, mock_schedule_lookup_tasks): u = login(client, faker) dth = DemographicsTestHelper(faker=faker, user=u, row_count=1, find_pre_pmi_details=False) dr = dth.get_demographics_request__post_pmi_lookup() mock_pmi_details.return_value = None extract_post_pmi_details(dr.id) actual = DemographicsRequest.query.get(dr.id) assert actual.pmi_data_post_completed_datetime is None assert sum(1 for d in actual.data if d.pmi_post_processed_datetime is not None) == 1 assert actual.data[0].pmi_data is None assert len(actual.data[0].messages) == 0 mock_schedule_lookup_tasks.assert_called_once_with(dr.id) _remove_files(dr)