Exemplo n.º 1
0
def run_ddl_as_script():
    parser = setup_parser()
    options, args = parser.parse_args()

    if len(args) != 1:
        parser.print_help()
        sys.exit(1)
        return

    instance_path = args[0]

    global app

    # Enable Faux HTTP request object
    app = spoof_request(app)

    # Get Plone site object from Zope application server root
    site = app.unrestrictedTraverse(instance_path)
    setHooks()
    setSite(site)
    site.setupCurrentSkin(app.REQUEST)

    # Load portal types with enabled IMirroredContent behavior
    loader.load_models(site)

    if options.drop:
        schema.metadata.drop_all()
    if not options.no_create:
        schema.metadata.create_all()
Exemplo n.º 2
0
def CMFDefaultPortal(db=None, connection=None, environ=None):
    """Context manager for working with the Plone portal during layer setup::

        with CMFDefaultPortal() as portal:
            ...

    This is based on the ``z2.zopeApp()`` context manager. See the module
     ``plone.testing.z2`` for details.

    Do not use this in a test. Use the 'portal' resource from the PloneFixture
    layer instead!

    Pass a ZODB handle as ``db`` to use a specificdatabase. Alternatively,
    pass an open connection as ``connection`` (the connection will not be
    closed).
    """

    from zope.site.hooks import setSite, getSite, setHooks
    setHooks()

    site = getSite()

    with z2.zopeApp(db, connection, environ) as app:
        portal = app[SITE_ID]

        setSite(portal)
        z2.login(portal['acl_users'], TEST_USER_ID)

        try:
            yield portal
        finally:
            z2.logout()
            if site is not portal:
                setSite(site)
 def setUp(self):
     portal = self.layer['portal']
     self.portal = portal
     self.request = self.layer['request']
     setRoles(portal, TEST_USER_ID, ['Manager'])
     setHooks()
     setSite(portal)
 def setUp(self):
     portal = self.layer["portal"]
     self.portal = portal
     self.request = self.layer["request"]
     setRoles(portal, TEST_USER_ID, ["Manager"])
     setHooks()
     setSite(portal)
Exemplo n.º 5
0
def _setup(app, site=None):
    """Set up our environment.

    Create a request, log in as admin and set the traversal hooks on the site.

    """
    from Testing import makerequest # Do not import this at the module level!
    app = makerequest.makerequest(app)

    # Login as admin
    admin = app.acl_users.getUserById('admin')
    if admin is None:
        logger.error("No user called `admin` found in the database. "
            "Use --rootpassword to create one.")
        sys.exit(1)

    # Wrap the admin in the right context; from inside the site if we have one
    if site is not None:
        admin = admin.__of__(site.acl_users)
        site = app[site.getId()]
    else:
        admin = admin.__of__(app.acl_users)
    newSecurityManager(None, admin)

    # Set up local site manager, skins and language
    if site is not None:
        setHooks()
        setSite(site)
        site.setupCurrentSkin(site.REQUEST)
        site.REQUEST['HTTP_ACCEPT_LANGUAGE'] = site.Language()

    return (app, site)
Exemplo n.º 6
0
def _get_site(app, args):
    # Zope.Startup.zopectl.ZopeCmd.run_entrypoint promises to pass the entry
    # point's name as the first argument and any further arguments after that,
    # but that does not work with plone.recipe.zope2instance. Using positional
    # arguments therefore is unreliable - resolve to using a flag.
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--plonesite',
        help='Name of the Plone site',
        default=None
    )
    namespace, unused = parser.parse_known_args(args)
    name = namespace.plonesite
    if name is not None:
        if name not in app:
            logger.error("Specified site '%s' not found in database." % name)
            sys.exit(1)
    else:
        from Products.CMFPlone.Portal import PloneSite
        for k, v in app.items():
            if isinstance(v, PloneSite):
                name = k
                break
    if not name:
        logger.error("No Plone site found in database root.")
        sys.exit(1)
    site = getattr(app, name)
    setHooks()
    setSite(site)
    return site
