Esempio n. 1
0
def check_census_case_fields(context):
    test_helper.assertTrue(context.case_details['caseRef'])
    test_helper.assertEquals(len(context.case_details['caseRef']), 10)
    test_helper.assertTrue(luhn.verify(context.case_details['caseRef']))

    test_helper.assertTrue(context.case_details['estabUprn'])
    test_helper.assertTrue(context.case_details['estabType'])
    test_helper.assertTrue(context.case_details['uprn'])
    test_helper.assertTrue(context.case_details['collectionExerciseId'])
    test_helper.assertTrue(context.case_details['createdDateTime'])
    test_helper.assertTrue(context.case_details['lastUpdated'])
    test_helper.assertTrue(context.case_details['addressLine1'])
    test_helper.assertTrue(context.case_details['addressLine2'])
    test_helper.assertTrue(context.case_details['addressLine3'])
    test_helper.assertTrue(context.case_details['townName'])
    test_helper.assertTrue(context.case_details['postcode'])
    test_helper.assertTrue(context.case_details['addressLevel'])
    test_helper.assertTrue(context.case_details['abpCode'])
    test_helper.assertTrue(context.case_details['region'])
    test_helper.assertTrue(context.case_details['latitude'])
    test_helper.assertTrue(context.case_details['longitude'])
    test_helper.assertTrue(context.case_details['oa'])
    test_helper.assertTrue(context.case_details['lsoa'])
    test_helper.assertTrue(context.case_details['msoa'])
    test_helper.assertTrue(context.case_details['lad'])
    test_helper.assertTrue(context.case_details['id'])
    test_helper.assertTrue(context.case_details['addressType'])
    test_helper.assertTrue(context.case_details['caseType'])
    test_helper.assertEqual(context.case_details['surveyType'], "CENSUS")
    test_helper.assertFalse(context.case_details['handDelivery'])
Esempio n. 2
0
def retrieve_ce_secureType_true_or_false_case(context):
    context.first_case = get_case_and_case_events_by_case_id(context.case_id)

    test_helper.assertEqual(context.first_case['id'], context.case_id)
    test_helper.assertEqual(context.first_case['collectionExerciseId'], context.collection_exercise_id)

    _check_ce_secure_estab_case_address_details(context.first_case)
def check_correct_Welsh_CE_Estab_questionnaire_files_on_sftp_server(context, pack_code):
    # in the print file, there will be multiple rows with English/Welsh UAC/QID pairs for each case
    # we do not know which English UAC/QID pair will be on which row as the Welsh UAC/QID pair is on
    # so 'line_ending' matches the case details after UAC/QID values have been assigned
    # we filter print file by 'line_ending' to get a list of rows for that case
    # then we check that Ind English and Ind Welsh UAC/QID pairs are accounted for in the filtered rows

    expected_case_data = create_expected_Welsh_CE_Estab_questionnaire_csv_line_endings(context, pack_code)

    expected_print_file_line_count = 0
    for case_id, value in expected_case_data.items():
        expected_print_file_line_count += value['case_details']['ceExpectedCapacity']

    actual_print_file_rows = check_ce_estab_welsh_questionnaire_is_correct(context, pack_code,
                                                                           expected_print_file_line_count)

    for case_id, value in expected_case_data.items():
        matching_rows = []
        for row in actual_print_file_rows:
            if row.endswith(value['line_ending']):
                matching_rows.append(row)

        test_helper.assertEqual(len(matching_rows), value['case_details']['ceExpectedCapacity'])

        for uac in context.uac_created_events:
            if uac['payload']['uac']['caseId'] == value['case_details']['id']:
                _check_uac_qid_pair_located_in_welsh_ce_estab_cases(matching_rows, uac, value)
Esempio n. 4
0
def get_case_by_id(context, expected_value):
    case_id = context.case_created_events[0]['payload']['collectionCase']['id']
    response = requests.get(f'{Config.CASE_API_CASE_URL}{case_id}')
    test_helper.assertEqual(response.status_code, 200, 'Case not found')
    case_details = response.json()

    assert case_details['secureEstablishment'] == str2bool(expected_value), "Unexpected secureEstablishment value"
