Ejemplo n.º 1
0
def test_historical_check_empty(barred_list_importer, logger, mocked_statsd,
                                db_conn, metadata_db_conn, mocked_config,
                                tmpdir):
    """Verify that empty file import fails after importing a non empty file."""
    expect_success(barred_list_importer, 20, db_conn, logger)
    with get_importer(
            BarredListImporter, db_conn, metadata_db_conn,
            mocked_config.db_config, tmpdir, logger, mocked_statsd,
            BarredListParams(
                filename='empty_barredlist_historical_check.csv')) as imp:
        expect_failure(imp, exc_message='Failed import size historic check')
Ejemplo n.º 2
0
def test_repeat_import(barred_list_importer, logger, mocked_statsd, db_conn,
                       metadata_db_conn, mocked_config, tmpdir):
    """Verify that valid barred list data can be successfully imported into the database.

    when repeating the import of the same file.
    """
    expect_success(barred_list_importer, 21, db_conn, logger)
    with get_importer(
            BarredListImporter, db_conn, metadata_db_conn,
            mocked_config.db_config, tmpdir, logger, mocked_statsd,
            BarredListParams(filename='sample_barred_list_v1.csv')) as imp:
        expect_success(imp, 21, db_conn, logger)
Ejemplo n.º 3
0
def test_historical_check_percent_fails(barred_list_importer, logger,
                                        mocked_statsd, db_conn, mocked_config,
                                        metadata_db_conn, tmpdir):
    """Verify that barred list import fails historical check."""
    expect_success(barred_list_importer, 20, db_conn, logger)
    with get_importer(
            BarredListImporter, db_conn, metadata_db_conn,
            mocked_config.db_config, tmpdir, logger, mocked_statsd,
            BarredListParams(
                filename='sample_barred_list_historicalcheck.csv',
                import_size_variation_percent=mocked_config.
                barred_threshold_config.import_size_variation_percent,
                import_size_variation_absolute=mocked_config.
                barred_threshold_config.import_size_variation_absolute)
    ) as imp:
        expect_failure(imp, exc_message='Failed import size historic check')
Ejemplo n.º 4
0
def test_malformed_imeis(barred_list_importer, logger, mocked_statsd, db_conn,
                         metadata_db_conn, mocked_config, tmpdir):
    """Verify that the barred list data file is accepted.

    And imported if the data contains IMEIs with #, and *.
    """
    expect_success(barred_list_importer, 20, db_conn, logger)
    # attempting to import stolen list file containing symbol not allowed '%'.
    with get_importer(
            BarredListImporter, db_conn, metadata_db_conn,
            mocked_config.db_config, tmpdir, logger, mocked_statsd,
            BarredListParams(
                filename='barred_list_hexpound_bad_symbol.csv')) as imp:
        expect_failure(imp,
                       exc_message='regex("^[0-9A-Fa-f\\\\*\\\\#]{1,16}$") '
                       'fails for line: 1, column: imei, value: '
                       '"62%222222222222"\\nFAIL')
Ejemplo n.º 5
0
def test_historical_check_percent_succeeds(barred_list_importer, logger,
                                           mocked_statsd, db_conn,
                                           mocked_config, metadata_db_conn,
                                           tmpdir):
    """Verify that a local barred data is successfully imported.

    After having imported two files where the second file has 80% size of the first one and the threshold value is 75.
    """
    expect_success(barred_list_importer, 100, db_conn, logger)
    with get_importer(
            BarredListImporter, db_conn, metadata_db_conn,
            mocked_config.db_config, tmpdir, logger, mocked_statsd,
            BarredListParams(
                filename=data_file_to_test(80,
                                           imei_custom_header='imei',
                                           imei_imsi=False),
                import_size_variation_percent=mocked_config.
                barred_threshold_config.import_size_variation_percent,
                import_size_variation_absolute=mocked_config.
                barred_threshold_config.import_size_variation_absolute)
    ) as imp:
        expect_success(imp, 80, db_conn, logger)
Ejemplo n.º 6
0
    # verify data in db
    with db_conn.cursor() as cursor:
        cursor.execute('SELECT imei_norm FROM barred_list ORDER BY imei_norm')
        result_list = [res.imei_norm for res in cursor]

    assert result.exit_code == 0
    assert result_list == [
        '10000110000006', '10000220000007', '10000330000008', '10000440000009',
        '10000550000000', '10000660000001'
    ]


@pytest.mark.parametrize(
    'barred_list_importer',
    [BarredListParams(filename='barred_list_missing_header.csv')],
    indirect=True)
def test_missing_header(barred_list_importer, logger, db_conn):
    """Verify that the barred list data is not imported if a header column is missing."""
    expect_failure(
        barred_list_importer,
        exc_message='Metadata header, cannot find the column headers - imei, '
        '642222222222222')


@pytest.mark.parametrize(
    'barred_list_importer',
    [BarredListParams(filename='sample_barred_list_normalize.csv')],
    indirect=True)
def test_matching_normalization(barred_list_importer, logger, db_conn):
    """Verify that IMEIs that normalize to the same value are successfully imported into the database."""