Exemplo n.º 7
0
def pushGlobalRegistry(portal, new=None, name=None):
    """Set a new global component registry that uses the current registry as
    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.

    Also ensure that the persistent component registry at ``portal`` has the
    new global registry as its base.
    """

    from zope.site.hooks import setSite, getSite, setHooks
    site = getSite()

    localSiteManager = portal.getSiteManager()

    current = zca.pushGlobalRegistry(new=new)

    if current not in localSiteManager.__bases__:
        localSiteManager.__bases__ = (current, )

    if site is not None:
        setHooks()
        setSite(site)

    return current
Exemplo n.º 8
0
def _get_site(app, args):
    # Zope.Startup.zopectl.ZopeCmd.run_entrypoint promises to pass the entry
    # point's name as the first argument and any further arguments after that,
    # but that does not work with plone.recipe.zope2instance. Using positional
    # arguments therefore is unreliable - resolve to using a flag.
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--plonesite',
        help='Name of the Plone site',
        default=None
    )
    namespace, unused = parser.parse_known_args(args)
    name = namespace.plonesite
    if name is not None:
        if name not in app:
            logger.error("Specified site '%s' not found in database." % name)
            sys.exit(1)
    else:
        from Products.CMFPlone.Portal import PloneSite
        for k, v in app.items():
            if isinstance(v, PloneSite):
                name = k
                break
    if not name:
        logger.error("No Plone site found in database root.")
        sys.exit(1)
    site = getattr(app, name)
    setHooks()
    setSite(site)
    return site
Exemplo n.º 9
0
    def testSetUp(cls):
        import Products.Five
        import zope.traversing

        zcml.load_config('meta.zcml', Products.Five)
        zcml.load_config('configure.zcml', zope.traversing)
        setHooks()
Exemplo n.º 10
0
    def testSetUp(cls):
        import Zope2.App
        import AccessControl
        import Products.Five
        import Products.GenericSetup
        import Products.CMFCore
        import Products.CMFCore.exportimport

        try:
            zcml.load_config('meta.zcml', Zope2.App)
        except IOError:  # Zope <= 2.12.x
            pass

        zcml.load_config('meta.zcml', Products.Five)

        try:
            zcml.load_config('permissions.zcml', AccessControl)
        except IOError:  # Zope <= 2.12.x
            pass

        zcml.load_config('permissions.zcml', Products.Five)

        zcml.load_config('meta.zcml', Products.GenericSetup)
        zcml.load_config('configure.zcml', Products.GenericSetup)
        zcml.load_config('permissions.zcml', Products.CMFCore)
        zcml.load_config('tool.zcml', Products.CMFCore)
        zcml.load_config('configure.zcml', Products.CMFCore.exportimport)
        zcml.load_string(_DUMMY_ZCML)
        setHooks()
Exemplo n.º 11
0
    def testSetUp(cls):
        import Zope2.App
        import AccessControl
        import Products.Five
        import Products.GenericSetup
        import Products.CMFCore
        import Products.CMFCore.exportimport

        try:
            zcml.load_config('meta.zcml', Zope2.App)
        except IOError:  # Zope <= 2.12.x
            pass

        zcml.load_config('meta.zcml', Products.Five)

        try:
            zcml.load_config('permissions.zcml', AccessControl)
        except IOError:  # Zope <= 2.12.x
            pass

        zcml.load_config('permissions.zcml', Products.Five)

        zcml.load_config('meta.zcml', Products.GenericSetup)
        zcml.load_config('configure.zcml', Products.GenericSetup)
        zcml.load_config('permissions.zcml', Products.CMFCore)
        zcml.load_config('tool.zcml', Products.CMFCore)
        zcml.load_config('configure.zcml', Products.CMFCore.exportimport)
        zcml.load_string(_DUMMY_ZCML)
        setHooks()
