Re: [Zope-dev] Functional testing of export/import?

2003-07-29 Thread Paul Winkler
On Mon, Jul 28, 2003 at 02:49:33PM -0400, Casey Duncan wrote:
 You can usually commit a subtransaction to get a _p_jar and oid (I think) set. 
 You can still abort this at the end of the test to clean up.

yep, this seems to work very nicely! Thanks Casey!

def setUp(self):
   ...
   get_transaction().commit(1)
   ...


def tearDown(self):
   ...
   get_transaction().abort(1)
   ...

-- 

Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's EXTRA YELLOW BLOWER CHEESEMONGER!
(random hero from isometric.spaceninja.com)

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


[Zope-dev] Functional testing of export/import?

2003-07-28 Thread Paul Winkler
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.

Background:
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()

# W! must get _p_jar set
old, self.cp1._p_jar = self.cp1._p_jar, self.root._p_jar
try:
data = self.fol1.manage_exportObject(id, download=1)
finally:
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
http://www.slinkp.com


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


Re: [Zope-dev] Functional testing of export/import?

2003-07-28 Thread Casey Duncan
You can usually commit a subtransaction to get a _p_jar and oid (I think) set. 
You can still abort this at the end of the test to clean up.

hth,

-Casey

On Monday 28 July 2003 12:39 pm, Paul Winkler wrote:
 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.
 
 Background:
 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()
 
 # W! must get _p_jar set
 old, self.cp1._p_jar = self.cp1._p_jar, self.root._p_jar
 try:
 data = self.fol1.manage_exportObject(id, download=1)
 finally:
 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
 http://www.slinkp.com
 
 
 ___
 Zope-Dev maillist  -  [EMAIL PROTECTED]
 http://mail.zope.org/mailman/listinfo/zope-dev
 **  No cross posts or HTML encoding!  **
 (Related lists - 
  http://mail.zope.org/mailman/listinfo/zope-announce
  http://mail.zope.org/mailman/listinfo/zope )
 


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