def test_get_table_data_paginated(app_with_hawk_user, app_with_mock_cache):
    app_with_hawk_user.config['app']['pagination_size'] = 10

    for i in range(15):
        SPIREFootnoteFactory(text='foo bar', status='CURRENT')

    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(
        client, '/api/v1/table-data/spire/footnotes?orientation=records'
    )
    expected_next_url = (
        'http://localhost/api/v1/table-data/spire/footnotes?orientation=records&next-id=11'
    )

    assert response.status_code == 200
    assert response.json == {
        'results': [{'id': i, 'text': 'foo bar', 'status': 'CURRENT'} for i in range(1, 11)],
        'next': expected_next_url,
    }

    # Go to next page
    response = make_hawk_auth_request(client, response.json['next'].replace('http://localhost', ''))
    assert response.status_code == 200
    assert response.json == {
        'results': [{'id': i, 'text': 'foo bar', 'status': 'CURRENT'} for i in range(11, 16)],
        'next': None,
    }
예제 #2
0
def test_lower_case_and_whitespace_dit_reference_postcode(
        add_dit_reference_postcodes, app_with_hawk_user, app_with_mock_cache):
    postcodes = [
        {
            'postcode': 'AB10 1AA',
            'local_authority_district_code': 'asdf'
        },
        {
            'postcode': 'ZZ10 1ZZ',
            'local_authority_district_code': 'zzzz'
        },
    ]
    url = '/api/v1/get-dit-reference-postcode/?postcode=AB101AA'
    add_dit_reference_postcodes(postcodes)
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client, url)
    assert response.status_code == 200
    assert len(response.json['values']) == 1
    assert response.json['values'][0][:2] == ['AB10 1AA', 'asdf']

    url = '/api/v1/get-dit-reference-postcode/?postcode=zz10%201zz'
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client, url)
    assert response.status_code == 200
    assert len(response.json['values']) == 1
    assert response.json['values'][0][:2] == ['ZZ10 1ZZ', 'zzzz']

    url = '/api/v1/get-dit-reference-postcode/?postcode=zz10%201zz%20%20'
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client, url)
    assert response.status_code == 200
    assert len(response.json['values']) == 1
    assert response.json['values'][0][:2] == ['ZZ10 1ZZ', 'zzzz']
예제 #3
0
def test_get_dit_reference_postcode_when_no_param_specified(
        app_with_hawk_user, app_with_mock_cache):
    url = '/api/v1/get-dit-reference-postcode/'
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client, url)
    assert response.status_code == 400
    assert response.json['error'] == 'No postcode specified'
예제 #4
0
def test_get_dit_reference_postcode_when_no_data(app_with_hawk_user,
                                                 app_with_mock_cache):
    url = '/api/v1/get-dit-reference-postcode/?postcode=AB10%201AA'
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client, url)
    assert response.status_code == 200
    assert response.json['values'] == []
예제 #5
0
def test_get_dit_reference_postcodes_when_next_id_specified(
        app_with_hawk_user, app_with_mock_cache, add_dit_reference_postcodes):
    app_with_hawk_user.config['app']['pagination_size'] = 1
    postcodes = [
        {
            'postcode': 'AB10 1AA',
            'local_authority_district_code': 'asdf'
        },
        {
            'postcode': 'ZZ10 1ZZ',
            'local_authority_district_code': 'zzzz'
        },
    ]

    add_dit_reference_postcodes(postcodes)
    client = app_with_hawk_user.test_client()

    expected_values = ['ZZ10 1ZZ', 'zzzz']

    response = make_hawk_auth_request(
        client, '/api/v1/get-dit-reference-postcodes/?next-id=2')
    assert response.status_code == 200
    assert response.json['next'] is None
    assert len(response.json['values']) == 1
    assert response.json['values'][0][:2] == expected_values
예제 #6
0
def test_get_world_bank_raw_tariffs_empty_dataset(app_with_hawk_user, app_with_mock_cache):
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(
        client, '/api/v1/get-world-bank-tariffs/raw/?orientation=records'
    )

    assert response.status_code == 200
    assert response.json == {'next': None, 'results': []}
