Exemple #1
0
 def test_processing(self):
     model = Model(
         params=[
             Value(name='foo', value=4),
             Value(name='bar', value=u'quux')])
     result = model.process()
     self.assertEquals(result, dict(foo=4, bar=u'quux'))
Exemple #2
0
 def test_processing(self):
     model = Model(params=[
         Value(name='foo', value=4),
         Value(name='bar', value=u'quux')
     ])
     result = model.process()
     self.assertEquals(result, dict(foo=4, bar=u'quux'))
Exemple #3
0
    def test_attachMany(self):
        model = Model()
        p1 = Value(name='foo')
        p2 = Value(name='bar')

        model.attach(p1, p2)
        self.assertIdentical(model.params['foo'], p1)
        self.assertIdentical(model.params['bar'], p2)
Exemple #4
0
    def test_attachMany(self):
        model = Model()
        p1 = Value(name='foo')
        p2 = Value(name='bar')

        model.attach(p1, p2)
        self.assertIdentical(model.params['foo'], p1)
        self.assertIdentical(model.params['bar'], p2)
Exemple #5
0
    def setUp(self):
        s = self.store = Store()
        installOn(WebSite(store=s), s)

        self.model = Model(params=[
            Value(name='foo', value=4),
            Value(name='bar', value=u'quux')
        ])
Exemple #6
0
 def test_loadFromItem(self):
     item = _DummyItem(i=55, t=u'lulz')
     model = Model(params=[
         Value.fromAttr(_DummyItem.i),
         Value.fromAttr(_DummyItem.t)
     ])
     loadFromItem(model, item)
     self.assertEqual(model.params['i'].value, item.i)
     self.assertEqual(model.params['t'].value, item.t)
Exemple #7
0
class _DummyLiveForm(object):
    page = None
    liveFragmentChildren = []
    model = Model(params=[])

    def addFormChild(self, *args):
        pass

    def getParameter(self, name):
        return _DummyParameter()
Exemple #8
0
    def test_constraints(self):
        def _constraint(value):
            if value != 5:
                return u'Value must be 5'

        param = Value(name='param')
        param._constraint = constraint(_constraint)
        self.assertFalse(param.isValid(4))
        self.assertTrue(param.isValid(5))

        model = Model([param])
        param.value = 3
        self.assertRaises(errors.ConstraintError, model.process)
Exemple #9
0
def containerFromAttributes(containerFactory, store, attributes, callback, doc,
                            **env):
    """
    Generate a model and view, with inputs, from Axiom attributes.

    Any additional keyword arguments are passed to L{inputTypeFromAttribute},
    when creating the inputs.

    @type containerFactory: C{callable} taking a L{Model} parameter
    @param containerFactory: Callable to create an input container

    @type store: L{axiom.store.Store}
    @param store: Store backing the synthesized L{Model}

    @type attributes: C{iterable} of Axiom attributes
    @param attributes: Attributes to synthesize a model and view for

    @type callback: C{callable} taking keyword arguments with names matching
        those of L{attributes}
    @param callback: Model callback

    @type doc: C{unicode}
    @param doc: Model caption

    @return: View container with child inputs for L{attributes}
    """
    attributes = tuple(attributes)

    model = Model(
        callback=callback,
        params=[paramFromAttribute(store, attr, None) for attr in attributes],
        doc=doc)

    container = containerFactory(model)

    for attr in attributes:
        inputType = inputTypeFromAttribute(attr, **env)
        inputType(parent=container, name=attr.attrname)

    return container
Exemple #10
0
 def setUp(self):
     self.form = view.LiveForm(store=None, model=Model())
Exemple #11
0
 def test_attach(self):
     model = Model()
     p = Value(name='foo')
     model.attach(p)
     self.assertIdentical(model.params['foo'], p)
Exemple #12
0
 def test_attach(self):
     model = Model()
     p = Value(name='foo')
     model.attach(p)
     self.assertIdentical(model.params['foo'], p)