def test_get_call_history_records_with_invalid_dates(interviewer_name, invalid_date): with pytest.raises(BertException) as err: get_call_history_records(interviewer_name, invalid_date, invalid_date) assert err.value.message == "Invalid date range parameters provided" assert err.value.code == 400
def test_get_call_history_records_with_multiple_entities_returns_all_webnudges( mock_get_datastore_records, interviewer_name, start_date_as_string, end_date_as_string, webnudge_outcome_code): original_status = "Questionnaire" new_status = "WebNudge" mock_datastore_entities = [ entity_builder(1, interviewer_name, start_date_as_string, end_date_as_string, webnudge_outcome_code, original_status), entity_builder(2, interviewer_name, start_date_as_string, end_date_as_string, webnudge_outcome_code, original_status) ] mock_get_datastore_records.return_value = mock_datastore_entities assert len(mock_datastore_entities) == 2 assert mock_datastore_entities[0]["status"] == original_status assert mock_datastore_entities[1]["status"] == original_status results = get_call_history_records(interviewer_name, start_date_as_string, end_date_as_string) assert len(results) == 2 assert results[0]["status"] == new_status assert results[1]["status"] == new_status
def test_get_call_history_records_with_multiple_entities_returns_one_webnudge( mock_get_datastore_records, interviewer_name, start_date_as_string, end_date_as_string, webnudge_outcome_code, arbitrary_outcome_code): original_status = "Completed" new_status = "WebNudge" mock_datastore_entities = [ entity_builder(2, interviewer_name, start_date_as_string, end_date_as_string, webnudge_outcome_code, original_status), entity_builder(3, interviewer_name, start_date_as_string, end_date_as_string, arbitrary_outcome_code, original_status), entity_builder(4, interviewer_name, start_date_as_string, end_date_as_string, arbitrary_outcome_code, original_status) ] mock_get_datastore_records.return_value = mock_datastore_entities assert len(mock_datastore_entities) == 3 assert mock_datastore_entities[0]["status"] == original_status assert mock_datastore_entities[1]["status"] == original_status assert mock_datastore_entities[2]["status"] == original_status results = get_call_history_records(interviewer_name, start_date_as_string, end_date_as_string) assert len(results) == 3 assert results[0]["status"] == new_status assert results[1]["status"] == original_status assert results[2]["status"] == original_status
def get_call_pattern_report(interviewer_name: str, start_date_string: str, end_date_string: str, survey_tla: str, questionnaires=None) -> object: result = get_call_history_records(interviewer_name, start_date_string, end_date_string, survey_tla, questionnaires) records = pd.DataFrame(result) print( f"Calculating call pattern data for interviewer '{interviewer_name}'") if records.empty: return {} if no_valid_records_are_found(records): return InterviewerCallPatternWithNoValidData( discounted_invalid_cases=percentage_of_invalid_records(records), invalid_fields=", ".join( provide_reasons_for_invalid_records(records))) return InterviewerCallPattern( total_valid_cases=len(get_valid_records(records)), hours_worked=str(calculate_hours_worked_as_datetime(records)), call_time=str(calculate_call_time_as_datetime(records)), hours_on_calls_percentage=calculate_hours_on_call_percentage(records), average_calls_per_hour=calculate_average_calls_per_hour(records), refusals=number_of_records_which_has_status(records, "Finished (Non response)"), no_contacts=number_of_records_which_has_status( records, "Finished (No contact)"), completed_successfully=number_of_records_which_has_status( records, "Completed"), appointments_for_contacts=number_of_records_which_has_status( records, "Finished (Appointment made)"), web_nudge=number_of_records_which_has_status(records, "WebNudge"), no_contact_answer_service=total_no_contact_records_with_call_result( records, "AnswerService"), no_contact_busy=total_no_contact_records_with_call_result( records, "Busy"), no_contact_disconnect=total_no_contact_records_with_call_result( records, "Disconnect"), no_contact_no_answer=total_no_contact_records_with_call_result( records, "NoAnswer"), no_contact_other=total_no_contact_records_with_call_result( records, "Others"), discounted_invalid_cases=percentage_of_invalid_records(records), invalid_fields=", ".join(provide_reasons_for_invalid_records(records)))
def test_get_call_history_records_with_one_datastore_entity( mock_get_datastore_records, interviewer_name, start_date_as_string, end_date_as_string, arbitrary_outcome_code): mock_datastore_entity = [ entity_builder(1, interviewer_name, start_date_as_string, end_date_as_string, arbitrary_outcome_code, "Completed") ] mock_get_datastore_records.return_value = mock_datastore_entity results = get_call_history_records(interviewer_name, start_date_as_string, end_date_as_string) assert len(results) == 1 assert results == mock_datastore_entity mock_get_datastore_records.assert_called_with( interviewer_name, datetime.datetime(2021, 9, 22, 0, 0), datetime.datetime(2021, 9, 22, 23, 59, 59), None, None)
def test_get_call_history_records_with_one_datastore_entity_returns_webnudge( mock_get_datastore_records, interviewer_name, start_date_as_string, end_date_as_string, webnudge_outcome_code): original_status = "Completed" new_status = "WebNudge" mock_datastore_entity = [ entity_builder(1, interviewer_name, start_date_as_string, end_date_as_string, webnudge_outcome_code, original_status) ] mock_get_datastore_records.return_value = mock_datastore_entity assert len(mock_datastore_entity) == 1 assert mock_datastore_entity[0]["status"] == original_status results = get_call_history_records(interviewer_name, start_date_as_string, end_date_as_string) assert len(results) == 1 assert results[0]["status"] == new_status
def test_get_call_history_records_with_a_list_of_questionnaires( mock_get_datastore_records, interviewer_name, start_date_as_string, end_date_as_string, arbitrary_outcome_code): mock_datastore_entity = [ entity_builder(1, interviewer_name, start_date_as_string, end_date_as_string, arbitrary_outcome_code, "Completed") ] mock_get_datastore_records.return_value = mock_datastore_entity results = get_call_history_records( interviewer_name, start_date_as_string, end_date_as_string, survey_tla="LMS", questionnaires=["LMS2202_TST", "LMS2101_AA1"]) assert len(results) == 1 assert results == mock_datastore_entity mock_get_datastore_records.assert_called_with( interviewer_name, datetime.datetime(2021, 9, 22, 0, 0), datetime.datetime(2021, 9, 22, 23, 59, 59), "LMS", ["LMS2202_TST", "LMS2101_AA1"])
def get_call_history_report(interviewer, start_date, end_date, survey_tla, questionnaires): return get_call_history_records(interviewer, start_date, end_date, survey_tla, questionnaires)