예제 #7
0
def test_get_dit_reference_postcodes_when_no_data(app_with_hawk_user,
                                                  app_with_mock_cache):
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client,
                                      '/api/v1/get-dit-reference-postcodes/')

    assert response.status_code == 200
    assert response.json['next'] is None
    assert response.json['values'] == []
예제 #8
0
def test_get_ons_postcodes_when_no_data(app_with_hawk_user,
                                        app_with_mock_cache):
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client, '/api/v1/get-ons-postcodes/')

    assert response.status_code == 200
    assert response.json == {
        'headers': ONS_POSTCODE_FIELDS,
        'next': None,
        'values': []
    }
def test_get_table_data(app_with_hawk_user, app_with_mock_cache):
    SPIREFootnoteFactory(text='foo bar', status='CURRENT')
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(
        client, '/api/v1/table-data/spire/footnotes?orientation=records'
    )
    assert response.status_code == 200
    assert response.json == {
        'results': [{'id': 1, 'text': 'foo bar', 'status': 'CURRENT'}],
        'next': None,
    }
def test_get_table_structure(app_with_hawk_user, app_with_mock_cache):
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client, '/api/v1/table-structure/spire/batches')
    assert response.status_code == 200
    assert response.json == {
        'columns': [
            {'name': 'id', 'type': 'INTEGER'},
            {'name': 'batch_ref', 'type': 'TEXT'},
            {'name': 'status', 'type': 'TEXT'},
            {'name': 'start_date', 'type': 'TIMESTAMP'},
            {'name': 'end_date', 'type': 'TIMESTAMP'},
            {'name': 'approve_date', 'type': 'TIMESTAMP'},
            {'name': 'release_date', 'type': 'TIMESTAMP'},
            {'name': 'staging_date', 'type': 'TIMESTAMP'},
        ],
    }
예제 #11
0
def test_get_world_bank_tariffs_single_row(
    app_with_hawk_user, app_with_mock_cache, add_world_bank_tariff
):
    add_world_bank_tariff(
        [
            {
                'data_source_row_id': 1,
                'product': 201,
                'reporter': 705,
                'partner': 36,
                'year': 1990,
                'assumed_tariff': 10.0,
                'app_rate': 11.0,
                'mfn_rate': 12.0,
                'bnd_rate': 14.0,
                'eu_rep_rate': 10,
                'eu_part_rate': 10,
                'eu_eu_rate': 15.0,
                'world_average': 16.0,
            }
        ]
    )

    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client, '/api/v1/get-world-bank-tariffs/?orientation=records')

    assert response.status_code == 200
    assert response.json == {
        'next': None,
        'results': [
            {
                'appRate': 11.0,
                'assumedTariff': 10.0,
                'bndRate': 14.0,
                'euEuRate': 15.0,
                'euPartRate': 10.0,
                'euRepRate': 10.0,
                'mfnRate': 12.0,
                'partner': 36,
                'product': 201,
                'reporter': 705,
                'worldAverage': 16.0,
                'year': 1990,
            }
        ],
    }
예제 #12
0
def test_alias_postcode_route(add_dit_reference_postcodes, app_with_hawk_user,
                              app_with_mock_cache):
    postcodes = [
        {
            'postcode': 'AB10 1AA',
            'local_authority_district_code': 'asdf'
        },
        {
            'postcode': 'ZZ10 1ZZ',
            'local_authority_district_code': 'zzzz'
        },
    ]
    url = '/api/v1/get-postcode-data/?postcode=AB10%201AA'
    add_dit_reference_postcodes(postcodes)
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client, url)
    assert response.status_code == 200
    assert len(response.json['values']) == 1
    assert response.json['values'][0][:2] == ['AB10 1AA', 'asdf']
