send key_type = normal when creating api keys

This commit is contained in:
Leo Hemsted
2016-06-27 12:02:16 +01:00
parent 045e12102f
commit 6ce087a7b5
3 changed files with 44 additions and 56 deletions

View File

@@ -1,28 +1,13 @@
import uuid
from datetime import date
from flask import url_for
from tests import validate_route_permission
def test_should_show_api_keys_and_documentation_page(app_,
api_user_active,
mock_login,
mock_get_user,
mock_get_user_by_email,
mock_get_service):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
response = client.get(url_for('main.documentation', service_id=uuid.uuid4()))
assert response.status_code == 200
def test_should_show_empty_api_keys_page(app_,
api_user_active,
mock_get_user,
mock_login,
mock_get_user_by_email,
mock_get_no_api_keys,
mock_get_service,
mock_has_permissions):
@@ -41,8 +26,6 @@ def test_should_show_empty_api_keys_page(app_,
def test_should_show_api_keys_page(app_,
api_user_active,
mock_login,
mock_get_user,
mock_get_user_by_email,
mock_get_api_keys,
mock_get_service,
mock_has_permissions,
@@ -60,15 +43,13 @@ def test_should_show_api_keys_page(app_,
mock_get_api_keys.assert_called_once_with(service_id=fake_uuid)
def test_should_show_name_api_key_page(app_,
api_user_active,
mock_login,
mock_get_user,
mock_get_user_by_email,
mock_get_api_keys,
mock_get_service,
mock_has_permissions,
fake_uuid):
def test_should_show_create_api_key_page(app_,
api_user_active,
mock_login,
mock_get_api_keys,
mock_get_service,
mock_has_permissions,
fake_uuid):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
@@ -78,32 +59,34 @@ def test_should_show_name_api_key_page(app_,
assert response.status_code == 200
def test_should_render_show_api_key(app_,
api_user_active,
mock_login,
mock_get_user,
mock_get_user_by_email,
mock_create_api_key,
mock_get_api_keys,
mock_get_service,
mock_has_permissions):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
service_id = str(uuid.uuid4())
response = client.post(url_for('main.create_api_key', service_id=service_id),
data={'key_name': 'some default key name'})
def test_should_create_api_key_with_type_normal(app_,
api_user_active,
mock_login,
mock_get_api_keys,
mock_get_service,
mock_has_permissions,
fake_uuid,
mocker):
post = mocker.patch('app.notify_client.api_key_api_client.ApiKeyApiClient.post', return_value={'data': fake_uuid})
service_id = str(uuid.uuid4())
assert response.status_code == 200
assert 'some default key name' in response.get_data(as_text=True)
mock_create_api_key.assert_called_once_with(service_id=service_id, key_name='some default key name')
with app_.test_request_context(), app_.test_client() as client:
client.login(api_user_active)
response = client.post(url_for('main.create_api_key', service_id=service_id),
data={'key_name': 'some default key name'})
assert response.status_code == 200
assert 'some default key name' in response.get_data(as_text=True)
post.assert_called_once_with(url='/service/{}/api-key'.format(service_id), data={
'name': 'some default key name',
'key_type': 'normal',
'created_by': api_user_active.id
})
def test_should_show_confirm_revoke_api_key(app_,
api_user_active,
mock_login,
mock_get_user,
mock_get_user_by_email,
mock_get_api_keys,
mock_get_service,
mock_has_permissions,
@@ -121,8 +104,6 @@ def test_should_show_confirm_revoke_api_key(app_,
def test_should_redirect_after_revoking_api_key(app_,
api_user_active,
mock_login,
mock_get_user,
mock_get_user_by_email,
mock_revoke_api_key,
mock_get_api_keys,
mock_get_service,