当前位置: 首页>>代码示例>>Python>>正文


Python hooks.setHooks函数代码示例

本文整理汇总了Python中zope.component.hooks.setHooks函数的典型用法代码示例。如果您正苦于以下问题:Python setHooks函数的具体用法?Python setHooks怎么用?Python setHooks使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setHooks函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_global_components_not_unregistered_on_delete

    def test_global_components_not_unregistered_on_delete(self):
        portal_type = u"testtype"
        fti = DexterityFTI(portal_type)
        container_dummy = self.create_dummy()

        # Mock the lookup of the site and the site manager at the site root
        dummy_site = self.create_dummy()
        self.mock_utility(dummy_site, ISiteRoot)

        site_manager_mock = self.mocker.proxy(PersistentComponents(bases=(getGlobalSiteManager(),)))
        getSiteManager_mock = self.mocker.replace("zope.component.hooks.getSiteManager")
        self.expect(getSiteManager_mock(dummy_site)).result(site_manager_mock)

        # Register FTI utility and factory utility

        self.mock_utility(fti, IDexterityFTI, name=portal_type)
        self.mock_utility(DexterityFactory(portal_type), IFactory, name=portal_type)

        # We expect to always be able to unregister without error, even if the
        # component exists. The factory is only unregistered if it was registered
        # with info='plone.dexterity.dynamic'.

        self.expect(site_manager_mock.unregisterUtility(provided=IDexterityFTI, name=portal_type)).passthrough()

        self.replay()

        ftiRemoved(fti, ObjectRemovedEvent(fti, container_dummy, fti.getId()))

        site_dummy = self.create_dummy(getSiteManager=lambda: site_manager_mock)
        setSite(site_dummy)
        setHooks()

        self.assertNotEquals(None, queryUtility(IDexterityFTI, name=portal_type))
        self.assertNotEquals(None, queryUtility(IFactory, name=portal_type))
开发者ID:numahell,项目名称:plone.dexterity,代码行数:34,代码来源:test_fti.py

示例2: __call__

    def __call__(self, config_file, run_as, server_url=None, context_path=None,
                 portal_id=None, **environ):
        Zope2.Startup.run.configure(config_file)
        environ['SERVER_URL'] = server_url
        self.app = makerequest(Zope2.app(), environ=environ)
        setHooks()
        if portal_id is not None:
            self.portal = self.app[portal_id]
        else:
            portals = self.app.objectValues('Plone Site')
            if len(portals) > 1:
                log.warn('More than one portal - using first one')
            self.portal = portals[0]
        setSite(self.portal)
        self.app.REQUEST.other['PARENTS'] = [self.portal, self.app]
        self.app.REQUEST.other['VirtualRootPhysicalPath'] = (
            '', self.portal.id)

        log.setLevel(logging.INFO)
        handler = logging.StreamHandler(sys.stdout)
        formatter = logging.Formatter(
            "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
        handler.setFormatter(formatter)
        log.addHandler(handler)

        with api.env.adopt_user(username=run_as):
            if context_path is not None:
                self.context = self.portal.restrictedTraverse(context_path)
            else:
                self.context = self.portal
            self.run()
        transaction.commit()
开发者ID:syslabcom,项目名称:slc.zopescript,代码行数:32,代码来源:script.py

示例3: test_components_unregistered_on_delete

    def test_components_unregistered_on_delete(self):
        portal_type = u"testtype"
        fti = DexterityFTI(portal_type)
        container_dummy = self.create_dummy()

        # Mock the lookup of the site and the site manager at the site root
        dummy_site = self.create_dummy()
        self.mock_utility(dummy_site, ISiteRoot)

        site_manager_mock = self.mocker.proxy(PersistentComponents(bases=(getGlobalSiteManager(),)))
        getSiteManager_mock = self.mocker.replace("zope.component.hooks.getSiteManager")
        self.expect(getSiteManager_mock(dummy_site)).result(site_manager_mock).count(1, None)

        # We expect to always be able to unregister without error, even if the
        # components do not exists (as here)

        self.expect(site_manager_mock.unregisterUtility(provided=IDexterityFTI, name=portal_type)).passthrough()
        self.expect(site_manager_mock.unregisterUtility(provided=IFactory, name=portal_type)).passthrough()

        self.replay()

        # First add the components
        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))

        # Then remove them again
        ftiRemoved(fti, ObjectRemovedEvent(fti, container_dummy, fti.getId()))

        site_dummy = self.create_dummy(getSiteManager=lambda: site_manager_mock)
        setSite(site_dummy)
        setHooks()

        self.assertEquals(None, queryUtility(IDexterityFTI, name=portal_type))
        self.assertEquals(None, queryUtility(IFactory, name=portal_type))
