コード例 #1
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 = []
コード例 #2
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'])
コード例 #3
0
def _check_actual_file_contents_sorted_by_production_code(
        unsorted_actual_content_list, pack_code):
    # If this was split over multiple files it could fail, not expected with current testing
    # produce a list of split_csv rows to sort
    split_csv_rows = [
        csvrow.split("|") for csvrow in unsorted_actual_content_list
    ]

    # If called with an invalid pack code the test will fail, this is expected behaviour
    sorted_list = []

    # This will sort a list of lists based on template ICL or QM
    # in both cases we're sorting by field_officer_id and org_name
    if pack_code in ICL_PACKCODES_WHICH_ARE_SORTED:
        sorted_list = sorted(split_csv_rows,
                             key=lambda row:
                             (row[ICL_TEMPLATE_FIELD_OFFICER_COLUMN], row[
                                 ICL_TEMPLATE_ORGANISATION_COLUMN]))
    elif pack_code in QM_PACKCODES_WHICH_ARE_SORTED:
        sorted_list = sorted(split_csv_rows,
                             key=lambda row:
                             (row[QM_TEMPLATE_FIELD_OFFICER_COLUMN], row[
                                 QM_TEMPLATE_ORGANISATION_COLUMN]))

    # Turn back to a list of expected_csv rows
    expected_csv_rows = ['|'.join(row) for row in sorted_list]

    test_helper.assertEquals(unsorted_actual_content_list, expected_csv_rows,
                             'Sorted file contents did not match expected')
コード例 #4
0
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}")
def compare_sftp_with_gcp_files(context, bucket, filename):
    blob = bucket.get_blob(filename)
    actual_file_content = blob.download_as_string().decode("utf-8")

    with SftpUtility() as sftp_utility:
        file_path = f'{PACK_CODE_TO_SFTP_DIRECTORY[context.expected_pack_code]}/{filename}'
        expected_file_content = sftp_utility.get_file_contents_as_string(file_path)

    test_helper.assertEquals(actual_file_content, expected_file_content,
                             f'file contents {filename} did not match gcp file contents')
コード例 #6
0
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'])
コード例 #7
0
def check_receipt_to_field_msg(context, action_instruction_type):
    if action_instruction_type == 'NONE':
        check_no_msgs_sent_to_queue(context, Config.RABBITMQ_OUTBOUND_FIELD_QUEUE, functools.partial(
            store_all_msgs_in_context, context=context,
            expected_msg_count=0), timeout=1)
        return

    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.receipting_case['id'])
    test_helper.assertEquals(msg_to_field['actionInstruction'], action_instruction_type)
    test_helper.assertEqual(msg_to_field['surveyName'], context.receipting_case['survey'])
コード例 #8
0
def _field_work_receipt_callback(ch, method, _properties, body, context):
    action_instruction = json.loads(body)

    if not action_instruction['actionInstruction'] == 'UPDATE':
        ch.basic_nack(delivery_tag=method.delivery_tag)
        test_helper.fail(
            f'Unexpected message on {Config.RABBITMQ_OUTBOUND_FIELD_QUEUE} case queue. '
            f'Got "{action_instruction["actionInstruction"]}", wanted "UPDATE"'
        )

    context.addressType = action_instruction['addressType']
    context.fwmt_emitted_case_id = action_instruction['caseId']
    context.fwmt_emitted_undelivered_flag = action_instruction[
        'undeliveredAsAddress']

    test_helper.assertEquals(context.first_case['address']['uprn'],
                             action_instruction['uprn'], "uprn")
    test_helper.assertEquals(context.first_case['address']['estabUprn'],
                             action_instruction['estabUprn'], "estab Uprn")

    ch.basic_ack(delivery_tag=method.delivery_tag)
    ch.stop_consuming()
コード例 #9
0
def _validate_print_file_content(context, sftp_utility, start_of_test,
                                 expected_csv_lines, pack_code):
    logger.debug('Checking for files on SFTP server')

    context.expected_print_files = sftp_utility.get_all_files_after_time(
        start_of_test, pack_code, ".csv.gpg")

    actual_content_list = sftp_utility.get_files_content_as_list(
        context.expected_print_files, pack_code)
    if not actual_content_list:
        raise FileNotFoundError

    unsorted_actual_content_list = copy.deepcopy(actual_content_list)
    actual_content_list.sort()
    expected_csv_lines.sort()

    test_helper.assertEquals(actual_content_list, expected_csv_lines,
                             'Print file contents did not match expected')

    if pack_code in ICL_PACKCODES_WHICH_ARE_SORTED or pack_code in QM_PACKCODES_WHICH_ARE_SORTED:
        _check_actual_file_contents_sorted_by_production_code(
            unsorted_actual_content_list, pack_code)
                            action_instruction['latitude'])
    test_helper.assertEqual(float(case['address']['longitude']),
                            action_instruction['longitude'])
    test_helper.assertEqual(case['address']['postcode'],
                            action_instruction['postcode'])
    test_helper.assertEqual('CENSUS', action_instruction['surveyName'])
    test_helper.assertEqual(case['address']['estabType'],
                            action_instruction['estabType'])
    test_helper.assertEquals(case['ceExpectedCapacity'],
                             int(action_instruction['ceExpectedCapacity']))
    test_helper.assertEquals(case['ceActualResponses'],
                             int(action_instruction['ceActualResponses']))
    test_helper.assertEquals(case['handDelivery'],
                             action_instruction['handDeliver'])
    test_helper.assertEquals(case['caseRef'], action_instruction['caseRef'])
    test_helper.assertEquals(len(action_instruction['caseRef']), 10)
    test_helper.assertEquals(case['address']['uprn'],
                             action_instruction['uprn'])
    test_helper.assertEquals(case['address']['estabUprn'],
                             action_instruction['estabUprn'])
    test_helper.assertTrue(luhn.verify(action_instruction['caseRef']))


def field_work_cancel_callback(ch, method, _properties, body, context):
    action_cancel = json.loads(body)

    if not action_cancel['actionInstruction'] == 'CANCEL':
        ch.basic_nack(delivery_tag=method.delivery_tag)
        test_helper.fail(
            f'Unexpected message on {Config.RABBITMQ_OUTBOUND_FIELD_QUEUE} case queue. '
            f'Got "{action_cancel["actionInstruction"]}", wanted "CANCEL"')
コード例 #11
0
def check_uac_updated_msg_sets_receipted_qid_to_unactive(context):
    uac = _get_emitted_uac(context)

    test_helper.assertEqual(uac['caseId'], context.receipting_case['id'])
    test_helper.assertEquals(uac['questionnaireId'], context.qid_to_receipt)
    test_helper.assertFalse(uac['active'])