Fix bug in UII field
Was displaying an empty list of UIIs as [''] in the textarea
This commit is contained in:
parent
af96237231
commit
070fe823d3
@ -32,6 +32,6 @@ class NewlineListField(Field):
|
||||
|
||||
def process_formdata(self, valuelist):
|
||||
if valuelist:
|
||||
self.data = [l.strip() for l in valuelist[0].split("\n")]
|
||||
self.data = [l.strip() for l in valuelist[0].split("\n") if l]
|
||||
else:
|
||||
self.data = []
|
||||
|
@ -1,25 +1,58 @@
|
||||
import pytest
|
||||
from wtforms import Form
|
||||
import pendulum
|
||||
from werkzeug.datastructures import ImmutableMultiDict
|
||||
|
||||
from atst.forms.fields import DateField
|
||||
from atst.forms.fields import DateField, NewlineListField
|
||||
|
||||
|
||||
class MyForm(Form):
|
||||
class DateForm(Form):
|
||||
date = DateField()
|
||||
|
||||
|
||||
class NewlineListForm(Form):
|
||||
newline_list = NewlineListField()
|
||||
|
||||
|
||||
def test_date_ie_format():
|
||||
form = MyForm(data={"date": "12/24/2018"})
|
||||
form = DateForm(data={"date": "12/24/2018"})
|
||||
assert form.date._value() == pendulum.date(2018, 12, 24)
|
||||
|
||||
|
||||
def test_date_sane_format():
|
||||
form = MyForm(data={"date": "2018-12-24"})
|
||||
form = DateForm(data={"date": "2018-12-24"})
|
||||
assert form.date._value() == pendulum.date(2018, 12, 24)
|
||||
|
||||
|
||||
def test_date_insane_format():
|
||||
form = MyForm(data={"date": "hello"})
|
||||
form = DateForm(data={"date": "hello"})
|
||||
with pytest.raises(ValueError):
|
||||
form.date._value()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("input_,expected", [
|
||||
("", []),
|
||||
("hello", ["hello"]),
|
||||
("hello\n", ["hello"]),
|
||||
("hello\nworld", ["hello", "world"]),
|
||||
("hello\nworld\n", ["hello", "world"])
|
||||
])
|
||||
def test_newline_list_process(input_, expected):
|
||||
form_data = ImmutableMultiDict({"newline_list": input_})
|
||||
form = NewlineListForm(form_data)
|
||||
|
||||
assert form.validate()
|
||||
assert form.data == {"newline_list": expected}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("input_,expected", [
|
||||
([], ""),
|
||||
(["hello"], "hello"),
|
||||
(["hello", "world"], "hello\nworld")
|
||||
])
|
||||
def test_newline_list_value(input_, expected):
|
||||
form_data = {"newline_list": input_}
|
||||
form = NewlineListForm(data=form_data)
|
||||
|
||||
assert form.validate()
|
||||
assert form.newline_list._value() == expected
|
||||
|
@ -3,12 +3,12 @@ import pytest
|
||||
from atst.forms.financial import suggest_pe_id
|
||||
|
||||
|
||||
@pytest.mark.parametrize("input,expected", [
|
||||
@pytest.mark.parametrize("input_,expected", [
|
||||
('0603502N', None),
|
||||
('0603502NZ', None),
|
||||
('603502N', '0603502N'),
|
||||
('063502N', '0603502N'),
|
||||
('63502N', '0603502N'),
|
||||
])
|
||||
def test_suggest_pe_id(input, expected):
|
||||
assert suggest_pe_id(input) == expected
|
||||
def test_suggest_pe_id(input_, expected):
|
||||
assert suggest_pe_id(input_) == expected
|
||||
|
Loading…
x
Reference in New Issue
Block a user