Added tests for get api endpoint

This commit is contained in:
Rebecca Law
2016-01-20 15:41:19 +00:00
parent 9eb856b86e
commit 3e141e05cb
2 changed files with 10 additions and 4 deletions

View File

@@ -123,7 +123,7 @@ def get_api_keys(service_id):
except DAOException as e:
return jsonify(result='error', message=str(e)), 400
return jsonify(apiKeys=api_keys_schema.dump(api_keys)), 200
return jsonify(apiKeys=api_keys_schema.dump(api_keys).data), 200
@service.route('/<int:service_id>/template', methods=['POST'])

View File

@@ -2,10 +2,12 @@ import json
from datetime import timedelta, datetime
from flask import url_for
from app.models import ApiKey
from dao.api_key_dao import save_model_api_key
from app.dao.api_key_dao import save_model_api_key
from tests import create_authorization_header
from tests.app.conftest import sample_api_key as create_sample_api_key
from tests.app.conftest import sample_service as create_sample_service
from tests.app.conftest import sample_user as create_user
def test_api_key_should_create_new_api_key_for_service(notify_api, notify_db,
@@ -91,12 +93,16 @@ def test_get_api_keys_should_return_all_keys_for_service(notify_api, notify_db,
sample_api_key):
with notify_api.test_request_context():
with notify_api.test_client() as client:
another_user = create_user(notify_db, notify_db_session, email='another@it.gov.uk')
another_service = create_sample_service(notify_db, notify_db_session, service_name='another',
user=another_user)
create_sample_api_key(notify_db, notify_db_session, service=another_service)
api_key2 = ApiKey(**{'service_id': sample_api_key.service_id, 'name': 'second_api_key'})
api_key3 = ApiKey(**{'service_id': sample_api_key.service_id, 'name': 'third_api_key',
'expiry_date': datetime.utcnow() + timedelta(hours=-1)})
save_model_api_key(api_key2)
save_model_api_key(api_key3)
assert ApiKey.query.count() == 3
assert ApiKey.query.count() == 4
auth_header = create_authorization_header(path=url_for('service.get_api_keys',
service_id=sample_api_key.service_id),