def test_ICL1E_PPD1_1(sftp_client): # Given icl1e_messages, _ = build_test_messages(ICL_message_template, 1, 'ICL1E', 'P_IC_ICL1') send_action_messages(icl1e_messages) # When matched_manifest_file, matched_print_file = get_print_and_manifest_filenames( sftp_client, TestConfig.SFTP_PPO_DIRECTORY, 'P_IC_ICL1') # Then decrypted_print_file = get_and_check_print_file( sftp=sftp_client, remote_print_file_path=TestConfig.SFTP_PPO_DIRECTORY + matched_print_file, decryption_key_path=Path(__file__).parents[2].joinpath( 'dummy_keys', 'dummy_ppo_supplier_private_key.asc'), decryption_key_passphrase='test', expected= '0|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' ) get_and_check_manifest_file( sftp=sftp_client, remote_manifest_path=TestConfig.SFTP_PPO_DIRECTORY + matched_manifest_file, expected_values={ 'description': 'Initial contact pack for English households', 'dataset': 'PPD1.1' }, decrypted_print_file=decrypted_print_file)
def test_example_print_file(sftp_client): # Given test_messages, _ = build_test_messages(10, supplier, pack_code) send_test_messages(test_messages) # When matched_manifest_file, matched_print_file = get_print_and_manifest_filenames( sftp_client, get_supplier_sftp_directory(supplier), pack_code) # Then decrypted_print_file = get_and_check_print_file( sftp=sftp_client, remote_print_file_path=get_supplier_sftp_directory(supplier) + matched_print_file, decryption_key_path=Path(__file__).parents[2].joinpath( 'dummy_keys', 'dummy-key-supplier-a-private.asc'), decryption_key_passphrase='test', expected='\n'.join(message['row'] for message in test_messages) + '\n') get_and_check_manifest_file( sftp=sftp_client, remote_manifest_path=get_supplier_sftp_directory(supplier) + matched_manifest_file, expected_values={ 'packCode': pack_code, 'supplier': supplier, }, decrypted_print_file=decrypted_print_file)
def test_P_OR_H2W_QM3_4(sftp_client): # Given messages, _ = build_test_messages(P_OR_message_template, 3, 'P_OR_HX', 'P_OR_H2W') send_action_messages(messages) # When matched_manifest_file, matched_print_file = get_print_and_manifest_filenames( sftp_client, TestConfig.SFTP_QM_DIRECTORY, 'P_OR_H2W') # Then decrypted_print_file = get_and_check_print_file( sftp=sftp_client, remote_print_file_path=TestConfig.SFTP_QM_DIRECTORY + matched_print_file, decryption_key_path=Path(__file__).parents[2].joinpath( 'dummy_keys', 'dummy_qm_supplier_private_key.asc'), decryption_key_passphrase='supplier', expected= ('0|english_qid||||Mr|Test|McTest|123 Fake Street|Duffryn||Newport|NPXXXX|P_OR_H2W||\n' '1|english_qid||||Mr|Test|McTest|123 Fake Street|Duffryn||Newport|NPXXXX|P_OR_H2W||\n' '2|english_qid||||Mr|Test|McTest|123 Fake Street|Duffryn||Newport|NPXXXX|P_OR_H2W||\n' )) get_and_check_manifest_file( sftp=sftp_client, remote_manifest_path=TestConfig.SFTP_QM_DIRECTORY + matched_manifest_file, expected_values={ 'description': 'Household Questionnaire for Wales (in Welsh)', 'dataset': 'QM3.4' }, decrypted_print_file=decrypted_print_file)
def test_ICHHQW_QM3_2(sftp_client): # Given ichhqw_messages, _ = build_test_messages( print_questionnaire_message_template, 3, 'ICHHQW', 'P_IC_H2') send_action_messages(ichhqw_messages) # When matched_manifest_file, matched_print_file = get_print_and_manifest_filenames( sftp_client, TestConfig.SFTP_QM_DIRECTORY, 'P_IC_H2') # Then decrypted_print_file = get_and_check_print_file( sftp=sftp_client, remote_print_file_path=TestConfig.SFTP_QM_DIRECTORY + matched_print_file, decryption_key_path=Path(__file__).parents[2].joinpath( 'dummy_keys', 'dummy_qm_supplier_private_key.asc'), decryption_key_passphrase='supplier', expected=('0|english_qid|1|welsh_qid|test_qm_coordinator_id|' '|||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_H2||\n' '2|english_qid|3|welsh_qid|test_qm_coordinator_id|' '|||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_H2||\n' '4|english_qid|5|welsh_qid|test_qm_coordinator_id|' '|||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_H2||\n')) get_and_check_manifest_file( sftp=sftp_client, remote_manifest_path=TestConfig.SFTP_QM_DIRECTORY + matched_manifest_file, expected_values={ 'description': 'Household Questionnaire for Wales', 'dataset': 'QM3.2' }, decrypted_print_file=decrypted_print_file)
def test_P_LP_HL1_PPD1_3(sftp_client): # Given messages, _ = build_test_messages(PPD1_3_message_template, 1, 'P_LP_HLX', 'P_LP_HL1', uac=False) send_action_messages(messages) # When matched_manifest_file, matched_print_file = get_print_and_manifest_filenames( sftp_client, TestConfig.SFTP_PPO_DIRECTORY, 'P_LP_HL1') # Then decrypted_print_file = get_and_check_print_file( sftp=sftp_client, remote_print_file_path=TestConfig.SFTP_PPO_DIRECTORY + matched_print_file, decryption_key_path=Path(__file__).parents[2].joinpath( 'dummy_keys', 'dummy_ppo_supplier_private_key.asc'), decryption_key_passphrase='test', expected= '|test_caseref|Mr|Test|McTest|123 Fake Street|Duffryn||Newport|NPXXXX|P_LP_HL1||||\n' ) get_and_check_manifest_file( sftp=sftp_client, remote_manifest_path=TestConfig.SFTP_PPO_DIRECTORY + matched_manifest_file, expected_values={ 'description': 'Household Questionnaire (Large Print) for England', 'dataset': 'PPD1.3' }, decrypted_print_file=decrypted_print_file)
def test_CE1_IC01_PPD1_7(sftp_client): # Given ce1_ic01_messages, _ = build_test_messages(ICL_message_template, 1, 'CE1_IC01', 'D_CE1A_ICLCR1', ce=True) send_action_messages(ce1_ic01_messages) # When matched_manifest_file, matched_print_file = get_print_and_manifest_filenames( sftp_client, TestConfig.SFTP_PPO_DIRECTORY, 'D_CE1A_ICLCR1') # Then decrypted_print_file = get_and_check_print_file( sftp=sftp_client, remote_print_file_path=TestConfig.SFTP_PPO_DIRECTORY + matched_print_file, decryption_key_path=Path(__file__).parents[2].joinpath( 'dummy_keys', 'dummy_ppo_supplier_private_key.asc'), decryption_key_passphrase='test', expected= '0|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|D_CE1A_ICLCR1|english_qid|ONS' '|ppo_field_coordinator_id|dummy_field_officer_id\n') get_and_check_manifest_file( sftp=sftp_client, remote_manifest_path=TestConfig.SFTP_PPO_DIRECTORY + matched_manifest_file, expected_values={ 'description': 'CE1 Packs (Hand Delivery) Addressed England', 'dataset': 'PPD1.7' }, decrypted_print_file=decrypted_print_file)
def test_P_RL_1RL1A_PPD1_2(sftp_client): # Given messages, _ = build_test_messages(reminder_message_template, 1, 'P_RL_1RL1A', 'P_RL_1RL1A') send_action_messages(messages) # When matched_manifest_file, matched_print_file = get_print_and_manifest_filenames( sftp_client, TestConfig.SFTP_PPO_DIRECTORY, 'P_RL_1RL1A') # Then decrypted_print_file = get_and_check_print_file( sftp=sftp_client, remote_print_file_path=TestConfig.SFTP_PPO_DIRECTORY + matched_print_file, decryption_key_path=Path(__file__).parents[2].joinpath( 'dummy_keys', 'dummy_ppo_supplier_private_key.asc'), decryption_key_passphrase='test', expected= '0|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_RL_1RL1A||||\n' ) get_and_check_manifest_file( sftp=sftp_client, remote_manifest_path=TestConfig.SFTP_PPO_DIRECTORY + matched_manifest_file, expected_values={ 'description': 'RU1 England- First reminder going to those who have launched EQ', 'dataset': 'PPD1.2' }, decrypted_print_file=decrypted_print_file)
def test_ICL1E_split_files(sftp_client): # Given icl1e_messages, _ = build_test_messages(ICL_message_template, 20, 'ICL1E', 'P_IC_ICL1') send_action_messages(icl1e_messages) # When matched_manifest_files, matched_print_files = get_multiple_print_and_manifest_filenames( sftp_client, TestConfig.SFTP_PPO_DIRECTORY, 'P_IC_ICL1') # Then get_and_check_multiple_manifest_files( sftp=sftp_client, remote_manifest_directory=TestConfig.SFTP_PPO_DIRECTORY, manifest_files=matched_manifest_files, expected_values={ 'description': 'Initial contact pack for English households', 'dataset': 'PPD1.1' }) get_and_check_multiple_print_files( sftp=sftp_client, remote_print_file_directory=TestConfig.SFTP_PPO_DIRECTORY, print_files=matched_print_files, decryption_key_path=Path(__file__).parents[2].joinpath( 'dummy_keys', 'dummy_ppo_supplier_private_key.asc'), decryption_key_passphrase='test', expected= ('0|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '1|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '2|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '3|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '4|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '5|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '6|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '7|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '8|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '9|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '10|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '11|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '12|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '13|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '14|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '15|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '16|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '17|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '18|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '19|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '20|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' ))
def test_icl1e_with_duplicate_uacs_is_quarantined(): # Given messages, batch_id = build_test_messages(ICL_message_template, 3, 'ICL1E', 'P_IC_ICL1') messages[0]['uac'] = 'test_duplicate' messages[2]['uac'] = 'test_duplicate' send_action_messages(messages) expected_quarantined_file = QUARANTINED_FILES_DIRECTORY.joinpath(f'ICL1E.P_IC_ICL1.{batch_id}.3') # When wait_for_quarantined_file(expected_quarantined_file) # Then assert expected_quarantined_file.read_text() == ( 'test_duplicate|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' '1|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' 'test_duplicate|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n')
def test_file_with_duplicate_rows_is_quarantined(): # Given quantity = 3 messages, batch_id = build_test_messages(quantity, supplier, pack_code) # Overwrite one of the test messages to be a duplicate messages[2] = messages[0] expected_quarantined_file = '\n'.join(message['row'] for message in messages) + '\n' # When send_test_messages(messages) # Then actual_quarantined_file = QUARANTINED_FILES_DIRECTORY.joinpath(f'{supplier}.{pack_code}.{batch_id}.{quantity}') wait_for_quarantined_file(actual_quarantined_file) assert actual_quarantined_file.read_text() == expected_quarantined_file
def test_our_decryption_key(sftp_client): # Given test_messages, _ = build_test_messages(1, supplier, pack_code) send_test_messages(test_messages) # When matched_manifest_file, matched_print_file = get_print_and_manifest_filenames( sftp_client, get_supplier_sftp_directory(supplier), pack_code) # Then get_and_check_print_file( sftp=sftp_client, remote_print_file_path=get_supplier_sftp_directory(supplier) + matched_print_file, decryption_key_path=Path(__file__).parents[2].joinpath( 'dummy_keys', 'dummy-key-ssdc-rm-private.asc'), decryption_key_passphrase='test', expected=test_messages[0]['row'] + '\n')
def test_ichhqw_with_duplicate_uacs_is_quarantined(): # Given messages, batch_id = build_test_messages(print_questionnaire_message_template, 3, 'ICHHQW', 'P_IC_H2') messages[0]['uac'] = 'test_duplicate' messages[2]['uacWales'] = 'test_duplicate' send_action_messages(messages) expected_quarantined_file = QUARANTINED_FILES_DIRECTORY.joinpath(f'ICHHQW.P_IC_H2.{batch_id}.3') # When wait_for_quarantined_file(expected_quarantined_file) # Then assert expected_quarantined_file.read_text() == ( 'test_duplicate|english_qid|1|welsh_qid|test_qm_coordinator_id|' '|||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_H2||\n' '2|english_qid|3|welsh_qid|test_qm_coordinator_id|' '|||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_H2||\n' '4|english_qid|test_duplicate|welsh_qid|test_qm_coordinator_id|' '|||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_H2||\n')
def test_our_decryption_key(sftp_client): # Given icl1e_messages, _ = build_test_messages(ICL_message_template, 1, 'ICL1E', 'P_IC_ICL1') send_action_messages(icl1e_messages) # When matched_manifest_file, matched_print_file = get_print_and_manifest_filenames( sftp_client, TestConfig.SFTP_PPO_DIRECTORY, 'P_IC_ICL1') # Then get_and_check_print_file( sftp=sftp_client, remote_print_file_path=TestConfig.SFTP_PPO_DIRECTORY + matched_print_file, decryption_key_path=Path(__file__).parents[2].joinpath( 'dummy_keys', 'our_dummy_private.asc'), decryption_key_passphrase='test', expected= '0|test_caseref||||123 Fake Street|Duffryn||Newport|NPXXXX|P_IC_ICL1||||\n' )
def test_P_QU_H2_QM3_3(sftp_client): # Given messages, _ = build_test_messages(print_questionnaire_message_template, 3, ActionType.P_QU_H2.value, PackCode.P_QU_H2.value) send_action_messages(messages) # When matched_manifest_file, matched_print_file = get_print_and_manifest_filenames( sftp_client, TestConfig.SFTP_QM_DIRECTORY, 'P_QU_H2') # Then decrypted_print_file = get_and_check_print_file( sftp=sftp_client, remote_print_file_path=TestConfig.SFTP_QM_DIRECTORY + matched_print_file, decryption_key_path=Path(__file__).parents[2].joinpath( 'dummy_keys', 'dummy_qm_supplier_private_key.asc'), decryption_key_passphrase='supplier', expected=('0|english_qid|1|welsh_qid|test_qm_coordinator_id|' '|||123 Fake Street|Duffryn||Newport|NPXXXX|P_QU_H2||\n' '2|english_qid|3|welsh_qid|test_qm_coordinator_id|' '|||123 Fake Street|Duffryn||Newport|NPXXXX|P_QU_H2||\n' '4|english_qid|5|welsh_qid|test_qm_coordinator_id|' '|||123 Fake Street|Duffryn||Newport|NPXXXX|P_QU_H2||\n')) get_and_check_manifest_file( sftp=sftp_client, remote_manifest_path=TestConfig.SFTP_QM_DIRECTORY + matched_manifest_file, expected_values={ 'description': 'RP1 - Wales Paper questionnaire going to HtC willingness 4&5', 'dataset': 'QM3.3' }, decrypted_print_file=decrypted_print_file)