Exemplo n.º 12
0
    def testSetUp(cls):
        import Products

        zcml.load_config('meta.zcml', Products.Five)
        zcml.load_config('event.zcml', Products.Five)
        zcml.load_config('event.zcml', Products.CMFCore)
        setHooks()
Exemplo n.º 13
0
    def testSetUp(cls):
        import Products

        zcml.load_config('meta.zcml', Products.Five)
        zcml.load_config('event.zcml', Products.Five)
        zcml.load_config('event.zcml', Products.CMFUid)
        setHooks()
Exemplo n.º 14
0
def silva_session_arg_generator(parent):
    root, options = parent.next()

    if not hasattr(options, 'paths') or not len(options.paths):
        fail(u"specifiy at least one Silva root path")

    for path in options.paths:
        try:
            silva = root.unrestrictedTraverse(path)
        except KeyError:
            fail("%s is not a valid Zope path" % path)
        if not IRoot.providedBy(silva):
            fail("%s is not a valid Silva root" % path)
        if ISite.providedBy(silva):
            setSite(silva)
        else:
            setSite(None)
        setHooks()

        if hasattr(options, 'username') and options.username:
            user = zope_find_user(silva, options.username)
            newSecurityManager(None, user)

        yield silva, options

    try:
        parent.next()
    except StopIteration:
        pass
    else:
        fail(u"internal error")
Exemplo n.º 15
0
def _setup(app, site=None):
    """Set up our environment.

    Create a request, log in as admin and set the traversal hooks on the site.

    """
    from Testing import makerequest # Do not import this at the module level!
    app = makerequest.makerequest(app)

    # Login as admin
    admin = app.acl_users.getUserById('admin')
    if admin is None:
        logger.error("No user called `admin` found in the database. "
            "Use --rootpassword to create one.")
        sys.exit(1)

    # Wrap the admin in the right context; from inside the site if we have one
    if site is not None:
        admin = admin.__of__(site.acl_users)
        site = app[site.getId()]
    else:
        admin = admin.__of__(app.acl_users)
    newSecurityManager(None, admin)

    # Set up local site manager, skins and language
    if site is not None:
        setHooks()
        setSite(site)
        site.setupCurrentSkin(site.REQUEST)
        site.REQUEST['HTTP_ACCEPT_LANGUAGE'] = site.Language()

    return (app, site)
Exemplo n.º 16
0
    def testSetUp(cls):
        import Products.Five
        import zope.traversing

        zcml.load_config('meta.zcml', Products.Five)
        zcml.load_config('configure.zcml', zope.traversing)
        setHooks()
Exemplo n.º 17
0
def pushGlobalRegistry(portal, new=None, name=None):
    """Set a new global component registry that uses the current registry as
    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.

    Also ensure that the persistent component registry at ``portal`` has the
    new global registry as its base.
    """

    from zope.site.hooks import setSite, getSite, setHooks
    site = getSite()

    localSiteManager = portal.getSiteManager()

    current = zca.pushGlobalRegistry(new=new)

    if current not in localSiteManager.__bases__:
        localSiteManager.__bases__ = (current, )

    if site is not None:
        setHooks()
        setSite(site)

    return current
Exemplo n.º 18
0
def ploneSite(db=None, connection=None, environ=None):
    """Context manager for working with the Plone portal during layer setup::

        with ploneSite() as portal:
            ...

    This is based on the ``z2.zopeApp()`` context manager. See the module
     ``plone.testing.z2`` for details.

    Do not use this in a test. Use the 'portal' resource from the PloneFixture
    layer instead!

    Pass a ZODB handle as ``db`` to use a specificdatabase. Alternatively,
    pass an open connection as ``connection`` (the connection will not be
    closed).
    """

    from zope.site.hooks import setSite, getSite, setHooks
    setHooks()

    site = getSite()

    with z2.zopeApp(db, connection, environ) as app:
        portal = app[PLONE_SITE_ID]

        setSite(portal)
        login(portal, TEST_USER_NAME)

        try:
            yield portal
        finally:
            logout()
            if site is not portal:
                setSite(site)