Esempio n. 5
0
def get_case_id_by_questionnaire_id(questionnaire_id):
    response = requests.get(
        f'{Config.CASE_API_CASE_URL}/qid/{questionnaire_id}')
    test_helper.assertEqual(response.status_code, 200,
                            "Unexpected status code")
    response_json = response.json()
    return response_json['id']
Esempio n. 6
0
def case_updated_msg_with_metadata_field(context, field, expected_field_value):
    start_listening_to_rabbit_queue(
        Config.RABBITMQ_RH_OUTBOUND_CASE_QUEUE,
        functools.partial(store_first_message_in_context, context=context))
    test_helper.assertEqual(
        context.first_message['payload']['metadata'][field],
        expected_field_value)
Esempio n. 7
0
def gather_welsh_reminder_uac_events(context, number_of_matching_cases):
    context.messages_received = []
    start_listening_to_rabbit_queue(
        Config.RABBITMQ_RH_OUTBOUND_UAC_QUEUE,
        functools.partial(
            store_all_uac_updated_msgs_by_collection_exercise_id,
            context=context,
            expected_msg_count=number_of_matching_cases * 2,
            collection_exercise_id=context.collection_exercise_id))
    test_helper.assertEquals(len(context.messages_received),
                             number_of_matching_cases * 2)
    context.reminder_uac_updated_events = context.messages_received.copy()
    qids = [
        uac_updated['payload']['uac']['questionnaireId']
        for uac_updated in context.reminder_uac_updated_events
    ]
    test_helper.assertEqual(
        len([qid for qid in qids
             if qid.startswith('02')]), number_of_matching_cases,
        (f'Expected to find an "02" questionnaire type QID '
         f'for each of the {number_of_matching_cases} cases, found {qids}'))
    test_helper.assertEqual(
        len([qid for qid in qids
             if qid.startswith('03')]), number_of_matching_cases,
        (f'Expected to find an "03" questionnaire type QID '
         f'for each of the {number_of_matching_cases} cases, found {qids}'))
    context.reminder_case_ids = {
        uac['payload']['uac']['caseId']
        for uac in context.reminder_uac_updated_events
    }
    context.messages_received = []
def get_new_qid_and_case_as_required(context, case_type, address_level, qid_type, country_code):
    context.loaded_case = context.case_created_events[0]['payload']['collectionCase']
    # receipting_case will be over written if a child case is created
    context.receipting_case = context.case_created_events[0]['payload']['collectionCase']

    if qid_type == "CE1":
        return qid_type_equals_ce1(address_level, case_type, context, country_code)

    if qid_type == "HH":
        return qid_type_equals_hh(case_type, context, country_code)

    if qid_type == 'Ind':
        if case_type == 'HI':
            context.case_type = "HI"
            request_hi_individual_telephone_capture(context, "HH", country_code)
            context.qid_to_receipt = context.telephone_capture_qid_uac['questionnaireId']
            context.receipting_case = _get_emitted_case(context, 'CASE_CREATED')

            uac = _get_emitted_uac(context)
            test_helper.assertEqual(uac['caseId'], context.receipting_case['id'])
            test_helper.assertEquals(uac['questionnaireId'], context.qid_to_receipt)
            return
        else:
            request_individual_telephone_capture(context, case_type, country_code)
            context.qid_to_receipt = context.telephone_capture_qid_uac['questionnaireId']
            check_correct_uac_updated_message_is_emitted(context)
            return

    if qid_type == 'Cont':
        send_print_fulfilment_request(context, "P_OR_HC1")
        listen_for_ad_hoc_uac_updated_message(context, "11")
        context.qid_to_receipt = context.requested_qid
        return

    test_helper.assertFalse(f"Failed to get qid for {qid_type}")
