Ejemplo n.º 1
0
def test_imei_api_pairing_list(per_test_flask_app, per_test_postgres, logger,
                               mocked_statsd, tmpdir, request, mocked_config,
                               api_version):
    """Test IMEI API call after pairing list import."""
    dsn = per_test_postgres.dsn()
    db_config = DBConfig(ignore_env=True, **dsn)
    with create_db_connection(db_config) as conn, \
            create_db_connection(db_config, autocommit=True) as metadata_conn:
        with get_importer(
                GSMADataImporter, conn, metadata_conn, db_config, tmpdir,
                logger, mocked_statsd,
                GSMADataParams(
                    filename='gsma_dump_small_july_2016.txt')) as imp:
            imp.import_data()

        with get_importer(
                PairingListImporter, conn, metadata_conn, db_config, tmpdir,
                logger, mocked_statsd,
                PairListParams(content='imei,imsi\n'
                               '811111013136460,111018001111111\n'
                               '359000000000000,111015113222222\n'
                               '357756065985824,111015113333333')) as imp:
            imp.import_data()

    if api_version == 'v1':
        rv = per_test_flask_app.get(
            url_for('{0}.imei_api'.format(api_version), imei='21260934000003'))
        assert rv.status_code == 200
    else:  # api version 2.0
        rv = per_test_flask_app.get(
            url_for('{0}.imei_get_pairings_api'.format(api_version),
                    imei='21260934000003'))
        assert rv.status_code == 200
Ejemplo n.º 2
0
def test_prune(per_test_postgres, tmpdir, logger, mocked_statsd, db_user,
               mocked_config, monkeypatch):
    """Test prune works with the poweruser security role."""
    dsn = per_test_postgres.dsn()
    db_config = DBConfig(ignore_env=True, **dsn)
    with create_db_connection(db_config) as conn, create_db_connection(
            db_config, autocommit=True) as metadata_conn:
        with get_importer(
                OperatorDataImporter, conn, metadata_conn, db_config, tmpdir,
                logger, mocked_statsd,
                OperatorDataParams(
                    filename=
                    'testData1-operator-operator4-anonymized_20161101_20161130.csv',
                    operator='1',
                    extract=False,
                    perform_leading_zero_check=False,
                    mcc_mnc_pairs=[{
                        'mcc': '111',
                        'mnc': '04'
                    }],
                    perform_unclean_checks=False,
                    perform_file_daterange_check=False)) as imp:
            imp.import_data()
            conn.commit()

    runner = CliRunner()
    monkeypatch.setattr(mocked_config.db_config, 'user', db_user)
    result = runner.invoke(dirbs_prune_cli, ['triplets'],
                           obj={'APP_CONFIG': mocked_config})
    if db_user in ['dirbs_poweruser_login']:
        assert result.exit_code == 0
    else:
        assert result.exit_code != 0
Ejemplo n.º 3
0
def test_report(per_test_postgres, tmpdir, db_user, logger, mocked_statsd,
                mocked_config, monkeypatch):
    """Test catalog works with the security role created based on abstract role."""
    dsn = per_test_postgres.dsn()
    db_config = DBConfig(ignore_env=True, **dsn)
    with create_db_connection(db_config) as conn, create_db_connection(
            db_config, autocommit=True) as metadata_conn:
        with get_importer(
                OperatorDataImporter, conn, metadata_conn, db_config, tmpdir,
                logger, mocked_statsd,
                OperatorDataParams(
                    filename=
                    'testData1-operator-operator1-anonymized_20161101_20161130.csv',
                    operator='operator1',
                    perform_unclean_checks=False,
                    extract=False)) as imp:
            imp.import_data()

    runner = CliRunner()
    output_dir = str(tmpdir)
    monkeypatch.setattr(mocked_config.db_config, 'user', db_user)
    result = runner.invoke(dirbs_report_cli, [
        'standard', '--disable-retention-check', '--disable-data-check', '11',
        '2016', output_dir
    ],
                           obj={'APP_CONFIG': mocked_config})

    if db_user in ['dirbs_poweruser_login', 'dirbs_report_user']:
        assert result.exit_code == 0
    else:
        assert result.exit_code != 0
