tests/_delta_helpers.py
def full_list_import_common(tmpdir, db_conn, mocked_config, importer_name, historic_tbl_name, delta_import=False):
    """Common code to test full list import.

    Import '52345678901234', '32345678901234' in db, with start_date '20160420' and end_date null.
    Import a full list containing '12345678901234', '22345678901234', '32345678901234'.
    1) Verify that 52345678901234 is removed(set end_date to not job date) because is only in db.
    2) Verify that 32345678901234 is ignored and remains the same (start_date '20160420') because is in both
    db and list.
    3) Verify that 12345678901234 and 22345678901234 are added with start date different from '20160420'
    and end date null because are in current list and not in db.
    """
    imei_one = '12345678901234'
    imei_two = '22345678901234'
    imei_three = '32345678901234'
    imei_five = '52345678901234'
    imei_norm_pk_name = 'imei_norm'
    if importer_name == 'golden_list':
        imei_one = imeis_md5_hashing_uuid(imei_one, convert_to_uuid=True)
        imei_two = imeis_md5_hashing_uuid(imei_two, convert_to_uuid=True)
        imei_three = imeis_md5_hashing_uuid(imei_three, convert_to_uuid=True)
        imei_five = imeis_md5_hashing_uuid(imei_five, convert_to_uuid=True)
        imei_norm_pk_name = 'hashed_imei_norm'

    # populate historic_tbl
    imei_norm_to_insert_list = [imei_five,
                                imei_three]
    # write into csv
    csv_imei_change_type_tuples = [('12345678901234', None), ('22345678901234', None),
                                   ('32345678901234', None)]
    # populate historic table
    historic_table_insert_params_from_dict(db_conn, importer_name, imei_norm_to_insert_list)
    # write csv input file
    valid_zip_import_data_file_path = write_import_csv(tmpdir, importer_name, csv_imei_change_type_tuples,
                                                       delta_import=delta_import)
    runner = CliRunner()
    result = runner.invoke(dirbs_import_cli, [importer_name, 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 == 4
    expected_output = {imei_one,
                       imei_two,
                       imei_three,
                       imei_five}
    imei_norm_set = {getattr(r, imei_norm_pk_name) for r in res}
    assert imei_norm_set == expected_output
    date_time_before_import = datetime(2016, 4, 20)
    # Test part 1
    assert all([(r.end_date is not None) for r in res if getattr(r, imei_norm_pk_name) in imei_five])
    # Test part 2 and 3
    assert all([(r.end_date is None) for r in res if getattr(r, imei_norm_pk_name) in (imei_one, imei_two,
                                                                                       imei_three)])
    assert all([(r.start_date != date_time_before_import) for r in res if getattr(r, imei_norm_pk_name)
                in (imei_one, imei_two)])
    assert all([(r.start_date == date_time_before_import) for r in res if getattr(r, imei_norm_pk_name)
                not in (imei_one, imei_two)])
Common code to test full list import.

    Import '52345678901234', '32345678901234' in db, with start_date '20160420' and end_date null.
    Import a full list containing '12345678901234', '22345678901234', '32345678901234'.
    1) Verify that 52345678901234 is removed(set end_date to not job date) because is only in db.
    2) Verify that 32345678901234 is ignored and remains the same (start_date '20160420') because is in both
    db and list.
    3) Verify that 12345678901234 and 22345678901234 are added with start date different from '20160420'
    and end date null because are in current list and not in db.
    
