Use client fixture everywhere

There were a few tests which weren't using the `client` fixture but were
using the code it contains. This simplifies them to use the fixture.
This commit is contained in:
Katie Smith
2021-12-16 14:26:17 +00:00
parent 0b7410818e
commit 3530d26ba3
3 changed files with 82 additions and 88 deletions

View File

@@ -38,20 +38,19 @@ 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_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',
'created_by': str(sample_service.created_by.id)
}
auth_header = create_admin_authorization_header()
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 == 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_create_api_key_without_key_type_rejects(client, sample_service):
data = {
'name': 'some secret name',
'created_by': str(sample_service.created_by.id)
}
auth_header = create_admin_authorization_header()
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 == 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):