Esempio n. 9
0
def retrieve_skeleton_case_and_check_uprn(context):
    context.first_case = get_case_and_case_events_by_case_id(context.case_id)

    test_helper.assertEqual(context.first_case['id'], context.case_id)
    test_helper.assertEqual(context.first_case['collectionExerciseId'], context.collection_exercise_id)

    expected_estab_uprn = context.new_address_uprn  # estabUprn should match uprn from event
    _check_case_address_details(context.first_case, context.new_address_uprn, expected_estab_uprn)
def check_case_created(context, address_type):
    response = requests.get(f'{Config.CASE_API_CASE_URL}{context.case_id}',
                            params={'caseEvents': True})
    test_helper.assertEqual(response.status_code, 200,
                            'CCS Property Listed case not found')

    context.first_case = context.ccs_case = response.json()
    test_helper.assertEqual(context.ccs_case['addressType'], address_type)
Esempio n. 11
0
def refusal_received(context):
    start_listening_to_rabbit_queue(
        Config.RABBITMQ_OUTBOUND_FIELD_QUEUE,
        functools.partial(field_work_cancel_callback, context=context))

    test_helper.assertEqual(context.fwmt_emitted_case_id,
                            context.refused_case_id)
    test_helper.assertEqual(context.addressType, 'HH')
Esempio n. 12
0
def retrieve_case_from_source_case_id_and_event_details(context):
    context.first_case = get_case_and_case_events_by_case_id(context.case_id)

    test_helper.assertEqual(context.first_case['id'], context.case_id)
    test_helper.assertEqual(context.first_case['collectionExerciseId'], context.collection_exercise_id)

    source_case = context.case_created_events[0]['payload']['collectionCase']
    _check_case_address_details(context.first_case, source_case['address']['uprn'],
                                source_case['address']['estabUprn'], expected_address_type=context.case_type)
Esempio n. 13
0
def validate_ccs_qid_for_case_id(context):
    response_json = get_ccs_qid_for_case_id(context.ccs_case['id'])
    test_helper.assertEqual(
        response_json['questionnaireId'][0:3], '713',
        'CCS QID has incorrect questionnaire type or tranche ID')
    test_helper.assertTrue(response_json['active'])
    test_helper.assertEqual(
        response_json['formType'], "H",
        f'Expected FormType is "H" but got "{response_json["formType"]}"')
Esempio n. 14
0
def check_case_created_message_is_emitted(context):
    context.messages_received = []
    start_listening_to_rabbit_queue(
        Config.RABBITMQ_RH_OUTBOUND_CASE_QUEUE,
        functools.partial(store_first_message_in_context, context=context))
    test_helper.assertEqual(
        context.first_message['payload']['collectionCase']['id'],
        context.case_id)
    context.case_created_events = [context.first_message]
Esempio n. 15
0
def _validate_case(parsed_body):
    test_helper.assertEqual('CENSUS',
                            parsed_body['payload']['collectionCase']['survey'])
    actual_case_ref = parsed_body['payload']['collectionCase']['caseRef']
    test_helper.assertEqual(10, len(actual_case_ref))
    parse_datetime(parsed_body['payload']['collectionCase']['createdDateTime'])
    parse_datetime(parsed_body['payload']['collectionCase']['lastUpdated'])

    test_helper.assertTrue(luhn.verify(actual_case_ref))
def check_address_valid_case_updated_events(context):
    address_valid_case_ids = [case_id['CASE_ID'] for case_id in context.bulk_uninvalidated_addresses]
    context.case_updated_events = get_case_updated_events(context, len(address_valid_case_ids))
    test_helper.assertEqual(len(context.case_updated_events), len(context.bulk_uninvalidated_addresses))
    for event in context.case_updated_events:
        test_helper.assertFalse(event['payload']['collectionCase']['addressInvalid'],
                                'Address invalid flag must be "False" on all updated events')
        test_helper.assertIn(event['payload']['collectionCase']['id'], address_valid_case_ids,
                             'Unexpected case ID found on updated event')