开发者ID:numahell,项目名称:plone.dexterity,代码行数:33,代码来源:test_fti.py

示例4: test_components_unregistered_on_delete

    def test_components_unregistered_on_delete(self):
        portal_type = u"testtype"
        fti = DexterityFTI(portal_type)
        container_dummy = self.create_dummy()

        # Mock the lookup of the site and the site manager at the site root
        dummy_site = self.create_dummy()
        self.mock_utility(dummy_site, ISiteRoot)

        site_manager_mock = Mock(
            wraps=PersistentComponents(bases=(getGlobalSiteManager(),)))
        from zope.component.hooks import getSiteManager
        self.patch_global(getSiteManager, return_value=site_manager_mock)

        # First add the components
        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))

        # Then remove them again
        ftiRemoved(fti, ObjectRemovedEvent(fti, container_dummy, fti.getId()))

        site_dummy = self.create_dummy(
            getSiteManager=lambda: site_manager_mock
        )
        setSite(site_dummy)
        setHooks()

        self.assertEqual(None, queryUtility(IDexterityFTI, name=portal_type))
        self.assertEqual(None, queryUtility(IFactory, name=portal_type))
开发者ID:plone,项目名称:plone.dexterity,代码行数:28,代码来源:test_fti.py

示例5: test_components_registered_on_add

    def test_components_registered_on_add(self):
        portal_type = u"testtype"
        fti = DexterityFTI(portal_type)
        container_dummy = self.create_dummy()
        
        # Mock the lookup of the site and the site manager at the site root
        dummy_site = self.create_dummy()
        self.mock_utility(dummy_site, ISiteRoot)
        
        site_manager_mock = self.mocker.proxy(PersistentComponents(bases=(getGlobalSiteManager(),)))
        getSiteManager_mock = self.mocker.replace('zope.component.hooks.getSiteManager')
        self.expect(getSiteManager_mock(dummy_site)).result(site_manager_mock)
        
        # We expect that no components are registered , so look for all registrations
        self.expect(site_manager_mock.registerUtility(fti, IDexterityFTI, portal_type, info='plone.dexterity.dynamic')).passthrough()
        self.expect(site_manager_mock.registerUtility(
                    mocker.MATCH(lambda x: isinstance(x, DexterityFactory) and x.portal_type == portal_type), 
                    IFactory, portal_type, info='plone.dexterity.dynamic')).passthrough()

        self.replay()
        
        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))
        
        site_dummy = self.create_dummy(getSiteManager = lambda: site_manager_mock)
        setSite(site_dummy)
        setHooks()
        
        self.assertNotEquals(None, queryUtility(IDexterityFTI, name=portal_type))
        self.assertNotEquals(None, queryUtility(IFactory, name=portal_type))
开发者ID:eleddy,项目名称:plone.dexterity,代码行数:29,代码来源:test_fti.py

