diff --git a/app/schemas.py b/app/schemas.py index 8ef213c8c..3e7741fa7 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -165,7 +165,7 @@ class NotificationsStatisticsSchema(BaseSchema): class ApiKeySchema(BaseSchema): created_by = field_for(models.ApiKey, 'created_by', required=True) - key_type = field_for(models.ApiKey, 'key_type', required=True, missing=models.KEY_TYPE_NORMAL) + key_type = field_for(models.ApiKey, 'key_type', required=True) class Meta: model = models.ApiKey diff --git a/tests/app/service/test_api_key_endpoints.py b/tests/app/service/test_api_key_endpoints.py index 35c354553..dfee92e2c 100644 --- a/tests/app/service/test_api_key_endpoints.py +++ b/tests/app/service/test_api_key_endpoints.py @@ -40,7 +40,7 @@ def test_api_key_should_return_error_when_service_does_not_exist(notify_api, sam assert response.status_code == 404 -def test_create_api_key_should_set_default_key_type_of_normal(notify_api, sample_service): +def test_create_api_key_without_key_type_rejects(notify_api, sample_service): with notify_api.test_request_context(), notify_api.test_client() as client: data = { 'name': 'some secret name', @@ -50,8 +50,10 @@ def test_create_api_key_should_set_default_key_type_of_normal(notify_api, sample response = client.post(url_for('service.create_api_key', service_id=sample_service.id), data=json.dumps(data), headers=[('Content-Type', 'application/json'), auth_header]) - assert response.status_code == 201 - assert ApiKey.query.one().key_type == KEY_TYPE_NORMAL + assert response.status_code == 400 + json_resp = json.loads(response.get_data(as_text=True)) + assert json_resp['result'] == 'error' + assert json_resp['message'] == {'key_type': ['Missing data for required field.']} def test_revoke_should_expire_api_key_for_service(notify_api, sample_api_key):