Esempio n. 17
0
def retrieve_skeleton_case_and_check_dummy_uprn(context):
    context.first_case = get_case_and_case_events_by_case_id(context.case_id)

    test_helper.assertEqual(context.first_case['id'], context.case_id)
    test_helper.assertEqual(context.first_case['collectionExerciseId'], context.collection_exercise_id)

    expected_dummy_uprn = f"999{context.first_case['caseRef']}"
    expected_dummy_estab_uprn = expected_dummy_uprn

    _check_case_address_details(context.first_case, expected_dummy_uprn, expected_dummy_estab_uprn)
Esempio n. 18
0
def test_uacs_correct_for_estab_units(context, expected_uacs,
                                      questionnaire_type):
    questionnaire_types_list = questionnaire_type.replace('[', '').replace(
        ']', '').split(',')
    test_helper.assertEqual(len(context.messages_received), expected_uacs)

    for msg in context.uac_created_events:
        _validate_uac_message(msg)
        test_helper.assertIn(msg['payload']['uac']['questionnaireId'][:2],
                             questionnaire_types_list)
def _check_if_event_is_logged(expected_event_type, case_id):
    actual_logged_events = get_logged_events_for_case_by_id(case_id)
    actual_logged_event_types = [
        event['eventType'] for event in actual_logged_events
    ]
    test_helper.assertEqual(
        actual_logged_event_types.count(expected_event_type),
        1,
        msg=(f'Expected event type = {expected_event_type},'
             f' actual logged event types = {actual_logged_event_types}'))
Esempio n. 20
0
def check_new_case(context, case_type, address_level):
    response = requests.get(f'{Config.CASE_API_CASE_URL}{context.new_case_id}?caseEvents=true')
    test_helper.assertEqual(response.status_code, 200, 'Case not found')
    new_case = response.json()
    emitted_case_created_event = context.case_created_events[0]['payload']['collectionCase']

    address_type_changed_check_created_event(emitted_case_created_event, context.old_case,
                                             context.event, address_level)

    address_type_changed_check_case(new_case, context.old_case, context.event, address_level)
Esempio n. 21
0
def new_addresses_sent_to_field_secureType_false(context):
    context.messages_received = []
    start_listening_to_rabbit_queue(Config.RABBITMQ_OUTBOUND_FIELD_QUEUE,
                                    functools.partial(
                                        store_all_msgs_in_context, context=context,
                                        expected_msg_count=1))

    field_msg = context.messages_received[0]
    test_helper.assertEqual(field_msg['actionInstruction'], 'CREATE')
    test_helper.assertFalse(field_msg['secureEstablishment'])
Esempio n. 22
0
def telephone_capture_against_case(context):
    context.first_case = context.case_created_events[0]['payload'][
        'collectionCase']
    context.fulfilment_requested_case_id = context.case_created_events[0][
        'payload']['collectionCase']['id']
    response = requests.get(
        f"{Config.CASEAPI_SERVICE}/cases/{context.first_case['id']}/qid")
    test_helper.assertEqual(response.status_code, 200)

    context.telephone_capture_qid_uac = response.json()
def check_message_to_field_for_ccs_case(context, action_instruction_type):
    context.messages_received = []
    start_listening_to_rabbit_queue(Config.RABBITMQ_OUTBOUND_FIELD_QUEUE,
                                    functools.partial(
                                        store_all_msgs_in_context, context=context,
                                        expected_msg_count=1))

    msg_to_field = context.messages_received[0]
    test_helper.assertEquals(msg_to_field['caseId'], context.ccs_case['id'])
    test_helper.assertEquals(msg_to_field['actionInstruction'], action_instruction_type)
    test_helper.assertEqual(msg_to_field['surveyName'], context.ccs_case['surveyType'])
def _get_emitted_uac(context):
    context.messages_received = []
    start_listening_to_rabbit_queue(Config.RABBITMQ_RH_OUTBOUND_UAC_QUEUE,
                                    functools.partial(
                                        store_all_msgs_in_context, context=context,
                                        expected_msg_count=1,
                                        type_filter='UAC_UPDATED'))

    test_helper.assertEqual(len(context.messages_received), 1)

    return context.messages_received[0]['payload']['uac']