Exemplo n.º 19
0
 def setUp(self):
     self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'),
                                            name=self.__name__)
     name = self.__name__ if self.__name__ is not None else 'not-named'
     contextName = "PloneSandboxLayer-%s" % name
     self['configurationContext'] = configurationContext = (
         zca.stackConfigurationContext(self.get('configurationContext'),
                                       name=contextName))
     # call ploneSite() for all pages in dict.
     plone_site_ids = [PLONE_SITE_ID]
     plone_site_ids.extend(additional_page['page_id']
                           for additional_page in ADDITIONAL_PAGES_TO_SETUP)
     for plone_site_id in plone_site_ids:
         with self.ploneSite(plone_site_id) as portal:
             from zope.site.hooks import setSite, setHooks
             setHooks()
             setSite(None)
             pushGlobalRegistry(portal)
             security.pushCheckers()
             from Products.PluggableAuthService.PluggableAuthService import (
                 MultiPlugins)
             preSetupMultiPlugins = MultiPlugins[:]
             self.setUpZope(portal.getPhysicalRoot(), configurationContext)
             setSite(portal)
             self.setUpPloneSite(portal)
             setSite(None)
         self.snapshotMultiPlugins(preSetupMultiPlugins)
Exemplo n.º 20
0
    def setUp(cls):
        import Products

        zcml._initialized = 0
        zcml.load_site()
        setHooks()
        component.provideHandler(eventlog.trace, (ITestItem, IObjectEvent))
        component.provideHandler(eventlog.trace, (IRelationship, IObjectEvent))
Exemplo n.º 21
0
    def setUp(cls):
        import Products

        zcml._initialized = 0
        zcml.load_site()
        setHooks()
        component.provideHandler(eventlog.trace, (ITestItem, IObjectEvent))
        component.provideHandler(eventlog.trace, (IRelationship, IObjectEvent))
Exemplo n.º 22
0
 def afterSetUp(self):
     setHooks()
     setSite(self.portal)
     self.manager = getUtility(IPortletManager, name=u'plone.leftcolumn')
     self.cat = self.manager[USER_CATEGORY]
     self.cat[user_name] = PortletAssignmentMapping(manager=u'plone.leftcolumn',
                                                    category=USER_CATEGORY,
                                                    name=user_name)
Exemplo n.º 23
0
 def setUp(self):
     self.portal = self.layer['portal']
     self.request = self.layer['request']
     setRoles(self.portal, TEST_USER_ID, ['Manager'])
     setHooks()
     # Make sure News Items use simple_publication_workflow
     self.portal.portal_workflow.setChainForPortalTypes(
         ['News Item'], ['simple_publication_workflow'])
Exemplo n.º 24
0
 def afterSetUp(self):
     setHooks()
     setSite(self.portal)
     self.setRoles(('Manager'), )
     self.portal.invokeFactory('Document', 'doc1')
     self.portal.invokeFactory('Document', 'doc2')
     self.portal.portal_membership.getMemberById('test_user_1_').setMemberProperties(
                                 {'fullname': 'Test user'})
Exemplo n.º 25
0
 def setUp(self):
     self.portal = self.layer['portal']
     self.request = self.layer['request']
     setRoles(self.portal, TEST_USER_ID, ['Manager'])
     setHooks()
     # Make sure News Items use simple_publication_workflow
     self.portal.portal_workflow.setChainForPortalTypes(
         ['News Item'], ['simple_publication_workflow'])
Exemplo n.º 26
0
 def afterSetUp(self):
     setHooks()
     setSite(self.portal)
     self.setRoles(('Manager', ))
     portal_setup = self.portal.portal_setup
     # wait a bit or we get duplicate ids on import
     time.sleep(0.2)
     portal_setup.runAllImportStepsFromProfile('profile-plone.app.portlets:z3ctesting')