Common code to test full list import.
Common code to test full list import .
def full_list_import_common(tmpdir, db_conn, mocked_config, importer_name, historic_tbl_name, delta_import=False):
    imei_one = '12345678901234'
    imei_two = '22345678901234'
    imei_three = '32345678901234'
    imei_five = '52345678901234'
    imei_norm_pk_name = 'imei_norm'
    if importer_name == 'golden_list':
        imei_one = imeis_md5_hashing_uuid(imei_one, convert_to_uuid=True)
        imei_two = imeis_md5_hashing_uuid(imei_two, convert_to_uuid=True)
        imei_three = imeis_md5_hashing_uuid(imei_three, convert_to_uuid=True)
        imei_five = imeis_md5_hashing_uuid(imei_five, convert_to_uuid=True)
        imei_norm_pk_name = 'hashed_imei_norm'
    imei_norm_to_insert_list = [imei_five,
                                imei_three]
    csv_imei_change_type_tuples = [('12345678901234', None), ('22345678901234', None),
                                   ('32345678901234', None)]
    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,
                                                       delta_import=delta_import)
    runner = CliRunner()
    result = runner.invoke(dirbs_import_cli, [importer_name, 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 == 4
    expected_output = {imei_one,
                       imei_two,
                       imei_three,
                       imei_five}
    imei_norm_set = {getattr(r, imei_norm_pk_name) for r in res}
    assert imei_norm_set == expected_output
    date_time_before_import = datetime(2016, 4, 20)
    assert all([(r.end_date is not None) for r in res if getattr(r, imei_norm_pk_name) in imei_five])
    assert all([(r.end_date is None) for r in res if getattr(r, imei_norm_pk_name) in (imei_one, imei_two,
                                                                                       imei_three)])
    assert all([(r.start_date != date_time_before_import) for r in res if getattr(r, imei_norm_pk_name)
                in (imei_one, imei_two)])
    assert all([(r.start_date == date_time_before_import) for r in res if getattr(r, imei_norm_pk_name)
                not in (imei_one, imei_two)])
def full_list_import_common ( tmpdir , db_conn , mocked_config , importer_name , historic_tbl_name , delta_import = False ) : imei_one = '12345678901234' imei_two = '22345678901234' imei_three = '32345678901234' imei_five = '52345678901234' imei_norm_pk_name = 'imei_norm' if importer_name == 'golden_list' : imei_one = imeis_md5_hashing_uuid ( imei_one , convert_to_uuid = True ) imei_two = imeis_md5_hashing_uuid ( imei_two , convert_to_uuid = True ) imei_three = imeis_md5_hashing_uuid ( imei_three , convert_to_uuid = True ) imei_five = imeis_md5_hashing_uuid ( imei_five , convert_to_uuid = True ) imei_norm_pk_name = 'hashed_imei_norm' imei_norm_to_insert_list = [ imei_five , imei_three ] csv_imei_change_type_tuples = [ ( '12345678901234' , None ) , ( '22345678901234' , None ) , ( '32345678901234' , None ) ] 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 , delta_import = delta_import ) runner = CliRunner ( ) result = runner . invoke ( dirbs_import_cli , [ importer_name , 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 == 4 expected_output = { imei_one , imei_two , imei_three , imei_five } imei_norm_set = { getattr ( r , imei_norm_pk_name ) for r in res } assert imei_norm_set == expected_output date_time_before_import = datetime ( 2016 , 4 , 20 ) assert all ( [ ( r . end_date is not None ) for r in res if getattr ( r , imei_norm_pk_name ) in imei_five ] ) assert all ( [ ( r . end_date is None ) for r in res if getattr ( r , imei_norm_pk_name ) in ( imei_one , imei_two , imei_three ) ] ) assert all ( [ ( r . start_date != date_time_before_import ) for r in res if getattr ( r , imei_norm_pk_name ) in ( imei_one , imei_two ) ] ) assert all ( [ ( r . start_date == date_time_before_import ) for r in res if getattr ( r , imei_norm_pk_name ) not in ( imei_one , imei_two ) ] )
Common code to test full list import.
Common code to test full list import .
"""Common code to test full list import.

    Import '52345678901234', '32345678901234' in db, with start_date '20160420' and end_date null.
    Import a full list containing '12345678901234', '22345678901234', '32345678901234'.
    1) Verify that 52345678901234 is removed(set end_date to not job date) because is only in db.
    2) Verify that 32345678901234 is ignored and remains the same (start_date '20160420') because is in both
    db and list.
    3) Verify that 12345678901234 and 22345678901234 are added with start date different from '20160420'
    and end date null because are in current list and not in db.
    """ # populate historic_tbl # write into csv # populate historic table # write csv input file # Test part 1 # Test part 2 and 3
tmpdir
db_conn
mocked_config
importer_name
historic_tbl_name
delta_import