mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 16:38:59 -04:00
Added a validator so that the key name is unique per service.
This commit is contained in:
16
tests/app/main/test_create_api_key_form.py
Normal file
16
tests/app/main/test_create_api_key_form.py
Normal 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
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user