Exemplo n.º 27
0
def _placefulSetUp(portal):
    '''Sets the local site/manager.'''
    try:
        from zope.site.hooks import setHooks, setSite
    except ImportError:
        from zope.app.component.hooks import setHooks, setSite
    setHooks()
    setSite(portal)
Exemplo n.º 28
0
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-%d' % 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.site.hooks import setSite, setHooks
    except ImportError:
        pass
    else:
        setSite()
        setHooks()

    return new
Exemplo n.º 29
0
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-%d' % 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.site.hooks import setSite, setHooks
    except ImportError:
        pass
    else:
        setSite()
        setHooks()

    return new
Exemplo n.º 30
0
 def afterSetUp(self):
     setHooks()
     setSite(self.portal)
     self.setRoles(('Manager', ))
     portal_setup = self.portal.portal_setup
     # wait a bit or we get duplicate ids on import
     time.sleep(0.2)
     portal_setup.runAllImportStepsFromProfile(
         'profile-plone.app.portlets:z3ctesting')
Exemplo n.º 31
0
 def setUp(self):
     BaseRegistryTests.setUp(self)
     setHooks()
     self.root.site = Folder(id='site')
     self.site = self.root.site
     make_objectmanager_site(self.site)
     setSite(self.site)
     sm = getSiteManager(self.site)
     sm.registerUtility(ViewletSettingsStorage(), IViewletSettingsStorage)
     self.storage = getUtility(IViewletSettingsStorage)
Exemplo n.º 32
0
def setUp(app):
    # enable zcml and site hooks
    placeless.setUp()
    import Products.Five
    from five import intid
    zcml.load_config('meta.zcml', Products.Five)
    zcml.load_config('configure.zcml', Products.Five)
    zcml.load_config('configure.zcml', intid)
    zcml.load_config('test.zcml', intid)
    setHooks()
Exemplo n.º 33
0
    def __init__(self, portal, admin):
        root = makerequest.makerequest(app)
        self.portal = getattr(root, portal, None)

        admin = root.acl_users.getUserById(admin)
        admin = admin.__of__(self.portal.acl_users)
        newSecurityManager(None, admin)
        setHooks()
        setSite(self.portal)
        self.portal.setupCurrentSkin(self.portal.REQUEST)
Exemplo n.º 34
0
 def close(self):
     if self.__result is not None:
         if hasattr(self.__result, 'close'):
             self.__result.close()
     if self.__site is not None:
         setSite(self.__site)
         setHooks()
     if self.__security is not None:
         setSecurityManager(self.__security)
     self.connection.sync()
Exemplo n.º 35
0
    def testSetUp(cls):
        import OFS
        import Products

        zcml.load_config('meta.zcml', Products.Five)
        try:
            zcml.load_config('event.zcml', OFS)
        except IOError:  # Zope <= 2.12.x
            zcml.load_config('event.zcml', Products.Five)
        zcml.load_config('event.zcml', Products.CMFCore)
        setHooks()
Exemplo n.º 36
0
    def setUp(self):
        provideAdapter(SharingXMLAdapter, name='plone.app.workflow.sharing')

        site = Folder('plone')
        make_objectmanager_site(site)
        setHooks()
        setSite(site)
        sm = getSiteManager()

        self.site = site
        self.sm = sm
Exemplo n.º 37
0
    def testSetUp(self):
        super(SilvaLayer, self).testSetUp()

        # Get the Silva Root and set it as a local site
        app = super(SilvaLayer, self).get_application()
        self._silva_root = app.root
        setSite(self._silva_root)
        setHooks()

        # List of created browsers
        self._browsers = []
Exemplo n.º 38
0
    def testSetUp(self):
        super(SilvaLayer, self).testSetUp()

        # Get the Silva Root and set it as a local site
        app = super(SilvaLayer, self).get_application()
        self._silva_root = app.root
        setSite(self._silva_root)
        setHooks()

        # List of created browsers
        self._browsers = []
