Exemplo n.º 1
0
def test_api_1_accounts_update_invalid_schema_put(swag_app, swag_app_client):
    account_dict = {
        'aliases': ['test'],
        'contacts': ['*****@*****.**'],
        'description': 'LOL, Test account',
        'email': '*****@*****.**',
        'environment': 'test',
        'id': '012345678910',
        'name': 'testaccount',
        'owner': 'netflix',
        'provider': 'aws',
        'sensitive': False
    }
    response = swag_app_client.put('/api/1/accounts/012345678910',
                                   data=json.dumps(account_dict),
                                   content_type='application/json')
    assert response.status_code == 204

    del account_dict['id']
    counter_metric, latency_metric = reset_metrics(swag_app)
    response = swag_app_client.post('/api/1/accounts/012345678910',
                                    data=json.dumps(account_dict),
                                    content_type='application/json')
    assert response.status_code == 400
    assert response.get_json() == {'id': ['Missing data for required field.']}

    mocked_metrics = {
        'method': 'post',
        'service': 'accounts',
        'endpoint': 'accounts.update_account',
        'status_code': '400'
    }
    metrics_tests(counter_metric, latency_metric, mocked_metrics)
Exemplo n.º 2
0
def test_api_1_account_service_add_valid_schema_put(swag_app, swag_app_client):
    response = swag_app_client.get(
        '/api/1/accounts/service/testaccount/myNewService')
    assert response.status_code == 404

    netflix_service = {
        'name': 'myNewService',
        'status': [{
            'region': 'all',
            'enabled': True,
            'notes': []
        }],
        'metadata': {},
        'roles': []
    }
    counter_metric, latency_metric = reset_metrics(swag_app)
    response = swag_app_client.put(
        '/api/1/accounts/service/testaccount/myNewService',
        data=json.dumps(netflix_service),
        content_type='application/json')
    assert response.status_code == 204

    mocked_metrics = {
        'method': 'put',
        'service': 'service',
        'endpoint': 'service.add_service_for_account',
        'status_code': '204'
    }
    metrics_tests(counter_metric, latency_metric, mocked_metrics)

    response = swag_app_client.get(
        '/api/1/accounts/service/testaccount/myNewService')
    assert response.status_code == 200
    assert response.get_json()['name'] == 'myNewService'
Exemplo n.º 3
0
def test_api_1_accounts_create_valid_schema_put(swag_app, swag_app_client):
    account_dict = {
        'aliases': ['test'],
        'contacts': ['*****@*****.**'],
        'description': 'LOL, Test account',
        'email': '*****@*****.**',
        'environment': 'test',
        'id': '012345678910',
        'name': 'testaccount',
        'owner': 'netflix',
        'provider': 'aws',
        'sensitive': False
    }
    response = swag_app_client.get('/api/1/accounts')
    assert len(response.get_json()) == 3

    counter_metric, latency_metric = reset_metrics(swag_app)
    response = swag_app_client.put('/api/1/accounts/012345678910',
                                   data=json.dumps(account_dict),
                                   content_type='application/json')
    assert response.status_code == 204
    mocked_metrics = {
        'method': 'put',
        'service': 'accounts',
        'endpoint': 'accounts.add_new_account',
        'status_code': '204'
    }
    metrics_tests(counter_metric, latency_metric, mocked_metrics)

    response = swag_app_client.get('/api/1/accounts')
    assert len(response.get_json()) == 4
Exemplo n.º 4
0
def test_api_1_account_service_updated_invalid_schema_post(swag_app, swag_app_client):
    response = swag_app_client.get('/api/1/accounts/service/testaccount/myService')
    assert response.status_code == 200

    netflix_service = {
        'status': [{
            'region': 'all',
            'enabled': True,
            'notes': []
        }],
        'metadata': {
            'updated': 'yesterday'
        },
        'roles': []
    }
    counter_metric, latency_metric = reset_metrics(swag_app)
    response = swag_app_client.post(
        '/api/1/accounts/service/testaccount/myService',
        data=json.dumps(netflix_service),
        content_type='application/json'
    )
    assert response.status_code == 400
    assert response.get_json() == {'services': {'2': {'name': ['Missing data for required field.']}}}

    mocked_metrics = {
        'method': 'post',
        'service': 'service',
        'endpoint': 'service.update_service_for_account',
        'status_code': '400'
    }
    metrics_tests(counter_metric, latency_metric, mocked_metrics)
Exemplo n.º 5
0
def test_api_1_healthcheck_bad_get(bad_swag_app, swag_app_client_bad):
    counter_metric, latency_metric = reset_metrics(bad_swag_app)
    response = swag_app_client_bad.get('/api/1/healthcheck')

    assert response.status_code == 500
    assert response.data.decode('utf-8') == 'BAD'

    mocked_metrics = {
        'method': 'get',
        'service': 'healthcheck',
        'status_code': '500'
    }
    metrics_tests(counter_metric, latency_metric, mocked_metrics)
Exemplo n.º 6
0
def test_api_1_account_service_delete(swag_app, swag_app_client):
    response = swag_app_client.get('/api/1/accounts/service/testaccount/myService')
    assert isinstance(response.get_json(), dict)

    counter_metric, latency_metric = reset_metrics(swag_app)
    response = swag_app_client.delete('/api/1/accounts/service/testaccount/myService')
    assert response.status_code == 204

    mocked_metrics = {
        'method': 'delete',
        'service': 'service',
        'endpoint': 'service.delete_service_from_account',
        'status_code': '204'
    }
    metrics_tests(counter_metric, latency_metric, mocked_metrics)

    response = swag_app_client.get('/api/1/accounts/service/testaccount/myService')
    assert response.status_code == 404
    assert response.get_json() == {'service': 'Not found'}
Exemplo n.º 7
0
def test_api_1_account_service_toggle_post(swag_app, swag_app_client):
    response = swag_app_client.get(
        '/api/1/accounts/service/testaccount/myService')
    assert response.get_json()['status'][0]['enabled']
    toggle_dict = {'enabled': False}

    counter_metric, latency_metric = reset_metrics(swag_app)
    response = swag_app_client.post(
        '/api/1/accounts/service/testaccount/myService/toggle',
        data=json.dumps(toggle_dict),
        content_type='application/json')
    assert response.status_code == 204
    mocked_metrics = {
        'method': 'post',
        'service': 'service',
        'endpoint': 'service.toggle_service_for_account',
        'status_code': '204'
    }
    metrics_tests(counter_metric, latency_metric, mocked_metrics)

    response = swag_app_client.get(
        '/api/1/accounts/service/testaccount/myService')
    assert not response.get_json()['status'][0]['enabled']