-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_base.py
90 lines (68 loc) · 2.34 KB
/
test_base.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from collections import namedtuple
import pytest
from flask import current_app
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from noggin.form.base import ButtonWidget, CSVListField, ModestForm, SubmitButtonField
def test_buttonwidget(client):
class TestForm(FlaskForm):
submit = SubmitField()
text = StringField()
form = TestForm()
widget = ButtonWidget()
kwargs = {"class": "testclass", "testattr": "testvalue"}
output = widget(form.submit, **kwargs)
assert output == (
'<button class="btn testclass" id="submit" name="submit" '
'testattr="testvalue" type="button">Submit</button>'
)
def test_modestform(client):
class TestForm(ModestForm):
text = StringField()
submit = SubmitButtonField()
with current_app.test_request_context('/', method="POST", data={"submit": "1"}):
form = TestForm()
assert form.is_submitted()
def test_modestform_button_not_clicked(client):
class TestForm(ModestForm):
text = StringField()
submit = SubmitButtonField()
with current_app.test_request_context(
'/', method="POST", data={"text": "dummy value"}
):
form = TestForm()
assert not form.is_submitted()
def test_modestform_no_submit_button(client):
class TestForm(ModestForm):
text = StringField()
with current_app.test_request_context(
'/', method="POST", data={"text": "dummy value"}
):
form = TestForm()
assert form.is_submitted()
@pytest.mark.parametrize(
"test_input,expected",
[
(["one,two,three"], ["one", "two", "three"]),
([" "], []),
([" , , , "], []),
([""], []),
([], []),
],
)
def test_csvlistfield(client, test_input, expected):
class DummyForm(FlaskForm):
csvfield = CSVListField('csv field')
form = DummyForm()
form.csvfield.process_formdata(test_input)
assert form.csvfield.data == expected
@pytest.mark.parametrize(
"data,expected",
[(["one", "two", "three"], "one,two,three"), ([""], ""), ([], "")],
)
def test_csvlistfield_read(client, data, expected):
class DummyForm(FlaskForm):
csvfield = CSVListField('csv field')
Obj = namedtuple("Obj", ["csvfield"])
form = DummyForm(obj=Obj(csvfield=data))
assert form.csvfield._value() == expected