Exemplo n.º 39
0
def setUp(test):
    testing.setUp(test)
    provideAdapter(DefaultTraversable, (None, ))
    provideAdapter(BrowserLanguages)
    provideAdapter(HTTPCharsets)

    import Products.Five
    import five.customerize
    load_config('configure.zcml', package=Products.Five)
    load_config('configure.zcml', package=five.customerize)
    setHooks()
    def setUp(self):
        portal = self.layer['portal']
        self.portal = portal
        self.request = self.layer['request']
        self.wft = getToolByName(self.portal, 'portal_workflow')
        setRoles(portal, TEST_USER_ID, ['Manager'])
        setHooks()
        setSite(portal)

        # Make sure Events use simple_publication_workflow
        self.portal.portal_workflow.setChainForPortalTypes(['Event'], ['simple_publication_workflow'])
Exemplo n.º 41
0
    def setUp(self):
        setHooks()
        self.site = Folder('site')
        make_objectmanager_site(self.site)
        setSite(self.site)
        sm = getSiteManager()
        sm.registerUtility(ViewletSettingsStorage(), IViewletSettingsStorage)

        self._obj = getUtility(IViewletSettingsStorage)

        self._BODY = _VIEWLETS_XML
Exemplo n.º 42
0
    def setUp(self):
        setHooks()
        self.site = Folder('site')
        make_objectmanager_site(self.site)
        setSite(self.site)
        sm = getSiteManager()
        self.site.portal_control_panel = PloneControlPanel()
        sm.registerUtility(self.site.portal_control_panel, IControlPanel)

        self._obj = self.site.portal_control_panel
        self._BODY = _CONTROLPANEL_XML
Exemplo n.º 43
0
    def setUp(self):
        provideAdapter(SharingXMLAdapter, name='plone.app.workflow.sharing')

        site = Folder('plone')
        make_objectmanager_site(site)
        setHooks()
        setSite(site)
        sm = getSiteManager()

        self.site = site
        self.sm = sm
Exemplo n.º 44
0
    def setUp(self):
        setHooks()
        self.site = Folder('site')
        make_objectmanager_site(self.site)
        setSite(self.site)
        sm = getSiteManager()
        self.site.portal_control_panel = PloneControlPanel()
        sm.registerUtility(self.site.portal_control_panel, IControlPanel)

        self._obj = self.site.portal_control_panel
        self._BODY = _CONTROLPANEL_XML
Exemplo n.º 45
0
def setUp(test):
    testing.setUp(test)
    provideAdapter(DefaultTraversable, (None,))
    provideAdapter(BrowserLanguages)
    provideAdapter(HTTPCharsets)

    import Products.Five
    import five.customerize
    load_config('configure.zcml', package=Products.Five)
    load_config('configure.zcml', package=five.customerize)
    setHooks()
Exemplo n.º 46
0
    def testSetUp(cls):
        import OFS
        import Products

        zcml.load_config('meta.zcml', Products.Five)
        try:
            zcml.load_config('event.zcml', OFS)
        except IOError:  # Zope <= 2.12.x
            zcml.load_config('event.zcml', Products.Five)
        zcml.load_config('event.zcml', Products.CMFCore)
        setHooks()
    def setUp(self):
        setHooks()
        self.site = Folder('site')
        make_objectmanager_site(self.site)
        setSite(self.site)
        sm = getSiteManager()
        self.site.portal_types = DummyTypesTool()
        sm.registerUtility(self.site.portal_types, ITypesTool)
        self.site.portal_factory = FactoryTool()

        self._obj = self.site.portal_factory
        self._BODY = _FACTORYTOOL_XML
