Skip to content

Commit

Permalink
Write test to better test CompoundWidget error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
amol- committed Mar 29, 2012
1 parent 8b15822 commit 74dd870
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test_validation.py
Expand Up @@ -22,6 +22,9 @@
twc.Widget(id='c', key='y', validator=formencode.validators.OpenId()), twc.Widget(id='c', key='y', validator=formencode.validators.OpenId()),
]) ])


#This is required to make tests pass on non english systems
formencode.api.set_stdtranslation(languages=['en'])

class TestValidationError(tb.WidgetTest): class TestValidationError(tb.WidgetTest):
def test_validator_msg(self): def test_validator_msg(self):
twc.core.request_local = tb.request_local_tst twc.core.request_local = tb.request_local_tst
Expand Down Expand Up @@ -142,6 +145,7 @@ class MatchyWidget(twc.CompoundWidget):
validator = formencode.validators.FieldsMatch('one', 'two') validator = formencode.validators.FieldsMatch('one', 'two')
one = twc.Widget one = twc.Widget
two = twc.Widget two = twc.Widget
three = twc.Widget(validator=twc.Validator(required=True))


try: try:
MatchyWidget.validate({'one': 'foo', 'two': 'bar'}) MatchyWidget.validate({'one': 'foo', 'two': 'bar'})
Expand All @@ -151,6 +155,14 @@ class MatchyWidget(twc.CompoundWidget):
assert 'do not match' not in ve.widget.error_msg assert 'do not match' not in ve.widget.error_msg
assert 'childerror' not in ve.widget.error_msg assert 'childerror' not in ve.widget.error_msg


try:
MatchyWidget.validate({'one': 'foo', 'two': 'foo', 'three':''})
assert False, "Widget should not have validated."
except ValidationError as ve:
assert 'Enter a value' in ve.widget.children[2].error_msg
assert 'Enter a value' not in ve.widget.error_msg
assert 'childerror' not in ve.widget.error_msg

def test_auto_unflatten(self): def test_auto_unflatten(self):
test = twc.CompoundWidget(id='a', children=[ test = twc.CompoundWidget(id='a', children=[
twc.Widget(id='b', validator=twc.Validator(required=True)), twc.Widget(id='b', validator=twc.Validator(required=True)),
Expand Down

0 comments on commit 74dd870

Please sign in to comment.