Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ logging upon failure in the [audit_trail_helper](/acceptance_tests/utilities/aud
| expected_collection_instrument_url | Stores the collection instrument URL expected on emitted `UAC_UPDATE` events | str |
| fulfilment_personalisation | Stores the personalisation values from a received fulfilment request event | Dict |
| sample | Stores the parsed sample file rows, split into `sample` and `sensitive` | List |
| sample_rows | Stores the parsed rows from the sample file used by the current scenario | List |
| export_file_templates | Stores the list of export file templates setup prior to the tests | Mapping |
| export_file_packcodes | Stores the list of export packcodes setup prior to the tests | Mapping |
| sms_templates | Stores the list of sms templates setup prior to the tests | Mapping |
Expand Down
3 changes: 2 additions & 1 deletion acceptance_tests/features/load_sample.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Feature: Sample files of all accepted shapes can be loaded

Scenario: A sample file is loaded
Given sample file "sample_input_england_census_spec.csv" is loaded successfully
Given sample file "sample_input_england_census_spec.csv" is loaded successfully
Then the outbound CASE_UPDATE events contain the expected sample data
91 changes: 77 additions & 14 deletions acceptance_tests/features/steps/sample_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,23 @@ def get_emitted_cases_and_check_against_sample(sample_rows, test_start_time):
emitted_cases = get_emitted_cases(len(sample_rows), test_start_time)
unmatched_sample_rows = sample_rows.copy()
for emitted_case in emitted_cases:
matched_row = None
for sample_row in unmatched_sample_rows:
if (sample_row["ESTAB_UPRN"] == emitted_case["address"]["estabUprn"] and
sample_row["ADDRESS_LINE1"] == emitted_case["address"]["addressLine1"] and
sample_row["UPRN"] == emitted_case["address"]["uprn"] and
sample_row["ADDRESS_LEVEL"] == emitted_case["address"]["addressLevel"]):
matched_row = sample_row
break

if matched_row:
unmatched_sample_rows.remove(matched_row)
else:
test_helper.fail(f"Could not find matching row in the sample data for case: {emitted_case} "
f"all emitted cases: {emitted_cases}")
matched_row = get_matching_sample_row(emitted_case, unmatched_sample_rows)
unmatched_sample_rows.remove(matched_row)

return emitted_cases


def get_matching_sample_row(emitted_case, sample_rows):
for sample_row in sample_rows:
if (sample_row["ESTAB_UPRN"] == emitted_case["address"]["estabUprn"] and
sample_row["ADDRESS_LINE1"] == emitted_case["address"]["addressLine1"] and
sample_row["UPRN"] == emitted_case["address"]["uprn"] and
sample_row["ADDRESS_LEVEL"] == emitted_case["address"]["addressLevel"]):
return sample_row

test_helper.fail(f"Could not find matching row in the sample data for case: {emitted_case}")


@step('sample file "{sample_file_name}" is loaded successfully')
def load_sample(context, sample_file_name):
sample_file_path = Config.SAMPLE_FILES_PATH.joinpath(sample_file_name)
Expand All @@ -49,6 +48,7 @@ def load_sample(context, sample_file_name):

upload_and_process_file_by_api(context.collex_id, sample_file_path, 'SAMPLE')

context.sample_rows = sample_rows
context.emitted_cases = get_emitted_cases_and_check_against_sample(sample_rows, context.test_start_utc_datetime)
non_n_emitted_case_ids = non_n_case_ids(context.emitted_cases)

Expand All @@ -61,3 +61,66 @@ def load_sample(context, sample_file_name):
test_helper.assertEqual(action_instruction['actionInstruction'], 'CREATE')
else:
context.emitted_fieldwork_action_instructions = []


@step('the outbound CASE_UPDATE events contain the expected sample data')
def check_outbound_case_update_events(context):
address_fields = {
"abpCode": "ABP_CODE",
"addressLevel": "ADDRESS_LEVEL",
"addressLine1": "ADDRESS_LINE1",
"addressLine2": "ADDRESS_LINE2",
"addressLine3": "ADDRESS_LINE3",
"addressType": "ADDRESS_TYPE",
"estabType": "ESTAB_TYPE",
"estabUprn": "ESTAB_UPRN",
"latitude": "LATITUDE",
"longitude": "LONGITUDE",
"organisationName": "ORGANISATION_NAME",
"postcode": "POSTCODE",
"townName": "TOWN_NAME",
"uprn": "UPRN",
}
case_fields = {
"caseType": "ADDRESS_TYPE",
"fieldCoordinatorId": "FIELDCOORDINATOR_ID",
"fieldOfficerId": "FIELDOFFICER_ID",
"htcDigital": "HTC_DIGITAL",
"htcWillingness": "HTC_WILLINGNESS",
"lad": "LAD",
"lsoa": "LSOA",
"msoa": "MSOA",
"oa": "OA",
"printBatch": "PRINT_BATCH",
"treatmentCode": "TREATMENT_CODE",
}

for emitted_case in context.emitted_cases:
sample_row = get_matching_sample_row(emitted_case, context.sample_rows)

for event_field, sample_field in address_fields.items():
test_helper.assertEqual(
emitted_case["address"][event_field],
sample_row[sample_field],
f'CASE_UPDATE address field "{event_field}" did not match sample row {sample_row}')

for event_field, sample_field in case_fields.items():
test_helper.assertEqual(
emitted_case[event_field],
sample_row[sample_field],
f'CASE_UPDATE field "{event_field}" did not match sample row {sample_row}')

sample_region = sample_row["REGION"]
emitted_region = emitted_case["address"]["region"]
test_helper.assertGreater(
len(sample_region),
1,
f'Test sample region must contain more than one character, but was "{sample_region}"')
test_helper.assertEqual(
emitted_region,
sample_region[0],
f'CASE_UPDATE region must be the leading character of sample region "{sample_region}"')
test_helper.assertEqual(
len(emitted_region),
1,
f'CASE_UPDATE region must contain one character, but was "{emitted_region}"')
Loading