Problem with PTC test setup

5 messages Options
Embed this post
Permalink
ajung () Problem with PTC test setup
Reply Threaded More More options
Print post
Permalink
Hi there,

currently writing tests for vs.event - an AT-derived event type for Plone.
The code works perfectly in reality but the tests don't.

This is the test setup (everything is straight-forward):

import vs.event

PloneTestCase.installProduct('vs.event')
PloneTestCase.setupPloneSite(products=('vs.event', ),
                             extension_profiles=('vs.event:default',))


class VSEventTest(PloneTestCase.PloneTestCase):

    def afterSetUp(self):
        ZopeTestCase.utils.setupCoreSessions(self.app)
        zcml.load_config('configure.zcml', vs.event)
        self.membership = self.portal.portal_membership
        self.membership.addMember('god', 'secret', ['Manager'], [])


    def testCreateEvent(self):
        self.login('god')
        user = getSecurityManager().getUser()
        self.assertEqual('Manager' in user.getRoles(), True)
        self.portal.invokeFactory('VSEvent', id='foo')

However invokeFactory() fails (although I am Manager):

  File
"/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/src/vs.event/vs/event/tests.py",
line 42, in testCreateEvent
    self.portal.invokeFactory('VSEvent', id='foo')
  File
"/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/parts/plone/CMFCore/PortalFolder.py",
line 315, in invokeFactory
    return pt.constructContent(type_name, self, id, RESPONSE, *args, **kw)
  File
"/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/parts/plone/CMFCore/TypesTool.py",
line 717, in constructContent
    ob = info.constructInstance(container, id, *args, **kw)
  File
"/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/parts/plone/CMFCore/TypesTool.py",
line 274, in constructInstance
    raise AccessControl_Unauthorized('Cannot create %s' % self.getId())
Unauthorized: Cannot create VSEvent


Somehow isConstructionAllowed is making the problem:

..>
/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/parts/plone/CMFCore/TypesTool.py(415)isConstructionAllowed()
-> if self.product:
(Pdb) args
self = <DynamicViewTypeInformation at VSEvent>
container = <PloneSite at plone>
(Pdb) print self

The FTI for VSEvent also looks fine to me:

(Pdb) pp self.__dict__
{'__ac_local_roles__': {'portal_owner': ['Owner']},
 '_actions': (<ActionInformation at view>,
              <ActionInformation at edit>,
              <ActionInformation at references>,
              <ActionInformation at ics>,
              <ActionInformation at vcs>,
              <ActionInformation at history>,
              <ActionInformation at external_edit>),
 '_aliases': {'(Default)': '(dynamic view)',
              'edit': 'atct_edit',
              'sharing': '@@sharing',
              'view': '(selected layout)'},
 'allow_discussion': False,
 'allowed_content_types': (),
 'content_icon': 'event_icon.gif',
 'content_meta_type': 'VSEvent',
 'default_view': 'vs_event_view',
 'description': 'Information about an upcoming event, which can be
displayed in the calendar.',
 'factory': 'addVSEvent',
 'filter_content_types': True,
 'global_allow': True,
 'i18n_domain': 'vs.event',
 'id': 'VSEvent',
 'immediate_view': 'vs_event_view',
 'product': 'vs.event',
 'title': 'VSEvent',
 'view_methods': ('vs_event_view',)}

Somehow the factory 'addVSEvent' can not be obtained.
Am I missing something in my test setup?

Andreas


[lists.vcf]

begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[hidden email]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard



_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Ricardo Alves-2 () Re: Problem with PTC test setup
Reply Threaded More More options
Print post
Permalink
Andreas Jung wrote:

> Hi there,
>
> currently writing tests for vs.event - an AT-derived event type for Plone.
> The code works perfectly in reality but the tests don't.
>
> This is the test setup (everything is straight-forward):
>
> import vs.event
>
> PloneTestCase.installProduct('vs.event')
> PloneTestCase.setupPloneSite(products=('vs.event', ),
>                              extension_profiles=('vs.event:default',))
>

AFAIU, to properly initialize content factories you need to use the
@onsetup decorator, so this function execution will be deferred until
the Plone site setup.

@onsetup
def setup_package():
    import vs.event
    zcml.load_config('configure.zcml', vs.event)
    ZopeTestCase.installPackage('vs.event')

setup_package()



I hope it helps.

Ricardo

