Ejemplo n.º 1
0
 def setUp(self):
     from AccessControl.SecurityManagement import newSecurityManager
     from Products.CMFCore.tests.base.dummy import DummyFolder
     from Products.CMFCore.tests.base.security import UserWithRoles
     self.f = DummyFolder(fake_product=1)
     self.ti = self._makeOne('Foo', product='FooProduct', factory='addFoo')
     newSecurityManager(None, UserWithRoles('FooAdder').__of__(self.f))
Ejemplo n.º 2
0
class FTIOldstyleConstructionTests(FTIConstructionTestCase):

    def setUp(self):
        self.f = DummyFolder(fake_product=1)
        self.ti = self._makeOne('Foo', product='FooProduct', factory='addFoo')
        newSecurityManager(None, UserWithRoles('FooAdder').__of__(self.f))

    def tearDown(self):
        noSecurityManager()

    def test_constructInstance_w_id_munge(self):
        self.f._prefix = 'majyk'
        self.ti.constructInstance(self.f, 'dust')
        majyk_dust = self.f._getOb('majyk_dust')
        self.assertEqual(majyk_dust.id, 'majyk_dust')
Ejemplo n.º 3
0
 def setUp(self):
     self.f = DummyFolder(fake_product=1)
     self.ti = self._makeOne('Foo', product='FooProduct', factory='addFoo')
     newSecurityManager(None, UserWithRoles('FooAdder').__of__(self.f))
Ejemplo n.º 4
0
 def __init__(self, id='', fake_product=0, prefix=''):
     BaseDummyFolder.__init__(self, fake_product, prefix)
     self._id = id
Ejemplo n.º 5
0
class FTIOldstyleConstructionTests(FTIConstructionTestCase, unittest.TestCase):

    def setUp(self):
        from AccessControl.SecurityManagement import newSecurityManager
        from Products.CMFCore.tests.base.dummy import DummyFolder
        from Products.CMFCore.tests.base.security import UserWithRoles
        self.f = DummyFolder(fake_product=1)
        self.ti = self._makeOne('Foo', product='FooProduct', factory='addFoo')
        newSecurityManager(None, UserWithRoles('FooAdder').__of__(self.f))

    def tearDown(self):
        from AccessControl.SecurityManagement import noSecurityManager
        from zope.testing.cleanup import cleanUp
        cleanUp()
        noSecurityManager()

    def test_constructInstance_w_id_munge(self):
        self.f._prefix = 'majyk'
        self.ti.constructInstance(self.f, 'dust')
        majyk_dust = self.f._getOb('majyk_dust')
        self.assertEqual(majyk_dust.id, 'majyk_dust')

    def test_events(self):
        from OFS.interfaces import IObjectWillBeAddedEvent
        from zope.component import adapter
        from zope.component import provideHandler
        from zope.container.interfaces import IContainerModifiedEvent
        from zope.container.interfaces import IObjectAddedEvent
        from zope.lifecycleevent.interfaces import IObjectCreatedEvent
        events = []

        @adapter(IObjectCreatedEvent)
        def _handleObjectCreated(event):
            events.append(event)
        provideHandler(_handleObjectCreated)

        @adapter(IObjectWillBeAddedEvent)
        def _handleObjectWillBeAdded(event):
            events.append(event)
        provideHandler(_handleObjectWillBeAdded)

        @adapter(IObjectAddedEvent)
        def _handleObjectAdded(event):
            events.append(event)
        provideHandler(_handleObjectAdded)

        @adapter(IContainerModifiedEvent)
        def _handleContainerModified(event):
            events.append(event)
        provideHandler(_handleContainerModified)

        self.ti.constructInstance(self.f, 'foo')
        self.assertEquals(len(events), 3)

        evt = events[0]
        self.failUnless(IObjectCreatedEvent.providedBy(evt))
        self.assertEquals(evt.object, self.f.foo)

        evt = events[1]
        self.failUnless(IObjectAddedEvent.providedBy(evt))
        self.assertEquals(evt.object, self.f.foo)
        self.assertEquals(evt.oldParent, None)
        self.assertEquals(evt.oldName, None)
        self.assertEquals(evt.newParent, self.f)
        self.assertEquals(evt.newName, 'foo')

        evt = events[2]
        self.failUnless(IContainerModifiedEvent.providedBy(evt))
        self.assertEquals(evt.object, self.f)
