Second plone site on PloneTestCase.PloneTestCase.FunctionalTestCase

Ross Patterson me at rpatterson.net
Thu Nov 1 20:48:13 UTC 2007


Dirceu Pereira Tiegs
<dirceutiegs at gmail.com> writes:

> I need to use a second Plone Site on a FunctionalTestCase. I'm trying
> to do as follows:
>
> def setupNoticias(self):
>     from fixtures.noticias import noticias
>     self.setRoles(['Manager','Owner'])
>     zope_root = self.portal.aq_inner.aq_parent
>     zope_root.manage_addProduct['CMFPlone'].addPloneSite('noticias',
> create_userfolder=1, snapshot=0, profile_id='CMFPlone:plone')
>     portal_noticias = getattr(zope_root, 'noticias')

You could just call:

    PloneTestCase.setupPloneSite(id='noticias')

at the module level, then when the Plone layer is setup, the portal will
be added.

> The traceback is:
>
> File
> "/Users/dirceu/devel/zope298/Products/SebraeConfigurador/tests/test_associacao.py",
> line 75, in
> Products.SebraeConfigurador.tests.test_associacao.test_associacao_noticias
> Failed example:
>     setupNoticias(self)
> Exception raised:
>     Traceback (most recent call last):
>       File "/opt/zope298/lib/python/zope/testing/doctest.py", line
> 1348, in __run
>         compileflags, 1) in test.globs
>       File "<doctest
> Products.SebraeConfigurador.tests.test_associacao.test_associacao_noticias[1]>",
> line 1, in ?
>         setupNoticias(self)
>       File
> "/Users/dirceu/devel/zope298/Products/SebraeConfigurador/tests/utils.py",
> line 61, in setupNoticias
>
> zope_root.manage_addProduct['CMFPlone'].addPloneSite('noticias',
> create_userfolder=1, snapshot=0, profile_id='CMFPlone:plone')
>       File "/Users/dirceu/devel/zope298/Products/CMFPlone/factory.py",
> line 52, in addPloneSite
>         setup_tool.runAllImportSteps()
>       File
> "/Users/dirceu/devel/zope298/Products/GenericSetup/tool.py", line 252,
> in runAllImportSteps
>         return self._runImportStepsFromContext(context,
> purge_old=purge_old)
>       File
> "/Users/dirceu/devel/zope298/Products/GenericSetup/tool.py", line 766,
> in _runImportStepsFromContext
>         message = self._doRunImportStep(step, context)
>       File
> "/Users/dirceu/devel/zope298/Products/GenericSetup/tool.py", line 732,
> in _doRunImportStep
>         return handler(context)
>       File
> "/Users/dirceu/devel/zope298/Products/CMFPlone/setuphandlers.py", line
> 202, in importVarious
>         gen.installProducts(site)
>       File
> "/Users/dirceu/devel/zope298/Products/CMFPlone/setuphandlers.py", line
> 28, in installProducts
>         qi.installProduct('PlonePAS', locked=1)
>       File
> "/Users/dirceu/devel/zope298/Products/CMFQuickInstallerTool/QuickInstallerTool.py",
> line 333, in installProduct
>         res=install(portal)
>       File
> "/opt/zope298/lib/python/Products/ExternalMethod/ExternalMethod.py",
> line 225, in __call__
>         try: return f(*args, **kw)
>       File
> "/Users/dirceu/devel/zope298/Products/PlonePAS/Extensions/Install.py",
> line 837, in install
>         setupTools(portal, out)
>       File
> "/Users/dirceu/devel/zope298/Products/PlonePAS/Extensions/Install.py",
> line 396, in setupTools
>         migratePloneTool(portal, out)
>       File
> "/Users/dirceu/devel/zope298/Products/PlonePAS/Extensions/Install.py",
> line 407, in migratePloneTool
>         portal.manage_delObjects(['plone_utils'])
>       File "/Users/dirceu/devel/zope298/Products/CMFPlone/Portal.py",
> line 143, in manage_delObjects
>         raise Unauthorized, (
>     Unauthorized: Do not have permissions to remove this object

This is happening because at that point the logged in user is just a
normal portal user and doesn't have permissions to add users.  You can
login as the portal owner but be sure to log back in as the normal user
after you're done::

    self.loginAsPortalOwner()
    ... do stuff ...
    self.login()

Hope that helps!

Ross

> I'm using Zope 2.9.8 and Plone 2.5.3. How can I use a second plone
> site on a PloneTestCase test?
>
> Thanks,
> -- 
> Dirceu Pereira Tiegs
> Weimar Consultoria
>
> Hospedagem Plone, Zope e Python
> http://www.pytown.com





More information about the Product-Developers mailing list