Ejemplo n.º 4
0
def test_imei_api_registration_list(per_test_flask_app, per_test_postgres,
                                    logger, mocked_statsd, tmpdir, request,
                                    mocked_config, api_version):
    """Test IMEI API call after registration list import."""
    dsn = per_test_postgres.dsn()
    db_config = DBConfig(ignore_env=True, **dsn)
    with create_db_connection(db_config) as conn, \
            create_db_connection(db_config, autocommit=True) as metadata_conn:
        with get_importer(
                GSMADataImporter, conn, metadata_conn, db_config, tmpdir,
                logger, mocked_statsd,
                GSMADataParams(
                    filename='gsma_dump_small_july_2016.txt')) as imp:
            imp.import_data()

        with get_importer(
                RegistrationListImporter, conn, metadata_conn, db_config,
                tmpdir, logger, mocked_statsd,
                RegistrationListParams(
                    content=
                    'APPROVED_IMEI,make,model,status,model_number,brand_name,'
                    'device_type,radio_interface,device_id\n'
                    '21260934000003,,,,,,,,1')) as imp:
            imp.import_data()

    if api_version == 'v1':
        rv = per_test_flask_app.get(
            url_for('{0}.imei_api'.format(api_version), imei='21260934000003'))
        assert rv.status_code == 200
    else:  # api version 2.0
        rv = per_test_flask_app.get(
            url_for('{0}.imei_get_api'.format(api_version),
                    imei='21260934000003'))
        assert rv.status_code == 200
Ejemplo n.º 5
0
def test_tac_api(per_test_flask_app, per_test_postgres, logger, mocked_statsd,
                 tmpdir, request, mocked_config, api_version):
    """Test TAC API call works with the security role created based on abstract role."""
    dsn = per_test_postgres.dsn()
    dsn['user'] = '******'
    db_config = DBConfig(ignore_env=True, **dsn)
    with create_db_connection(db_config) as conn, create_db_connection(
            db_config, autocommit=True) as metadata_conn:
        with get_importer(
                GSMADataImporter, conn, metadata_conn, db_config, tmpdir,
                logger, mocked_statsd,
                GSMADataParams(
                    filename='sample_gsma_import_list_anonymized.txt')) as imp:
            imp.import_data()

    current_user = request.node.callspec.params['per_test_flask_app']
    if current_user in ['dirbs_poweruser_login', 'dirbs_api_user']:
        rv = per_test_flask_app.get(
            url_for('{0}.tac_api'.format(api_version), tac='01234404'))
        assert rv.status_code == 200
        results = json.loads(rv.data.decode('utf-8'))
        assert results['gsma'] is not None
    else:
        with pytest.raises(DatabaseRoleCheckException):
            per_test_flask_app.get(
                url_for('{0}.tac_api'.format(api_version), tac='01234404'))
Ejemplo n.º 6
0
def test_classify(per_test_postgres, db_user, tmpdir, logger, mocked_statsd,
                  monkeypatch, mocked_config):
    """Test classify works with the security role created based on abstract role."""
    dsn = per_test_postgres.dsn()
    db_config = DBConfig(ignore_env=True, **dsn)
    with create_db_connection(db_config) as conn, create_db_connection(
            db_config, autocommit=True) as metadata_conn:
        with get_importer(
                OperatorDataImporter, conn, metadata_conn, db_config, tmpdir,
                logger, mocked_statsd,
                OperatorDataParams(
                    content='date,imei,imsi,msisdn\n'
                    '20110101,8888#888622222,123456789012345,123456789012345\n'
                    '20110101,88888888622222,123456789012345,123456789012345\n'
                    '20110101,8888888862222209,123456789012345,123456789012345\n'
                    '20110101,88888862222209**,123456789012345,123456789012345',
                    extract=False,
                    perform_unclean_checks=False,
                    perform_region_checks=False,
                    perform_home_network_check=False,
                    operator='operator1')) as imp:
            imp.import_data()

        with get_importer(
                GSMADataImporter, conn, metadata_conn, db_config, tmpdir,
                logger, mocked_statsd,
                GSMADataParams(
                    filename='gsma_not_found_anonymized.txt')) as imp:
            imp.import_data()

        with get_importer(
                RegistrationListImporter, conn, metadata_conn, db_config,
                tmpdir, logger, mocked_statsd,
                RegistrationListParams(
                    filename='sample_registration_list.csv')) as imp:
            imp.import_data()

    # Run dirbs-classify using db args from the temp postgres instance
    runner = CliRunner()
    monkeypatch.setattr(mocked_config.db_config, 'user', db_user)
    result = runner.invoke(dirbs_classify_cli, ['--no-safety-check'],
                           obj={'APP_CONFIG': mocked_config})

    if db_user in ['dirbs_poweruser_login', 'dirbs_classify_user']:
        assert result.exit_code == 0
    else:
        assert result.exit_code != 0
