def test_registerUtilityOnSiteManager(self):
        sm = zapi.getSiteManager()
        self.failUnless(IRegisterUtilitySimply.providedBy(sm))
        dummy = DummyUtility()
        sm.registerUtility(IDummyUtility, dummy, 'dummy')

        self.assertEquals(zapi.getUtility(IDummyUtility, name='dummy'), dummy)
        self.assertEquals(list(zapi.getUtilitiesFor(IDummyUtility)),
                          [('dummy', dummy)])
        self.assertEquals(
            list(zapi.getAllUtilitiesRegisteredFor(IDummyUtility)), [dummy])
Exemple #2
0
    def test_registerUtilityOnSiteManager(self):
        sm = zapi.getSiteManager()
        self.failUnless(IRegisterUtilitySimply.providedBy(sm))
        dummy = DummyUtility()
        sm.registerUtility(IDummyUtility, dummy, 'dummy')

        self.assertEquals(zapi.getUtility(IDummyUtility, name='dummy'), dummy)
        self.assertEquals(list(zapi.getUtilitiesFor(IDummyUtility)), 
                          [('dummy', dummy)])
        self.assertEquals(list(zapi.getAllUtilitiesRegisteredFor(
            IDummyUtility)), [dummy])
    def test_registerTwoUtilitiesWithSameNameDifferentInterface(self):
        sm = zapi.getSiteManager()
        self.failUnless(IRegisterUtilitySimply.providedBy(sm))
        dummy = DummyUtility()
        superdummy = DummyUtility()
        directlyProvides(superdummy, ISuperDummyUtility)
        sm.registerUtility(IDummyUtility, dummy, 'dummy')
        sm.registerUtility(ISuperDummyUtility, superdummy, 'dummy')

        self.assertEquals(zapi.getUtility(IDummyUtility, 'dummy'), dummy)
        self.assertEquals(zapi.getUtility(ISuperDummyUtility, 'dummy'),
                          superdummy)
Exemple #4
0
    def test_registerTwoUtilitiesWithSameNameDifferentInterface(self):
        sm = zapi.getSiteManager()
        self.failUnless(IRegisterUtilitySimply.providedBy(sm))
        dummy = DummyUtility()
        superdummy = DummyUtility()
        directlyProvides(superdummy, ISuperDummyUtility)
        sm.registerUtility(IDummyUtility, dummy, 'dummy')
        sm.registerUtility(ISuperDummyUtility, superdummy, 'dummy')

        self.assertEquals(zapi.getUtility(IDummyUtility, 'dummy'), dummy)
        self.assertEquals(zapi.getUtility(ISuperDummyUtility, 'dummy'),
                          superdummy)
    def test_derivedInterfaceRegistration(self):
        # Utilities providing a derived interface should be listed
        # when you ask for an interface. So ask for IDummmyInterace, and
        # anything registered for IDummyInterface of ISuperDummyInterface
        # should come back.

        sm = zapi.getSiteManager()
        self.failUnless(IRegisterUtilitySimply.providedBy(sm))
        dummy = DummyUtility()
        superdummy = DummyUtility()
        directlyProvides(superdummy, ISuperDummyUtility)
        uts = list(sm.getUtilitiesFor(IDummyUtility))
        self.failUnlessEqual(uts, [])

        sm.registerUtility(ISuperDummyUtility, superdummy)

        # We should be able to access this utility both with
        # IDummyUtility and ISuperDummyUtility interfaces:
        uts = list(sm.getUtilitiesFor(IDummyUtility))
        self.failUnless(uts[0][1].aq_base is superdummy)
        uts = list(sm.getUtilitiesFor(ISuperDummyUtility))
        self.failUnless(uts[0][1].aq_base is superdummy)

        # Also try that the standard zapi call works:
        ut = zapi.getUtility(IDummyUtility, context=self.folder.site)
        self.failUnless(ut.aq_base is superdummy)
        ut = zapi.getUtility(ISuperDummyUtility, context=self.folder.site)
        self.failUnless(ut.aq_base is superdummy)

        # If we register a second utility we should find both utilities
        # when looking for the base interface
        sm.registerUtility(IDummyUtility, dummy)

        uts = list(sm.getAllUtilitiesRegisteredFor(IDummyUtility))
        self.failUnless(dummy in uts)
        self.failUnless(superdummy in uts)

        # But we should find only one when looking for the derived interface
        uts = list(sm.getAllUtilitiesRegisteredFor(ISuperDummyUtility))
        self.failUnless(dummy not in uts)
        self.failUnless(superdummy in uts)