--
Ricardo Alves <[hidden email]>
Eurotux <http://www.eurotux.com>


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
ajung () Re: Problem with PTC test setup
Reply Threaded More More options
Print post
Permalink
On 12.06.09 17:55, Ricardo Alves wrote:

> Andreas Jung wrote:
>> Hi there,
>>
>> currently writing tests for vs.event - an AT-derived event type for
>> Plone.
>> The code works perfectly in reality but the tests don't.
>>
>> This is the test setup (everything is straight-forward):
>>
>> import vs.event
>>
>> PloneTestCase.installProduct('vs.event')
>> PloneTestCase.setupPloneSite(products=('vs.event', ),
>>                              extension_profiles=('vs.event:default',))
>>
>
> AFAIU, to properly initialize content factories you need to use the
> @onsetup decorator, so this function execution will be deferred until
> the Plone site setup.
>
> @onsetup
> def setup_package():
>    import vs.event
>    zcml.load_config('configure.zcml', vs.event)
>    ZopeTestCase.installPackage('vs.event')
>
> setup_package()
Thanks for the evil and magical boilerplate - it's working now.

Andreas

[lists.vcf]

begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[hidden email]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard



_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
ajung () Re: Problem with PTC test setup/now 'roadrunner issue
Reply Threaded More More options
Print post
Permalink
Next issue is now using roadrunner. I followed the roadrunner
instructions on PyPI and
I get the following strange error when running roadrunner:

ajung@blackmoon:/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk>
bin/roadrunner  -s vs.event
Preloading Plone ...
Installing CMFCore ... done (0.234s)
Installing CMFDefault ... done (0.152s)
Installing CMFCalendar ... done (0.025s)
Installing CMFTopic ... done (0.013s)
Installing DCWorkflow ... done (0.034s)
Installing CMFActionIcons ... done (0.013s)
Installing CMFQuickInstallerTool ... done (0.038s)
Installing CMFFormController ... done (0.220s)
Installing GroupUserFolder ... done (0.249s)
Installing ZCTextIndex ... done (0.033s)
Installing CMFPlone ... done (1.571s)
Installing Archetypes ... done (0.192s)
Installing ATContentTypes ... done (0.031s)
Installing ATReferenceBrowserWidget ... done (0.009s)
Installing CMFDynamicViewFTI ... done (0.009s)
Installing ExternalEditor ... done (0.010s)
Installing ExtendedPathIndex ... done (0.011s)
Installing ResourceRegistries ... done (0.009s)
Installing SecureMailHost ... done (0.009s)
Installing CMFPlacefulWorkflow ... done (0.039s)
Installing PasswordResetTool ... done (0.011s)
Installing PluggableAuthService ... done (0.015s)
Installing PluginRegistry ... done (0.012s)
Installing PlonePAS ... done (0.014s)
Installing kupu ... done (0.194s)
Installing CMFEditions ... done (0.017s)
Installing CMFDiffTool ... done (0.014s)
Installing PloneLanguageTool ... done (0.014s)
  Set up Products.PloneTestCase.layer.ZCML in 2.974 seconds.
  Set up Products.PloneTestCase.layer.PloneSite in 7.064 seconds.
Preloading took: 13.544 seconds.
Running tests at level 1
Installing vs.event ... NOT FOUND
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Running Products.PloneTestCase.layer.PloneSite tests:
2009-06-14 14:37:50 ERROR GenericSetup Unknown step in dependency chain:
'profile-vs.event:default'
  Set up Products.PloneTestCase.layer.PloneSite
Traceback (most recent call last):
  File "bin/roadrunner", line 77, in ?
    roadrunner.runner.plone(zope_conf, preload_modules,
packages_under_test, zope2_location, buildout_home, part_dir)
  File
"/home/ajung/.buildout/eggs/roadrunner-0.2.2-py2.4.egg/roadrunner/runner.py",
line 88, in plone
    setup_layers=setup_layers)
  File
"/home/ajung/.buildout/eggs/roadrunner-0.2.2-py2.4.egg/roadrunner/testrunner.py",
line 273, in run
    failed = not run_with_options(options, setup_layers=setup_layers)
  File
"/home/ajung/.buildout/eggs/roadrunner-0.2.2-py2.4.egg/roadrunner/testrunner.py",
line 436, in run_with_options
    setup_layers, failures, errors)
  File