Ejemplo n.º 7
0
def test_listgen(per_test_postgres, tmpdir, logger, mocked_statsd, db_user,
                 mocked_config, monkeypatch, classification_data):
    """Test that the dirbs-listgen instance runs without an error."""
    dsn = per_test_postgres.dsn()
    db_config = DBConfig(ignore_env=True, **dsn)
    with create_db_connection(db_config) as conn, create_db_connection(
            db_config, autocommit=True) as metadata_conn:
        with get_importer(
                OperatorDataImporter, conn, metadata_conn, db_config, tmpdir,
                logger, mocked_statsd,
                OperatorDataParams(
                    content='date,imei,imsi,msisdn\n'
                    '20160203,811111013136460,111018001111111,223338000000\n'
                    '20160203,359000000000000,111015113222222,223355000000\n'
                    '20160203,357756065985824,111015113333333,223355111111',
                    cc=['22', '74'],
                    mcc_mnc_pairs=[{
                        'mcc': '111',
                        'mnc': '01'
                    }],
                    operator='operator1',
                    extract=False)) as imp:
            imp.import_data()

        with get_importer(
                PairingListImporter, conn, metadata_conn, db_config, tmpdir,
                logger, mocked_statsd,
                PairListParams(content='imei,imsi\n'
                               '811111013136460,111018001111111\n'
                               '359000000000000,111015113222222\n'
                               '357756065985824,111015113333333')) as imp:
            imp.import_data()

    # Now run listgen as requested user
    runner = CliRunner()
    monkeypatch.setattr(mocked_config.db_config, 'user', db_user)
    output_dir = str(tmpdir)
    result = runner.invoke(dirbs_listgen_cli, [output_dir],
                           obj={'APP_CONFIG': mocked_config})
    if db_user in ['dirbs_poweruser_login', 'dirbs_listgen_user']:
        assert result.exit_code == 0
    else:
        assert result.exit_code != 0
Ejemplo n.º 8
0
def test_imei_api(per_test_flask_app, per_test_postgres, logger, mocked_statsd,
                  tmpdir, request, mocked_config, api_version):
    """Test IMEI API call works with the security role created based on abstract role."""
    dsn = per_test_postgres.dsn()
    db_config = DBConfig(ignore_env=True, **dsn)
    with create_db_connection(db_config) as conn, create_db_connection(
            db_config, autocommit=True) as metadata_conn:
        with get_importer(
                OperatorDataImporter, conn, metadata_conn, db_config, tmpdir,
                logger, mocked_statsd,
                OperatorDataParams(
                    filename=
                    'testData1-operator-operator1-anonymized_20161101_20161130.csv',
                    operator='operator1',
                    perform_unclean_checks=False,
                    extract=False)) as imp:
            imp.import_data()

    current_user = request.node.callspec.params['per_test_flask_app']
    if current_user in ['dirbs_poweruser_login', 'dirbs_api_user']:
        rv = per_test_flask_app.get(
            url_for('{0}.imei_api'.format(api_version),
                    imei='388260336982806',
                    include_seen_with=1))
        assert rv.status_code == 200
        assert json.loads(rv.data.decode('utf-8'))['seen_with'] == \
            [{'imsi': '11101400135251', 'msisdn': '22300825684694'},
             {'imsi': '11101400135252', 'msisdn': '22300825684692'}]
        assert json.loads(rv.data.decode(
            'utf-8'))['realtime_checks']['ever_observed_on_network'] is True

    else:
        with pytest.raises(DatabaseRoleCheckException):
            per_test_flask_app.get(
                url_for('{0}.imei_api'.format(api_version),
                        imei='388260336982806',
                        include_seen_with=1))
Ejemplo n.º 9
0
            'Number of job_metadata entries must be a positive int digit')

    try:
        int_data_catalog_enties = int(data_catalog_enties)
    except ValueError:
        raise Exception(
            'Number of data_catalog entries must be a positive int digit')

    a = b = c = n = 0
    file_importer_map = {}
    map_of_occurrences = {'operator': a, 'gsma': b, 'stolen': c}

    while n < int(job_metadata_entries):
        n += 1
        importer_list = ['operator', 'gsma', 'stolen']
        i = random.choice(importer_list)
        map_of_occurrences[i] += 1
        file_importer_map.update(
            {'{0}_{1}_file.zip'.format(map_of_occurrences.get(i), i): i})

    key_map = {
        'database': '<db_name>',
        'user': '******',
        'host': '<host>',
        'port': '<port>'
    }

    db_config = DBConfig(ignore_env=False, **key_map)
    dummy_data_generator(create_db_connection(db_config),
                         int_data_catalog_enties, file_importer_map)