예제 #13
0
def test_get_ons_postcodes(app_with_hawk_user, app_with_mock_cache,
                           add_ons_postcode):

    postcode = 'AB1 1BA'

    add_ons_postcode([{'postcode': postcode}])
    client = app_with_hawk_user.test_client()

    expected_result = [None] * len(ONS_POSTCODE_FIELDS)
    expected_result[0] = 1
    expected_result[3] = postcode

    response = make_hawk_auth_request(client, '/api/v1/get-ons-postcodes/')

    assert response.status_code == 200
    assert response.json == {
        'headers': ONS_POSTCODE_FIELDS,
        'next': None,
        'values': [expected_result],
    }
예제 #14
0
def test_get_ons_postcodes_next_url(app_with_hawk_user, app_with_mock_cache,
                                    add_ons_postcode):
    app_with_hawk_user.config['app']['pagination_size'] = 1
    postcode_1 = 'AB1 1BA'
    postcode_2 = 'AB2 2BA'

    add_ons_postcode([{'postcode': postcode_1}, {'postcode': postcode_2}])
    client = app_with_hawk_user.test_client()

    expected_result = [None] * len(ONS_POSTCODE_FIELDS)
    expected_result[0] = 1
    expected_result[3] = postcode_1

    response = make_hawk_auth_request(client, '/api/v1/get-ons-postcodes/')
    assert response.status_code == 200
    assert response.json == {
        'headers': ONS_POSTCODE_FIELDS,
        'next':
        'http://localhost/api/v1/get-ons-postcodes/?orientation=tabular&next-id=2',
        'values': [expected_result],
    }
예제 #15
0
def test_get_dit_reference_postcodes(app_with_hawk_user, app_with_mock_cache,
                                     add_dit_reference_postcodes):

    postcodes = [
        {
            'postcode': 'AB10 1AA',
            'local_authority_district_code': 'asdf'
        },
    ]

    add_dit_reference_postcodes(postcodes)
    client = app_with_hawk_user.test_client()

    expected_values = ['AB10 1AA', 'asdf']

    response = make_hawk_auth_request(client,
                                      '/api/v1/get-dit-reference-postcodes/')

    assert response.status_code == 200
    assert response.json['next'] is None
    assert response.json['values'][0][:2] == expected_values
예제 #16
0
def test_get_world_bank_raw_tariffs_single_row(
    app_with_hawk_user, app_with_mock_cache, add_world_bank_raw_tariff
):
    add_world_bank_raw_tariff(
        [
            {
                'product': 201,
                'reporter': 50,
                'partner': 52,
                'year': 1990,
                'simple_average': 15.0,
                'duty_type': 'MFN',
                'number_of_total_lines': 6,
            }
        ]
    )

    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(
        client, '/api/v1/get-world-bank-tariffs/raw/?orientation=records'
    )
    assert response.status_code == 200
    assert response.json == {
        'next': None,
        'results': [
            {
                'dutyType': 'MFN',
                'simpleAverage': 15.0,
                'partner': 52,
                'product': 201,
                'reporter': 50,
                'year': 1990,
                'numberOfTotalLines': 6,
            }
        ],
    }
def test_get_table_data_that_doesnt_have_id_columns(app_with_hawk_user, app_with_mock_cache):
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client, '/api/v1/table-data/spire/applications')
    assert response.status_code == 422
def test_get_table_data_that_doesnt_exist(app_with_hawk_user, app_with_mock_cache):
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client, '/api/v1/table-data/spire/batches_foo')
    assert response.status_code == 404
예제 #19
0
def test_get_hawk_request_when_no_users_in_db(app_with_db):
    HawkUsers.query.delete()
    client = app_with_db.test_client()
    response = make_hawk_auth_request(client, '/api/v1/get-dit-reference-postcodes/')
    assert response.status_code == 401
def test_get_table_structure_in_excluded_schema(app_with_hawk_user, app_with_mock_cache):
    client = app_with_hawk_user.test_client()
    response = make_hawk_auth_request(client, '/api/v1/table-structure/public/hawk_users')
    assert response.status_code == 404