"/home/ajung/.buildout/eggs/roadrunner-0.2.2-py2.4.egg/roadrunner/testrunner.py",
line 607, in run_layer
    setup_layer(layer, setup_layers)
  File
"/home/ajung/.buildout/eggs/roadrunner-0.2.2-py2.4.egg/roadrunner/testrunner.py",
line 695, in setup_layer
    layer.setUp()
  File
"/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/parts/plone/PloneTestCase/layer.py",
line 33, in setUp
    func(*args, **kw)
  File
"/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/parts/plone/PloneTestCase/setup.py",
line 167, in setupPloneSite
    base_profile, extension_profiles).run()
  File
"/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/parts/plone/PloneTestCase/setup.py",
line 213, in run
    self._setupProfiles()
  File
"/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/parts/plone/PloneTestCase/setup.py",
line 281, in _setupProfiles
    setup.runAllImportStepsFromProfile(profile_id)
  File
"/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/parts/plone/GenericSetup/tool.py",
line 390, in runAllImportStepsFromProfile
    ignore_dependencies=ignore_dependencies)
  File
"/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/parts/plone/GenericSetup/tool.py",
line 1155, in _runImportStepsFromContext
    chain = self.getProfileDependencyChain( profile_id )
  File
"/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/parts/plone/GenericSetup/tool.py",
line 1135, in getProfileDependencyChain
    dependencies = self.getDependenciesForProfile( profile_id )
  File
"/data/develop/repository/ext1.svn.banality.de/vs.event/buildout/trunk/parts/plone/GenericSetup/tool.py",
line 911, in getDependenciesForProfile
    raise KeyError, profile_id
KeyError: 'profile-vs.event:default'


The current test code looks like this:

PloneTestCase.installProduct('vs.event')
PloneTestCase.setupPloneSite(extension_profiles=('vs.event:default',))

@onsetup
def setup_package():

  ZopeTestCase.installPackage('vs.event')
  zcml.load_config('configure.zcml', vs.event)

setup_package()

class TestBase(PloneTestCase.FunctionalTestCase):

    def afterSetUp(self):
        ZopeTestCase.utils.setupCoreSessions(self.app)
#        zcml.load_config('configure.zcml', vs.event)
        self.membership = self.portal.portal_membership
        self.membership.addMember('god', 'secret', ['Manager'], [])

class VSEventTest(TestBase):

    def testCalendarToolCheck(self):
        pc = self.portal.portal_calendar
        self.assertEqual(pc.meta_type, 'Chronos Calendar Tool')


Andreas


[lists.vcf]

begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[hidden email]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard



_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
David Glick-2 () Re: Problem with PTC test setup/now 'roadrunner issue
Reply Threaded More More options
Print post
Permalink

On Jun 14, 2009, at 5:41 AM, Andreas Jung wrote:

> The current test code looks like this:
>
> PloneTestCase.installProduct('vs.event')
> PloneTestCase.setupPloneSite(extension_profiles=('vs.event:default',))
>
> @onsetup
> def setup_package():
>
>  ZopeTestCase.installPackage('vs.event')
>  zcml.load_config('configure.zcml', vs.event)
>
> setup_package()
>
> class TestBase(PloneTestCase.FunctionalTestCase):
>
>    def afterSetUp(self):
>        ZopeTestCase.utils.setupCoreSessions(self.app)
> #        zcml.load_config('configure.zcml', vs.event)
>        self.membership = self.portal.portal_membership
>        self.membership.addMember('god', 'secret', ['Manager'], [])
>
> class VSEventTest(TestBase):
>
>    def testCalendarToolCheck(self):
>        pc = self.portal.portal_calendar
>        self.assertEqual(pc.meta_type, 'Chronos Calendar Tool')


You need to move your installProduct/setupPloneSite calls to be after  
the setup_package() call; otherwise your product's ZCML hasn't  
loaded.  You might also need to move the ztc.installPackage call below  
the zcml.load_config call.

I always refer to Martin's example test setup in PPD; it has worked  
consistently for me when using roadrunner.

David Glick
Web Developer
ONE/Northwest

New tools and strategies for engaging people in protecting the  
environment

http://www.onenw.org
[hidden email]
work: (206) 286-1235 x32
mobile: (206) 679-3833

Subscribe to ONEList, our email newsletter!
Practical advice for effective online engagement
http://www.onenw.org/full_signup





_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers