File: test_mac_address.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 (28 lines) | stat: -rw-r--r-- 822 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
import pytest

from wtforms.validators import mac_address
from wtforms.validators import ValidationError


@pytest.mark.parametrize("mac_addr_val", ["01:23:45:67:ab:CD"])
def test_valid_mac_passes(mac_addr_val, dummy_form, dummy_field):
    """
    Valid MAC address should pass without raising
    """
    validator = mac_address()
    dummy_field.data = mac_addr_val
    validator(dummy_form, dummy_field)


@pytest.mark.parametrize(
    "mac_addr_val",
    ["00:00:00:00:00", "01:23:45:67:89:", "01:23:45:67:89:gh", "123:23:45:67:89:00"],
)
def test_bad_mac_raises(mac_addr_val, dummy_form, dummy_field):
    """
    Bad MAC address should raise ValidatioError
    """
    validator = mac_address()
    dummy_field.data = mac_addr_val
    with pytest.raises(ValidationError):
        validator(dummy_form, dummy_field)