File: test_month.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 (29 lines) | stat: -rw-r--r-- 648 bytes parent folder | download
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
from datetime import date

from tests.common import DummyPostData
from wtforms.fields import MonthField
from wtforms.form import Form


class F(Form):
    a = MonthField()
    b = MonthField(format="%m/%Y")


def test_basic():
    d = date(2008, 5, 1)
    form = F(DummyPostData(a=["2008-05"], b=["05/2008"]))

    assert d == form.a.data
    assert "2008-05" == form.a._value()

    assert d == form.b.data


def test_failure():
    form = F(DummyPostData(a=["2008-bb"]))

    assert not form.validate()
    assert 1 == len(form.a.process_errors)
    assert 1 == len(form.a.errors)
    assert "Not a valid date value." == form.a.process_errors[0]