Exemplo n.º 48
0
    def upgrade(self, root):
        # If it's a Five site manager disable it first. The annoying
        # part might be that the code might already have been removed
        # from Zope ...
        setattr(root, '__initialization__', True)
        if ISite.providedBy(root):
            sm = root.getSiteManager()
            if ((IFiveSiteManager is not None and
                 IFiveSiteManager.providedBy(sm)) or
                isinstance(sm, ZODB.broken.Broken)):
                setSite(None)
                setHooks()
                unregisterBeforeTraverse(aq_base(root), '__local_site_hook__')
                if hasattr(aq_base(root), '__local_site_hook__'):
                    delattr(aq_base(root), '__local_site_hook__')
                zope.interface.noLongerProvides(root, ISite)
                root.setSiteManager(None)
            else:
                # Cleanup broken utilities
                for registration in list(sm.registeredUtilities()):
                    if isinstance(registration.component, ZODB.broken.Broken):
                        sm.unregisterUtility(
                            registration.component,
                            registration.provided)

        # Activate local site, add an intid service.
        ism = interfaces.ISiteManager(root)
        if not ism.is_site():
            ism.make_site()
        setSite(root)
        setHooks()

        # Delete unused Silva Document service
        for s in ['service_doc_previewer',
                  'service_nlist_previewer',
                  'service_sub_previewer',]:
            if hasattr(root, s):
                root.manage_delObjects([s,])

        # Update service_files settings
        service_files = root.service_files
        if hasattr(aq_base(service_files), '_filesystem_storage_enabled'):
            service_files.storage = BlobFile
            delattr(service_files , '_filesystem_storage_enabled')
        elif service_files.storage is not BlobFile:
            # For the upgrade
            service_files.storage = BlobFile

        # Disable quota verification (but not accounting if this
        # enabled) during the migration, so the file migration can
        # safely happens.
        root.service_extensions._quota_verify = False
        return root
Exemplo n.º 49
0
    def setUp(self):
        setHooks()
        self.site = Folder('site')
        make_objectmanager_site(self.site)
        setSite(self.site)
        sm = getSiteManager()
        self.site.portal_types = DummyTypesTool()
        sm.registerUtility(self.site.portal_types, ITypesTool)
        self.site.portal_factory = FactoryTool()

        self._obj = self.site.portal_factory
        self._BODY = _FACTORYTOOL_XML
Exemplo n.º 50
0
    def setUp(self):
        try:
            # Push a new database storage so that database changes
            # commited during layer setup can be easily torn down
            self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'),
                    name=self.__name__)

            # Push a new configuration context so that it's possible to re-import
            # ZCML files after tear-down
            name = self.__name__ if self.__name__ is not None else 'not-named'
            contextName = "PloneSandboxLayer-%s" % name
            self['configurationContext'] = configurationContext = (
                zca.stackConfigurationContext(self.get('configurationContext'),
                name=contextName))

            with ploneSite() as portal:

                from zope.site.hooks import setSite, setHooks
                setHooks()

                # Make sure there's no local site manager while we load ZCML
                setSite(None)

                # Push a new component registry so that ZCML registations
                # and other global component registry changes are sandboxed
                pushGlobalRegistry(portal)

                # Make sure zope.security checkers can be set up and torn down
                # reliably

                security.pushCheckers()

                from Products.PluggableAuthService.PluggableAuthService import (
                        MultiPlugins)

                preSetupMultiPlugins = MultiPlugins[:]

                # Allow subclass to load ZCML and products
                self.setUpZope(portal.getPhysicalRoot(), configurationContext)

                # Allow subclass to configure a persistent fixture
                setSite(portal)
                self.setUpPloneSite(portal)
                setSite(None)

            # Keep track of PAS plugins that were added during setup
            self.snapshotMultiPlugins(preSetupMultiPlugins)
        except:
            del self['configurationContext']
            self['zodbDB'].close()
            del self['zodbDB']
            raise
Exemplo n.º 51
0
 def setUp(cls):
     import zope.component
     import OFS
     import Products.Five
     zcml.load_config('meta.zcml', zope.component)
     try:
         zcml.load_config('meta.zcml', OFS)
         zcml.load_config('configure.zcml', OFS)
     except IOError:  # Zope <= 2.13.0a2
         zcml.load_config('meta.zcml', Products.Five)
     # In Zope 2.12 this does an implicit commit
     installPackage('OFS')
     setHooks()
