コード例 #1
0
def test_return_validation_error_when_key_type_not_chosen(app_, key_type, expected_error):

    with app_.test_request_context():
        form = CreateKeyForm(
            [],
            formdata=MultiDict([('key_name', 'Some key'), ('key_type', key_type)]))
        form.validate()
        assert form.errors['key_type'] == [expected_error]
コード例 #2
0
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]
コード例 #3
0
def test_return_validation_error_when_key_name_exists(app_):
    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 form.errors['key_name'] == ['A key with this name already exists']
コード例 #4
0
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']
コード例 #5
0
def test_return_validation_error_when_key_name_exists(
    client,
    expiry_date,
    expected_errors,
):
    _existing_keys = [
        {
            "name": "some key",
            "expiry_date": expiry_date,
        },
        {
            "name": "another key",
            "expiry_date": None,
        },
    ]

    form = CreateKeyForm(_existing_keys, formdata=MultiDict([("key_name", "Some key")]))

    form.key_type.choices = [("a", "a"), ("b", "b")]
    form.validate()
    assert form.errors.get("key_name") == expected_errors
コード例 #6
0
def test_return_validation_error_when_key_name_exists(
    client,
    expiry_date,
    expected_errors,
):
    _existing_keys = [
        {
            'name': 'some key',
            'expiry_date': expiry_date,
        },
        {
            'name': 'another key',
            'expiry_date': None,
        },
    ]

    form = CreateKeyForm(_existing_keys,
                         formdata=MultiDict([('key_name', 'Some key')]))

    form.key_type.choices = [('a', 'a'), ('b', 'b')]
    form.validate()
    assert form.errors.get('key_name') == expected_errors
コード例 #7
0
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]