tests/_delta_helpers.py
def delta_add_check_and_disable_option_common(db_conn, tmpdir, mocked_config, logger, importer_name,
                                              historic_tbl_name):
    """Common code to verify delta add check and CLI option to disable check.

    1) Verify that import fails if the check is enabled and the record to add is already in db.
    2) Verify '--disable-delta-adds-check' CLI option and verify that, if disabled, the import succeeds.
    """
    imei_norm_one = '12345678901243'
    imei_norm_three = '32345678901234'
    imei_norm_pk = 'imei_norm'
    if importer_name == 'golden_list':
        imei_norm_one = imeis_md5_hashing_uuid(imei_norm_one, convert_to_uuid=True)
        imei_norm_three = imeis_md5_hashing_uuid(imei_norm_three, convert_to_uuid=True)
        imei_norm_pk = 'hashed_imei_norm'
    # populate historic_tbl
    imei_norm_to_insert_list = [imei_norm_one, imei_norm_three]
    # write into csv
    csv_imei_change_type_tuples = [('12345678901243', 'add')]
    # Test part 1)
    historic_table_insert_params_from_dict(db_conn, importer_name, imei_norm_to_insert_list)
    valid_zip_import_data_file_path = write_import_csv(tmpdir, importer_name, csv_imei_change_type_tuples)
    runner = CliRunner()
    result = runner.invoke(dirbs_import_cli, [importer_name, '--delta', valid_zip_import_data_file_path],
                           obj={'APP_CONFIG': mocked_config})
    assert result.exit_code == 1
    assert 'Failed add delta validation check. Cannot add item that is already in db. ' \
           'Failing rows: {imei_norm_pk}: {imei_norm}'.format(imei_norm_pk=imei_norm_pk,
                                                              imei_norm=imei_norm_one) \
           in logger_stream_contents(logger)
    # historic_table rows
    count, res = fetch_tbl_rows(historic_tbl_name, db_conn)
    # only 2 rows that were inserted manually at the beginning of the test
    assert count == 2
    # Test part 2)
    result = runner.invoke(dirbs_import_cli, [importer_name, '--delta', '--disable-delta-adds-check',
                                              valid_zip_import_data_file_path], obj={'APP_CONFIG': mocked_config})
    assert result.exit_code == 0
    # historic_table rows
    count, res = fetch_tbl_rows(historic_tbl_name, db_conn)
    # only 2 rows that were inserted manually at the beginning of the test
    assert count == 2
Common code to verify delta add check and CLI option to disable check.

    1) Verify that import fails if the check is enabled and the record to add is already in db.
    2) Verify '--disable-delta-adds-check' CLI option and verify that, if disabled, the import succeeds.
    
Common code to verify delta add check and CLI option to disable check.
1) Verify that import fails if the check is enabled and the record to add is already in db.
Common code to verify delta add check and CLI option to disable check . 1 ) Verify that import fails if the check is enabled and the record to add is already in db .
def delta_add_check_and_disable_option_common(db_conn, tmpdir, mocked_config, logger, importer_name,
                                              historic_tbl_name):
    imei_norm_one = '12345678901243'
    imei_norm_three = '32345678901234'
    imei_norm_pk = 'imei_norm'
    if importer_name == 'golden_list':
        imei_norm_one = imeis_md5_hashing_uuid(imei_norm_one, convert_to_uuid=True)
        imei_norm_three = imeis_md5_hashing_uuid(imei_norm_three, convert_to_uuid=True)
        imei_norm_pk = 'hashed_imei_norm'
    imei_norm_to_insert_list = [imei_norm_one, imei_norm_three]
    csv_imei_change_type_tuples = [('12345678901243', 'add')]
    historic_table_insert_params_from_dict(db_conn, importer_name, imei_norm_to_insert_list)
    valid_zip_import_data_file_path = write_import_csv(tmpdir, importer_name, csv_imei_change_type_tuples)
    runner = CliRunner()
    result = runner.invoke(dirbs_import_cli, [importer_name, '--delta', valid_zip_import_data_file_path],
                           obj={'APP_CONFIG': mocked_config})
    assert result.exit_code == 1
    assert 'Failed add delta validation check. Cannot add item that is already in db. ' \
           'Failing rows: {imei_norm_pk}: {imei_norm}'.format(imei_norm_pk=imei_norm_pk,
                                                              imei_norm=imei_norm_one) \
           in logger_stream_contents(logger)
    count, res = fetch_tbl_rows(historic_tbl_name, db_conn)
    assert count == 2
    result = runner.invoke(dirbs_import_cli, [importer_name, '--delta', '--disable-delta-adds-check',
                                              valid_zip_import_data_file_path], obj={'APP_CONFIG': mocked_config})
    assert result.exit_code == 0
    count, res = fetch_tbl_rows(historic_tbl_name, db_conn)
    assert count == 2
def delta_add_check_and_disable_option_common ( db_conn , tmpdir , mocked_config , logger , importer_name , historic_tbl_name ) : imei_norm_one = '12345678901243' imei_norm_three = '32345678901234' imei_norm_pk = 'imei_norm' if importer_name == 'golden_list' : imei_norm_one = imeis_md5_hashing_uuid ( imei_norm_one , convert_to_uuid = True ) imei_norm_three = imeis_md5_hashing_uuid ( imei_norm_three , convert_to_uuid = True ) imei_norm_pk = 'hashed_imei_norm' imei_norm_to_insert_list = [ imei_norm_one , imei_norm_three ] csv_imei_change_type_tuples = [ ( '12345678901243' , 'add' ) ] historic_table_insert_params_from_dict ( db_conn , importer_name , imei_norm_to_insert_list ) valid_zip_import_data_file_path = write_import_csv ( tmpdir , importer_name , csv_imei_change_type_tuples ) runner = CliRunner ( ) result = runner . invoke ( dirbs_import_cli , [ importer_name , '--delta' , valid_zip_import_data_file_path ] , obj = { 'APP_CONFIG' : mocked_config } ) assert result . exit_code == 1 assert 'Failed add delta validation check. Cannot add item that is already in db. ' 'Failing rows: {imei_norm_pk}: {imei_norm}' . format ( imei_norm_pk = imei_norm_pk , imei_norm = imei_norm_one ) in logger_stream_contents ( logger ) count , res = fetch_tbl_rows ( historic_tbl_name , db_conn ) assert count == 2 result = runner . invoke ( dirbs_import_cli , [ importer_name , '--delta' , '--disable-delta-adds-check' , valid_zip_import_data_file_path ] , obj = { 'APP_CONFIG' : mocked_config } ) assert result . exit_code == 0 count , res = fetch_tbl_rows ( historic_tbl_name , db_conn ) assert count == 2
Common code to verify delta add check and CLI option to disable check.
Common code to verify delta add check and CLI option to disable check .
"""Common code to verify delta add check and CLI option to disable check.

    1) Verify that import fails if the check is enabled and the record to add is already in db.
    2) Verify '--disable-delta-adds-check' CLI option and verify that, if disabled, the import succeeds.
    """ # populate historic_tbl # write into csv # Test part 1) # historic_table rows # only 2 rows that were inserted manually at the beginning of the test # Test part 2) # historic_table rows # only 2 rows that were inserted manually at the beginning of the test
db_conn
tmpdir
mocked_config
logger
importer_name
historic_tbl_name