File: test_uuid.py

package info (click to toggle)
wtforms 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,064 kB
  • sloc: python: 5,264; makefile: 27; sh: 17
file content (36 lines) | stat: -rw-r--r-- 944 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pytest

from wtforms.validators import UUID
from wtforms.validators import ValidationError


@pytest.mark.parametrize(
    "uuid_val",
    ["2bc1c94f-0deb-43e9-92a1-4775189ec9f8", "2bc1c94f0deb43e992a14775189ec9f8"],
)
def test_valid_uuid_passes(uuid_val, dummy_form, dummy_field):
    """
    Valid UUID should pass without raising
    """
    validator = UUID()
    dummy_field.data = uuid_val
    validator(dummy_form, dummy_field)


@pytest.mark.parametrize(
    "uuid_val",
    [
        "2bc1c94f-deb-43e9-92a1-4775189ec9f8",
        "2bc1c94f-0deb-43e9-92a1-4775189ec9f",
        "gbc1c94f-0deb-43e9-92a1-4775189ec9f8",
        "2bc1c94f 0deb-43e9-92a1-4775189ec9f8",
    ],
)
def test_bad_uuid_raises(uuid_val, dummy_form, dummy_field):
    """
    Bad UUID should raise ValueError
    """
    validator = UUID()
    dummy_field.data = uuid_val
    with pytest.raises(ValidationError):
        validator(dummy_form, dummy_field)