示例6: test_components_reregistered_on_rename

    def test_components_reregistered_on_rename(self):
        portal_type = u"testtype"
        fti = DexterityFTI(portal_type)
        container_dummy = self.create_dummy()
        
        # Mock the lookup of the site and the site manager at the site root
        dummy_site = self.create_dummy()
        self.mock_utility(dummy_site, ISiteRoot)
        
        site_manager_mock = self.mocker.proxy(PersistentComponents(bases=(getGlobalSiteManager(),)))
        getSiteManager_mock = self.mocker.replace('zope.component.hooks.getSiteManager')
        self.expect(getSiteManager_mock(dummy_site)).result(site_manager_mock).count(1,None)
        
        # First look for unregistration of all local components
        
        self.expect(site_manager_mock.unregisterUtility(provided=IDexterityFTI, name=portal_type)).passthrough()        
        
        # Then look for re-registration of global components
        self.expect(site_manager_mock.registerUtility(fti, IDexterityFTI, portal_type, info='plone.dexterity.dynamic')).passthrough()
        self.expect(site_manager_mock.registerUtility(
                    mocker.MATCH(lambda x: isinstance(x, DexterityFactory) and x.portal_type == portal_type), 
                    IFactory, portal_type, info='plone.dexterity.dynamic')).passthrough()

        self.assertEquals('string:${folder_url}/++add++testtype', fti.add_view_expr)

        self.replay()
        
        ftiRenamed(fti, ObjectMovedEvent(fti, container_dummy, fti.getId(), container_dummy, u"newtype"))
        
        site_dummy = self.create_dummy(getSiteManager = lambda: site_manager_mock)
        setSite(site_dummy)
        setHooks()
        
        self.assertNotEquals(None, queryUtility(IDexterityFTI, name=portal_type))
        self.assertNotEquals(None, queryUtility(IFactory, name=portal_type))
开发者ID:eleddy,项目名称:plone.dexterity,代码行数:35,代码来源:test_fti.py

示例7: testSetUp

    def testSetUp(cls):
        import Products.Five
        import zope.traversing

        zcml.load_config('meta.zcml', Products.Five)
        zcml.load_config('configure.zcml', zope.traversing)
        setHooks()
开发者ID:zopefoundation,项目名称:Products.CMFCore,代码行数:7,代码来源:testing.py

示例8: setUp

def setUp(test):
    from zope.component.testing import setUp
    setUp()
    from zope.container.testing import setUp
    setUp()
    from zope.component import hooks
    hooks.setHooks()
    from zope.traversing.testing import setUp
    setUp()

    from zope.publisher.browser import BrowserLanguages
    from zope.publisher.interfaces.http import IHTTPRequest
    from zope.i18n.interfaces import IUserPreferredLanguages
    zope.component.provideAdapter(BrowserLanguages, [IHTTPRequest],
                   IUserPreferredLanguages)

    from zope.site.folder import rootFolder
    site = rootFolder()
    from zope.site.site import LocalSiteManager
    from zope.component.interfaces import ISite
    if not ISite.providedBy(site):
        site.setSiteManager(LocalSiteManager(site))
    hooks.setSite(site)
    test.globs = {
        'print_function': print_function,
        'root': site,
        'pprint': pprint.pprint}
开发者ID:zopefoundation,项目名称:z3c.form,代码行数:27,代码来源:testing.py

示例9: setUp

def setUp(self):
    """Test setUp based on z3c.form.testing.setUp minus their globals.
    """
    from zope.component.testing import setUp
    setUp()
    from zope.container.testing import setUp
    setUp()
    from zope.component import hooks
    hooks.setHooks()
    from zope.traversing.testing import setUp
    setUp()

    from zope.publisher.browser import BrowserLanguages
    from zope.publisher.interfaces.http import IHTTPRequest
    from zope.i18n.interfaces import IUserPreferredLanguages
    import zope.component
    zope.component.provideAdapter(
        BrowserLanguages, [IHTTPRequest], IUserPreferredLanguages)

    from zope.site.folder import rootFolder
    site = rootFolder()
    from zope.site.site import LocalSiteManager
    from zope.component.interfaces import ISite
    if not ISite.providedBy(site):
        site.setSiteManager(LocalSiteManager(site))
    hooks.setSite(site)
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:26,代码来源:tests.py

