コード例 #1
0
ファイル: test_validation.py プロジェクト: abele/tw2.core
    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)
コード例 #2
0
 def test_compound_id(self):
     test = twc.CompoundWidget(id='x',
                               children=[
                                   twc.Widget(id='a'),
                                   twc.Widget(id='b'),
                               ])
     assert (test.children.a.compound_id == 'x:a')
コード例 #3
0
ファイル: test_validation.py プロジェクト: abele/tw2.core
 def test_auto_unflatten(self):
     test = twc.CompoundWidget(
         id='a',
         children=[
             twc.Widget(id='b', validator=twc.Validator(required=True)),
         ])
     testapi.request(1)
     eq_(test.validate({'a:b': '10'}), {'b': '10'})
コード例 #4
0
 def test_widget_nesting(self):
     twc.core.request_local()['middleware'] = twc.make_middleware(None)
     for outer, inner in itertools.product(engines, engines):
         outer = '%s:tw2.core.test_templates.widget_%s' % (outer, outer)
         inner = '%s:tw2.core.test_templates.inner_%s' % (inner, inner)
         test = twc.CompoundWidget(
             id='x',
             template=outer,
             children=[TestWD(id='y', template=inner)])
         eq_(test.display(), '<p>TEST <p>TEST bob</p></p>')
コード例 #5
0
    def test_cw_propagate(self):
        testb = twc.CompoundWidget(id='a', template='x', children=[
            Child(id='b'),
            Child(id='c'),
        ])
        test = testb.req(value = {'b':1, 'c':2})
        test.prepare()
        assert(test.children.b.value == 1)
        assert(test.children.c.value == 2)

        class A:
            pass
        a = A()
        a.b = 10
        a.c= 20
        test = testb.req(value = a)
        test.prepare()
        assert(test.children.b.value == 10)
        assert(test.children.c.value == 20)
コード例 #6
0
ファイル: test_validation.py プロジェクト: abele/tw2.core
import tw2.core as twc, testapi
import tw2.core.testbase as tb
from tw2.core.validation import *
import re
import datetime
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'])