Exemplo n.º 52
0
 def ploneSite(self, plone_site_id, db=None, connection=None, environ=None):
     from zope.site.hooks import setSite, getSite, setHooks
     setHooks()
     site = getSite()
     with z2.zopeApp(db, connection, environ) as app:
         portal = app[plone_site_id]
         setSite(portal)
         login(portal, TEST_USER_NAME)
         try:
             yield portal
         finally:
             logout()
             if site is not portal:
                 setSite(site)
Exemplo n.º 53
0
    def afterSetUp(self):
        setHooks()
        setSite(self.portal)
        self.setRoles(('Manager'), )
        self.portal.invokeFactory('Document', 'doc1')
        self.portal.invokeFactory('Document', 'doc2')
        self.portal.portal_membership.getMemberById('test_user_1_').setMemberProperties(
                                    {'fullname': 'Test user'})

        # add Folder and assign Reviewer role to our Test user there
        self.portal.invokeFactory('Folder', 'folder1')
        self.folder1 = self.portal.folder1
        self.folder1.manage_setLocalRoles('test_user_1_', ['Reviewer'])
        self.folder1.reindexObjectSecurity()
Exemplo n.º 54
0
    def testSetUp(cls):
        import Products.Five
        import Products.GenericSetup
        import Products.CMFCore
        import Products.CMFCore.exportimport

        zcml.load_config('meta.zcml', Products.Five)
        zcml.load_config('meta.zcml', Products.GenericSetup)
        zcml.load_config('permissions.zcml', Products.Five)
        zcml.load_config('meta.zcml', Products.GenericSetup)
        zcml.load_config('configure.zcml', Products.GenericSetup)
        zcml.load_config('tool.zcml', Products.CMFCore)
        zcml.load_config('configure.zcml', Products.CMFCore.exportimport)
        zcml.load_string(_DUMMY_ZCML)
        setHooks()
Exemplo n.º 55
0
    def setUp(self):
        testing.setUp()
        eventtesting.setUp()
        traversingSetUp()
        setHooks()
        provideAdapter(ContainerTraversable, (ISimpleReadContainer, ),
                       ITraversable)
        provideAdapter(SiteManagerAdapter, (Interface, ), IComponentLookup)

        self.root = rootFolder()
        createSiteManager(self.root, setsite=True)

        provideAdapter(connectionOfPersistent, (IPersistent, ), IConnection)
        provideAdapter(KeyReferenceToPersistent, (IPersistent, ),
                       IKeyReference)
Exemplo n.º 56
0
    def __init__(self, portal, admin, news_site, dataType):
        root = makerequest.makerequest(app)
        self.portal = getattr(root, portal, None)
        self.news_site = news_site_code.get(news_site, None)
        if self.portal is None or self.news_site is None:
            logger.error('lost or wrong argv!')
            exit()

        admin = root.acl_users.getUserById(admin)
        admin = admin.__of__(self.portal.acl_users)
        newSecurityManager(None, admin)
        setHooks()
        setSite(self.portal)
        self.portal.setupCurrentSkin(self.portal.REQUEST)

        self.dataType = dataType
Exemplo n.º 57
0
 def update(self, value):
     """Update the quota.
     """
     service = self._site.service_extensions
     if value > 0:
         service._site_quota = value
         if not service.get_quota_subsystem_status():
             try:
                 setSite(self._site)
                 setHooks()
                 service.enable_quota_subsystem()
             finally:
                 setSite(None)
                 setHooks()
     else:
         service._site_quota = 0
Exemplo n.º 58
0
    def setUp(self):
        # Create and enable a local component registry
        site = Folder()
        createComponentRegistry(site)
        setHooks()
        setSite(site)
        sm = getSiteManager()

        tool = DummyTool()
        site._setObject(tool.id, tool)

        tool2 = DummyTool2()
        site._setObject(tool2.id, tool2)

        self._obj = sm
        self._BODY = _COMPONENTS_BODY