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)
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'}
def test_api_1_accounts_update_valid_schema_post(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 account_dict['description'] = 'UPDATED' 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 == 204 mocked_metrics = { 'method': 'post', 'service': 'accounts', 'endpoint': 'accounts.update_account', 'status_code': '204' } metrics_tests(counter_metric, latency_metric, mocked_metrics) response = swag_app_client.get('/api/1/accounts/012345678910') assert response.get_json()['description'] == 'UPDATED'
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)
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']