예제 #1
0
    def test_createAndAdd(self):

        class Adding(object):

            implements(IAdding)

            def __init__(self, test):
                self.test = test

            def add(self, ob):
                self.ob = ob
                self.test.assertEqual(
                    ob.__dict__,
                    {'args': ("bar", "baz"),
                     'kw': {'email': '*****@*****.**'},
                     '_foo': 'foo',
                    })
                return ob
            def nextURL(self):
                return "."

        adding = Adding(self)
        self._invoke_add()
        (descriminator, callable, args, kw) = self._context.last_action
        factory = AddViewFactory(*args)
        request = TestRequest()
        view = zapi.getMultiAdapter((adding, request), name='addthis')

        view.createAndAdd(SampleData.__dict__)

        self.assertEqual(adding.ob.extra1, "extra1")
        self.assertEqual(adding.ob.extra2, "extra2")
        self.assertEqual(adding.ob.name, "foo")
        self.assertEqual(adding.ob.address, "aa")
        self.assertEqual(len(getEvents(IObjectCreatedEvent)), 1)
        self.assertEqual(len(getEvents(IObjectModifiedEvent)), 1)
예제 #2
0
 def test_update_via_adapter(self):
     f = Foo()
     request = TestRequest()
     v = BarV(f, request)
     # check adapter
     self.assertEqual(f.foo, u'Foo foo')
     a = IBar(f)
     self.assertEqual(a.bar, u'Foo foo')
     # update
     request.form[Update] = ''
     request.form['field.bar'] = u'r bar'
     message = v.update()
     self.failUnless(message.startswith('Updated '), message)
     self.assertEqual(a.bar, u'r bar')
     # wrong update
     self.failIf(getEvents())
예제 #3
0
 def test_update_no_update(self):
     c = C()
     request = TestRequest()
     v = EV(c, request)
     self.assertEqual(v.update(), '')
     self.assertEqual(c.foo, u'c foo')
     self.assertEqual(c.bar, u'c bar')
     self.assertEqual(c.a  , u'c a')
     self.assertEqual(c.b  , u'c b')
     self.assertEqual(c.getbaz(), u'c baz')
     request.form['field.foo'] = u'r foo'
     request.form['field.bar'] = u'r bar'
     request.form['field.a']   = u'r a'
     request.form['field.b']   = u'r b'
     request.form['field.getbaz'] = u'r baz'
     self.assertEqual(v.update(), '')
     self.assertEqual(c.foo, u'c foo')
     self.assertEqual(c.bar, u'c bar')
     self.assertEqual(c.a  , u'c a')
     self.assertEqual(c.b  , u'c b')
     self.assertEqual(c.getbaz(), u'c baz')
     self.failIf(getEvents())