Files
notifications-admin/tests/app/main/test_create_api_key_form.py
Chris Hill-Scott f3a0c505bd Enforce order and style of imports
Done using isort[1], with the following command:
```
isort -rc ./app ./tests
```

Adds linting to the `run_tests.sh` script to stop badly-sorted imports
getting re-introduced.

Chosen style is ‘Vertical Hanging Indent’ with trailing commas, because
I think it gives the cleanest diffs, eg:
```
from third_party import (
    lib1,
    lib2,
    lib3,
    lib4,
)
```

1. https://pypi.python.org/pypi/isort
2018-02-27 16:35:13 +00:00

32 lines
989 B
Python

import pytest
from werkzeug.datastructures import MultiDict
from app.main.forms import CreateKeyForm
def test_return_validation_error_when_key_name_exists(client):
def _get_names():
return ['some key', 'another key']
form = CreateKeyForm(_get_names(),
formdata=MultiDict([('key_name', 'Some key')]))
form.key_type.choices = [('a', 'a'), ('b', 'b')]
form.validate()
assert form.errors['key_name'] == ['A key with this name already exists']
@pytest.mark.parametrize(
'key_type, expected_error', [
('', 'This field is required.'),
('invalid', 'Not a valid choice')
]
)
def test_return_validation_error_when_key_type_not_chosen(client, key_type, expected_error):
form = CreateKeyForm(
[],
formdata=MultiDict([('key_name', 'Some key'), ('key_type', key_type)]))
form.key_type.choices = [('a', 'a'), ('b', 'b')]
form.validate()
assert form.errors['key_type'] == [expected_error]