Esempio n. 1
0
    def test_round_trip(self):
        test = twc.CompoundWidget(
            id='a',
            children=[
                twc.DisplayOnlyWidget(
                    child=twc.RepeatingWidget(id='q', child=twc.Widget)),
                twc.CompoundWidget(id='cc',
                                   children=[
                                       twc.Widget(id='d'),
                                       twc.Widget(id='e'),
                                   ])
            ])

        widgets = [
            test.children[0].child.rwbc[0],
            test.children[0].child.rwbc[1],
            test.children.cc.children.d,
            test.children.cc.children.e,
        ]

        data = dict(
            (w.compound_id, 'test%d' % i) for i, w in enumerate(widgets))
        testapi.request(1)
        vdata = test.validate(data)

        test = twc.core.request_local()['validated_widget']
        widgets = [
            test.children[0].child.children[0],
            test.children[0].child.children[1],
            test.children.cc.children.d,
            test.children.cc.children.e,
        ]

        for i, w in enumerate(widgets):
            eq_(w.value, 'test%d' % i)
Esempio n. 2
0
    def test_rw_length(self):
        testb = twc.RepeatingWidget(child=Child)

        test = testb.req(value=list(range(10)))
        test.repetitions = None
        test.prepare()
        assert(test.repetitions == 10)

        test = testb.req(value=list(range(10)))
        test.extra_reps = 5
        test.repetitions = None
        test.prepare()
        assert(test.repetitions == 15)

        test = testb.req(value=list(range(10)))
        test.max_reps = 10
        test.repetitions = None
        test.prepare()
        assert(test.repetitions == 10)

        test = testb.req(value=list(range(10)))
        test.max_reps = 30
        test.min_reps = 20
        test.repetitions = None
        test.prepare()
        assert(test.repetitions == 20)
Esempio n. 3
0
 def test_rw_propagate(self):
     test = twc.RepeatingWidget(child=Child).req()
     testapi.request(1)
     test.value = ['a', 'b', 'c']
     test.prepare()
     assert(len(test.children) == 3)
     assert([w.value for w in test.children] == ['a', 'b', 'c'])
Esempio n. 4
0
 def test_rwb(self):
     test = twc.RepeatingWidget(child=Child(template=None)).req()
     testapi.request(1)
     test.value = ['a', 'b', 'c']
     test.prepare()
     for i in range(4):
         assert(test.children[i].repetition == i)
     assert(test.children[0] is not test.children[1])
Esempio n. 5
0
import formencode
from nose.tools import eq_, raises
from webob.multidict import MultiDict
from unittest import TestCase
import sys

HAS_SKIP = sys.version_info[0] == 2 and sys.version_info[1] == 7

compound_widget = twc.CompoundWidget(
    id='a',
    children=[
        twc.Widget(id='b', validator=twc.Validator(required=True)),
        twc.Widget(id='c', validator=twc.Validator(required=True)),
    ])

repeating_widget = twc.RepeatingWidget(
    id='a', child=twc.Widget(validator=twc.Validator(required=True)))

compound_keyed_widget = twc.CompoundWidget(
    id='a',
    children=[
        twc.Widget(id='b', key='x', validator=twc.Validator(required=True)),
        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):
    def test_validator_msg(self):
        twc.core.request_local = tb.request_local_tst
Esempio n. 6
0
 def test_repeating_id(self):
     test = twc.RepeatingWidget(id='x', child=Child)
     assert(test.rwbc[3].compound_id == 'x:3')