Esempio n. 25
0
def uac_updated_with_active_set_to_false_for_all_original_uacs(context):
    uac_updated_events = get_uac_updated_events(
        context, len(context.bulk_deactivate_uac))

    for uac_updated in uac_updated_events:
        test_helper.assertFalse(uac_updated['payload']['uac']['active'])
        context.bulk_deactivate_uac.remove(
            uac_updated['payload']['uac']['questionnaireId'])

    test_helper.assertEqual(
        len(context.bulk_deactivate_uac), 0,
        "Expected to be empty after matching UAC_UPDATED events emitted")
Esempio n. 26
0
def create_msg_sent_to_field(context):
    context.messages_received = []
    start_listening_to_rabbit_queue(Config.RABBITMQ_OUTBOUND_FIELD_QUEUE, functools.partial(
        _field_work_create_callback, context=context))

    test_helper.assertEqual(context.fwmt_emitted_case_id, context.case_id)
    test_helper.assertEqual(context.addressType, "SPG")
    test_helper.assertEqual(context.field_action_create_message['surveyName'], "CENSUS")
    test_helper.assertEqual(context.field_action_create_message['uprn'],
                            f"999{context.field_action_create_message['caseRef']}")
    test_helper.assertEqual(context.field_action_create_message['estabUprn'],
                            "77469066363")  # original estabUprn should be retained
Esempio n. 27
0
def request_telephone_capture_qid_uac(context, address_level, address_type,
                                      country_code):
    context.first_case = context.case_created_events[0]['payload'][
        'collectionCase']
    context.fulfilment_requested_case_id = context.case_created_events[0][
        'payload']['collectionCase']['id']
    check_address_type_country_address_level(context.first_case,
                                             address_type,
                                             country_code,
                                             address_level=address_level)
    response = requests.get(
        f"{Config.CASEAPI_SERVICE}/cases/{context.first_case['id']}/qid")
    test_helper.assertEqual(response.status_code, 200)

    context.telephone_capture_qid_uac = response.json()
def check_individual_uac_print_requests(context, fulfilment_code,
                                        questionnaire_type):
    individual_case = requests.get(
        f'{Config.CASE_API_CASE_URL}{context.individual_case_id}').json()
    uac, qid = get_qid_and_uac_from_emitted_child_uac(context)
    test_helper.assertEqual(qid[:2], questionnaire_type,
                            "Incorrect questionnaire type")
    expected_csv_lines = [
        create_uac_print_materials_csv_line(individual_case, uac, qid,
                                            fulfilment_code)
    ]

    check_print_files_have_all_the_expected_data(context, expected_csv_lines,
                                                 fulfilment_code)
    check_manifest_files_created(context, fulfilment_code)
Esempio n. 29
0
def _test_uacs_updated_correct(context):
    case_ids = set(case['payload']['collectionCase']['id']
                   for case in context.case_created_events)
    test_helper.assertSetEqual(
        set(uac['payload']['uac']['caseId']
            for uac in context.uac_created_events), case_ids)
    welsh_uac_count = len(
        tuple(uac_updated_event
              for uac_updated_event in context.uac_created_events
              if uac_updated_event['payload']['uac']
              ['questionnaireId'].startswith('03')))
    non_welsh_uac_count = len(context.uac_created_events) - welsh_uac_count
    test_helper.assertEqual(non_welsh_uac_count,
                            len(context.case_created_events))

    test_helper.assertEqual(welsh_uac_count, len(context.welsh_cases))
Esempio n. 30
0
def test_uacs_correct(context):
    test_helper.assertEqual(len(context.messages_received),
                            len(context.expected_uacs_cases))

    for msg in context.uac_created_events:
        _validate_uac_message(msg)

        for index, case_created_event in enumerate(
                context.expected_uacs_cases):
            if (uac_message_matches_rh_message(case_created_event, msg) and
                (msg['payload']['uac']['questionnaireId'][:2]
                 == case_created_event['expected_questionnaire_type'])):
                del context.expected_uacs_cases[index]
                break
        else:
            test_helper.fail('Could not find UAC Updated event')