Added a validator so that the key name is unique per service.

This commit is contained in:
Rebecca Law
2016-01-21 14:15:36 +00:00
parent 2b24909ca6
commit e7713a8b7f
4 changed files with 35 additions and 4 deletions

View File

@@ -0,0 +1,16 @@
from werkzeug.datastructures import MultiDict
from app.main.forms import CreateKeyForm
def test_return_validation_error_when_key_name_exists(app_,
db_,
db_session):
def _get_names():
return ['some key', 'another key']
with app_.test_request_context():
form = CreateKeyForm(_get_names(),
formdata=MultiDict([('key_name', 'some key')]))
form.validate()
assert {'key_name': ['A key with this name already exists']} == form.errors

View File

@@ -62,7 +62,8 @@ def test_should_show_name_api_key_page(app_,
active_user,
mock_get_service,
mock_get_services,
mock_user_loader):
mock_user_loader,
mock_get_api_keys):
with app_.test_request_context():
with app_.test_client() as client:
client.login(active_user)
@@ -78,7 +79,8 @@ def test_should_render_show_api_key(app_,
mock_get_service,
mock_get_services,
mock_user_loader,
mock_create_api_key):
mock_create_api_key,
mock_get_api_keys):
with app_.test_request_context():
with app_.test_client() as client:
client.login(active_user)