Ejemplo n.º 6
0
 def _makeFolder(self, fake_product=0):
     return DummyFolder(fake_product)
Ejemplo n.º 7
0
    def _makeStuff(self, prefix=''):

        ti = FTI('Foo', product='FooProduct', factory='addFoo')
        folder = DummyFolder(fake_product=1, prefix=prefix)

        return ti, folder
Ejemplo n.º 8
0
 def __init__(self, id='', fake_product=0, prefix=''):
     BaseDummyFolder.__init__(self, fake_product, prefix)
     self._id = id
Ejemplo n.º 9
0
 def setUp(self):
     from Products.CMFCore.DirectoryView import registerDirectory
     from Products.CMFCore.DirectoryView import addDirectoryViews
     registerDirectory('fake_skins', _prefix)
     self.ob = DummyFolder()
     addDirectoryViews(self.ob, 'fake_skins', _prefix)
Ejemplo n.º 10
0
def _registerDirectory(self=None):
    registerDirectory('fake_skins', _prefix)
    if self is not None:
        ob = self.ob = DummyFolder()
        addDirectoryViews(ob, 'fake_skins', _prefix)
Ejemplo n.º 11
0
class FTIOldstyleConstructionTests(FTIConstructionTestCase, unittest.TestCase):

    def setUp(self):
        from AccessControl.SecurityManagement import newSecurityManager
        from Products.CMFCore.tests.base.dummy import DummyFolder
        from Products.CMFCore.tests.base.security import UserWithRoles
        self.f = DummyFolder(fake_product=1)
        self.ti = self._makeOne('Foo', product='FooProduct', factory='addFoo')
        newSecurityManager(None, UserWithRoles('FooAdder').__of__(self.f))

    def tearDown(self):
        from AccessControl.SecurityManagement import noSecurityManager
        from zope.testing.cleanup import cleanUp
        cleanUp()
        noSecurityManager()

    def test_constructInstance_w_id_munge(self):
        self.f._prefix = 'majyk'
        self.ti.constructInstance(self.f, 'dust')
        majyk_dust = self.f._getOb('majyk_dust')
        self.assertEqual(majyk_dust.id, 'majyk_dust')

    def test_events(self):
        from OFS.interfaces import IObjectWillBeAddedEvent
        from zope.component import adapter
        from zope.component import provideHandler
        from zope.container.interfaces import IContainerModifiedEvent
        from zope.container.interfaces import IObjectAddedEvent
        from zope.lifecycleevent.interfaces import IObjectCreatedEvent
        events = []

        @adapter(IObjectCreatedEvent)
        def _handleObjectCreated(event):
            events.append(event)
        provideHandler(_handleObjectCreated)

        @adapter(IObjectWillBeAddedEvent)
        def _handleObjectWillBeAdded(event):
            events.append(event)
        provideHandler(_handleObjectWillBeAdded)

        @adapter(IObjectAddedEvent)
        def _handleObjectAdded(event):
            events.append(event)
        provideHandler(_handleObjectAdded)

        @adapter(IContainerModifiedEvent)
        def _handleContainerModified(event):
            events.append(event)
        provideHandler(_handleContainerModified)

        self.ti.constructInstance(self.f, 'foo')
        self.assertEquals(len(events), 3)

        evt = events[0]
        self.failUnless(IObjectCreatedEvent.providedBy(evt))
        self.assertEquals(evt.object, self.f.foo)

        evt = events[1]
        self.failUnless(IObjectAddedEvent.providedBy(evt))
        self.assertEquals(evt.object, self.f.foo)
        self.assertEquals(evt.oldParent, None)
        self.assertEquals(evt.oldName, None)
        self.assertEquals(evt.newParent, self.f)
        self.assertEquals(evt.newName, 'foo')

        evt = events[2]
        self.failUnless(IContainerModifiedEvent.providedBy(evt))
        self.assertEquals(evt.object, self.f)
Ejemplo n.º 12
0
 def setUp(self):
     self.f = DummyFolder(fake_product=1)
     self.ti = self._makeOne('Foo', product='FooProduct', factory='addFoo')
     newSecurityManager(None, UserWithRoles('FooAdder').__of__(self.f))