-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed respondent data to log warning messages instead of print stat…
…ements If respondent data is empty is is not zipped up in reports added feature tests
- Loading branch information
Showing
10 changed files
with
1,073 additions
and
755 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from typing import List | ||
import pytest | ||
from werkzeug.security import generate_password_hash | ||
from app.app import setup_app | ||
from models.mi_hub_call_history_model import MiHubCallHistory | ||
from unittest.mock import create_autospec | ||
from functions.google_storage_functions import GoogleStorage | ||
|
||
|
||
def mock_mi_hub_call_history() -> List[MiHubCallHistory]: | ||
return [ | ||
MiHubCallHistory( | ||
questionnaire_name="LMS2222Z", | ||
questionnaire_id="s0me-r7nd0m-gu1d", | ||
serial_number="900001", | ||
dial_date="20221017", | ||
dial_time="10:31:36", | ||
end_time="10:32:06", | ||
seconds_interview=30, | ||
call_number=1, | ||
dial_number=1, | ||
interviewer="thorne1", | ||
dial_line_number=None, | ||
outcome_code="461", | ||
), | ||
MiHubCallHistory( | ||
questionnaire_name="LMS2222Z", | ||
questionnaire_id="s0me-r7nd0m-gu1d", | ||
serial_number="900002", | ||
dial_date="20221017", | ||
dial_time="10:33:36", | ||
end_time="10:34:36", | ||
seconds_interview=60, | ||
call_number=1, | ||
dial_number=1, | ||
interviewer="thorne1", | ||
dial_line_number=None, | ||
outcome_code="461", | ||
), | ||
MiHubCallHistory( | ||
questionnaire_name="LMS2222Z", | ||
questionnaire_id="s0me-r7nd0m-gu1d", | ||
serial_number="900003", | ||
dial_date="20221017", | ||
dial_time="10:35:36", | ||
end_time="10:35:46", | ||
seconds_interview=10, | ||
call_number=1, | ||
dial_number=1, | ||
interviewer="thorne1", | ||
dial_line_number=None, | ||
outcome_code="461", | ||
), | ||
] | ||
|
||
|
||
def before_scenario(context, _scenario): | ||
context.questionnaire_name = "LMS2222Z" | ||
context.mi_hub_respondent_data = [] | ||
context.mi_hub_call_history = mock_mi_hub_call_history() | ||
context.mock_google_storage = create_autospec(GoogleStorage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
Feature: Generate Reports | ||
|
||
Scenario Outline: All fields and data are available | ||
Given all of the following fields are available for the Respondent Data report | ||
| field_name | value | | ||
| QID.Serial_Number | 900001 | | ||
| QHAdmin.HOut | 310 | | ||
| QHAdmin.Interviewer[1] | testuser | | ||
| Mode | testmode | | ||
| QDataBag.PostCode | PO57 2OD | | ||
| QHousehold.QHHold.Person[1].Sex | Male | | ||
| QHousehold.QHHold.Person[1].tmpDoB| 2-11-2022_3:08 | | ||
| QHousehold.QHHold.Person[1].DVAge | 2 | | ||
| DateTimeStamp | 2-11-2022_9:20 | | ||
Then data is present in all fields | ||
When the report generation is triggered | ||
Then the report should be generated and delivered | ||
And no warnings should be logged | ||
Examples: | ||
| field_name | | ||
| 0 | | ||
|
||
Scenario Outline: Some fields are missing and all data is available | ||
Given all of the following fields are available for the Respondent Data report | ||
| field_name | value | | ||
| QID.Serial_Number | 900001 | | ||
| QHAdmin.HOut | 310 | | ||
| QHAdmin.Interviewer[1] | testuser | | ||
| Mode | testmode | | ||
| QDataBag.PostCode | | | ||
| QHousehold.QHHold.Person[1].Sex | Male | | ||
| QHousehold.QHHold.Person[1].tmpDoB| | | ||
| QHousehold.QHHold.Person[1].DVAge | 2 | | ||
| DateTimeStamp | 2-11-2022_9:20 | | ||
Then data is present in all fields | ||
Then the field "postcode" is missing | ||
And the field "date_of_birth" is missing | ||
When the report generation is triggered | ||
Then the report should be generated and delivered | ||
And "Done - LMS2222Z" is logged as an information message | ||
Examples: | ||
| field_name | | ||
| 0 | | ||
|
||
|
||
Scenario Outline: All fields are missing | ||
Given none of the following fields are available for the report | ||
| field_name | | ||
| QID.Serial_Number | | ||
| QHAdmin.HOut | | ||
| QHAdmin.Interviewer[1] | | ||
| Mode | | ||
| QDataBag.PostCode | | ||
| QHousehold.QHHold.Person[1].Sex | | ||
| QHousehold.QHHold.Person[1].tmpDoB| | ||
| QHousehold.QHHold.Person[1].DVAge | | ||
| DateTimeStamp | | ||
When the report generation is triggered | ||
Then the report should be generated and delivered | ||
And "No respondent data for LMS2222Z" is logged as an warning message | ||
Examples: | ||
| field_name | | ||
| 0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# type: ignore[no-redef] | ||
|
||
import logging | ||
from behave import given, then, when | ||
from models.mi_hub_respondent_data_model import MiHubRespondentData | ||
from services.deliver_mi_hub_reports_service import DeliverMiHubReportsService | ||
|
||
|
||
@given('all of the following fields are available for the Respondent Data report') | ||
def step_impl(context): | ||
if context.table: | ||
fields = {row["field_name"]: row["value"] for row in context.table} | ||
|
||
context.mi_hub_respondent_data = [MiHubRespondentData( | ||
serial_number=str(fields["QID.Serial_Number"]), | ||
outcome_code=str(fields["QHAdmin.HOut"]), | ||
date_completed=str(fields["DateTimeStamp"]), | ||
interviewer=str(fields["QHAdmin.Interviewer[1]"]), | ||
mode=str(fields["Mode"]), | ||
postcode=str(fields["QDataBag.PostCode"]), | ||
gender=str(fields["QHousehold.QHHold.Person[1].Sex"]), | ||
date_of_birth=str(fields["QHousehold.QHHold.Person[1].tmpDoB"]), | ||
age=str(fields["QHousehold.QHHold.Person[1].DVAge"]), | ||
)] | ||
|
||
|
||
@when('the report generation is triggered') | ||
def step_impl(context): | ||
response = DeliverMiHubReportsService.upload_mi_hub_reports_to_gcp( | ||
questionnaire_name=context.questionnaire_name, | ||
mi_hub_call_history=context.mi_hub_call_history, | ||
mi_hub_respondent_data=context.mi_hub_respondent_data, | ||
google_storage=context.mock_google_storage, | ||
) | ||
|
||
context.response = response | ||
|
||
|
||
@then('data is present in all fields') | ||
def step_impl(context): | ||
for respondent_data in context.mi_hub_respondent_data: | ||
assert ( | ||
not all(value in ("", None) for value in vars(respondent_data).values()) | ||
), f"Fields are not all present" | ||
|
||
|
||
@then('the field "{field}" is missing') | ||
def step_impl(context, field): | ||
for respondent_data in context.mi_hub_respondent_data: | ||
assert ( | ||
getattr(respondent_data, field) == "" | ||
), f"Field {field} is present" | ||
|
||
|
||
@given('none of the following fields are available for the report') | ||
def step_impl(context): | ||
context.mi_hub_respondent_data = [] | ||
|
||
|
||
@then('the report should be generated and delivered') | ||
def step_impl(context): | ||
assert ( | ||
context.response == "Done - " + context.questionnaire_name | ||
), f"No report is generated" | ||
|
||
|
||
@then('no warnings should be logged') | ||
def step_impl(context): | ||
assert ( | ||
True | ||
), f"Warnings should not be generated" | ||
|
||
|
||
@then('"{message}" is logged as an {error_level} message') | ||
def step_impl(context, message, error_level): | ||
messages = [ | ||
(record.levelno, record.getMessage()) for record in context.log_capture.buffer | ||
] | ||
mappings = {"information": logging.INFO, "error": logging.ERROR, "warning": logging.WARNING} | ||
assert ( | ||
mappings[error_level], | ||
message, | ||
) in messages, f"Could not find {mappings[error_level]}, {message} in {messages}" |