示例10: setUp

 def setUp(self):
     portal = self.layer['portal']
     self.portal = portal
     self.request = self.layer['request']
     setRoles(portal, TEST_USER_ID, ['Manager'])
     setHooks()
     setSite(portal)
开发者ID:plone,项目名称:plone.app.event,代码行数:7,代码来源:test_portlet_calendar.py

示例11: pushGlobalRegistry

def pushGlobalRegistry(new=None):
    """Set a new global component registry that uses the current registry as
    a a base. If you use this, you *must* call ``popGlobalRegistry()`` to
    restore the original state.

    If ``new`` is not given, a new registry is created. If given, you must
    provide a ``zope.component.globalregistry.BaseGlobalComponents`` object.

    Returns the new registry.
    """

    from zope.component import globalregistry

    # Save the current top of the stack in a registry
    current = globalregistry.base

    # The first time we're called, we need to put the default global
    # registry at the bottom of the stack, and then patch the class to use
    # the stack for loading pickles. Otherwise, we end up with POSKey and
    # pickling errors when dealing with persistent registries that have the
    # global registry (globalregistry.base) as a base

    if len(_REGISTRIES) == 0:
        _REGISTRIES.append(current)
        globalregistry.BaseGlobalComponents._old__reduce__ = (
            globalregistry.BaseGlobalComponents.__reduce__)
        globalregistry.BaseGlobalComponents.__reduce__ = (
            lambda self: (loadRegistry, (self.__name__,)))

    if new is None:
        name = 'test-stack-{0}'.format(len(_REGISTRIES))
        new = globalregistry.BaseGlobalComponents(name=name, bases=(current,))
        logger.debug(
            'New component registry: %s based on %s',
            name,
            current.__name__)
    else:
        logger.debug('Push component registry: %s', new.__name__)

    _REGISTRIES.append(new)

    # Monkey patch this into the three (!) places where zope.component
    # references it as a module global variable
    _hookRegistry(new)

    # Reset the site manager hook so that getSiteManager() returns the base
    # again
    from zope.component import getSiteManager
    getSiteManager.reset()

    try:
        from zope.component.hooks import setSite, setHooks
    except ImportError:
        pass
    else:
        setSite()
        setHooks()

    return new
开发者ID:plone,项目名称:plone.testing,代码行数:59,代码来源:zca.py

示例12: _placefulSetUp

def _placefulSetUp(portal):
    '''Sets the local site/manager.'''
    try:
        from zope.component.hooks import setHooks, setSite
    except ImportError:
        from zope.app.component.hooks import setHooks, setSite
    setHooks()
    setSite(portal)
开发者ID:plone,项目名称:Products.PloneTestCase,代码行数:8,代码来源:setup.py

示例13: testSetUp

    def testSetUp(cls):
        import Products
        import OFS

        zcml.load_config('meta.zcml', Products.Five)
        zcml.load_config('event.zcml', OFS)
        zcml.load_config('event.zcml', Products.CMFUid)
        setHooks()
开发者ID:zopefoundation,项目名称:Products.CMFUid,代码行数:8,代码来源:testing.py

示例14: setUp

 def setUp(self):
     setHooks()
     context = config.ConfigurationMachine()
     xmlconfig.registerCommonDirectives(context)
     for feature in self.features:
         context.provideFeature(feature)
     self.context = self._load_zcml(context)
     provideHandler(events.append, (None,))
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:8,代码来源:testlayer.py

示例15: __init__

    def __init__(self, paster_variables):
        setHooks()

        self.paster = toargs(self, IPasterVariables, paster_variables)

        getGlobalSiteManager().registerUtility(provided=IConfiguration,
            component=self)
        
        load_configuration(self.paster['configure_zcml'])
开发者ID:avnik,项目名称:nanozope,代码行数:9,代码来源:config.py


注:本文中的zope.component.hooks.setHooks函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。