I'm trying to write a functional test that verifies that an instance
of my Product works correctly after it's been exported and re-imported.
I'm stuck on how to give the test object a valid _p_oid which is needed
to do the export.

This Product is a dynamic content object for CMF. Its behavior depends on 
another CMF type instances, which it keeps a path to. So I need to ensure
that things work even when one or both objects have moved. I've got
moving & renaming handled well and now I want to test import/export.

So my test suite sets up a dummy CMF instance. I do this by swiping 
stuff from the CMFCore and CMFDefault tests; I subclass SecurityRequestTest
and then do

    manage_addCMFSite(self.root, 'cmf_test_site' )
    self.site = self.root.cmf_test_site

I've also got a portal folder in the site which I keep a handy 
reference to as self.fol1. 

All tests are passing, now I move on to writing the export / import tests.

Let's say the object I want to export is self.cmf_test_site.fol1.cp1.
I have a shorthand reference to this stored as self.cp1.
So I think the first thing I need to do is get the export data
like this:
    data self.fol1.manage_exportObject('cp1', download=1)

... and once that works, I'll use the same data to do an import.

But the export fails. Using pdb and browsing some source I've learned 
that cp1 needs a _p_jar and _p_oid in order to be exported.  
The _p_jar I've already dealt with in my move / rename tests, by swiping
a hack from CMFCore/tests/test_portalFolder.py:

    id = self.cp1.getId()

    # WAAAA! must get _p_jar set
    old, self.cp1._p_jar = self.cp1._p_jar, self.root._p_jar
        data = self.fol1.manage_exportObject(id, download=1)
        self.cp1._p_jar = old

That seems to work fine. 

But now I'm stuck on _p_oid. How do I give the object a valid one?
I'm sure I can't just use the same trick and swipe the _p_oid of the app 
root :-P

I must say that using pyunit to write functional tests for zope 2 / CMF 
is a royal pain. It requires too much knowledge of implementation.
(why should i need to worry about _p_foo???)
Also I've found that if there's an error in your class' setUp(),
it can cause the test to hang and never show you a traceback.


Paul Winkler

Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to