Exemple #6
0
    def test_derivedInterfaceRegistration(self):
        # Utilities providing a derived interface should be listed
        # when you ask for an interface. So ask for IDummmyInterace, and
        # anything registered for IDummyInterface of ISuperDummyInterface
        # should come back.

        sm = zapi.getSiteManager()
        self.failUnless(IRegisterUtilitySimply.providedBy(sm))
        dummy = DummyUtility()
        superdummy = DummyUtility()
        directlyProvides(superdummy, ISuperDummyUtility)
        uts = list(sm.getUtilitiesFor(IDummyUtility))
        self.failUnlessEqual(uts, [])

        sm.registerUtility(ISuperDummyUtility, superdummy)
        
        # We should be able to access this utility both with 
        # IDummyUtility and ISuperDummyUtility interfaces:
        uts = list(sm.getUtilitiesFor(IDummyUtility))
        self.failUnless(uts[0][1].aq_base is superdummy)
        uts = list(sm.getUtilitiesFor(ISuperDummyUtility))
        self.failUnless(uts[0][1].aq_base is superdummy)
        
        # Also try that the standard zapi call works:
        ut = zapi.getUtility(IDummyUtility, context=self.folder.site)
        self.failUnless(ut.aq_base is superdummy)
        ut = zapi.getUtility(ISuperDummyUtility, context=self.folder.site)
        self.failUnless(ut.aq_base is superdummy)
    
        # If we register a second utility we should find both utilities
        # when looking for the base interface
        sm.registerUtility(IDummyUtility, dummy)

        uts = list(sm.getAllUtilitiesRegisteredFor(IDummyUtility))
        self.failUnless(dummy in uts)
        self.failUnless(superdummy in uts)

        # But we should find only one when looking for the derived interface
        uts = list(sm.getAllUtilitiesRegisteredFor(ISuperDummyUtility))
        self.failUnless(dummy not in uts)
        self.failUnless(superdummy in uts)
Exemple #7
0
    def test_migration(self):
        # Migrate from Five.site to Five.component
        
        # Register utilities
        sm = getSiteManager()
        self.failUnless(IRegisterUtilitySimply.providedBy(sm))
        dummy = DummyUtility()
        superdummy = DummyUtility()
        directlyProvides(superdummy, ISuperDummyUtility)
        sm.registerUtility(IDummyUtility, dummy, 'dummy')
        sm.registerUtility(ISuperDummyUtility, superdummy, 'dummy')

        self.assertEquals(zapi.getUtility(IDummyUtility, 'dummy'), dummy)
        self.assertEquals(zapi.getUtility(ISuperDummyUtility, 'dummy'),
                          superdummy)
        
        siteview = self.folder.unrestrictedTraverse('manage_site.html')
        siteview.migrateToFive15()

        self.assert_('utilities' not in self.folder.objectIds())
        # It should still work
        self.assertEquals(zapi.getUtility(IDummyUtility, 'dummy'), dummy)
        self.assertEquals(zapi.getUtility(ISuperDummyUtility, 'dummy'),
                          superdummy)
Exemple #8
0
    def test_migration(self):
        # Migrate from Five.site to Five.component

        # Register utilities
        sm = getSiteManager()
        self.failUnless(IRegisterUtilitySimply.providedBy(sm))
        dummy = DummyUtility()
        superdummy = DummyUtility()
        directlyProvides(superdummy, ISuperDummyUtility)
        sm.registerUtility(IDummyUtility, dummy, 'dummy')
        sm.registerUtility(ISuperDummyUtility, superdummy, 'dummy')

        self.assertEquals(zapi.getUtility(IDummyUtility, 'dummy'), dummy)
        self.assertEquals(zapi.getUtility(ISuperDummyUtility, 'dummy'),
                          superdummy)

        siteview = self.folder.unrestrictedTraverse('manage_site.html')
        siteview.migrateToFive15()

        self.assert_('utilities' not in self.folder.objectIds())
        # It should still work
        self.assertEquals(zapi.getUtility(IDummyUtility, 'dummy'), dummy)
        self.assertEquals(zapi.getUtility(ISuperDummyUtility, 'dummy'),
                          superdummy)