[Zope-dev] Functional testing of export/import?
Casey Duncan
casey@zope.com
Mon, 28 Jul 2003 14:49:33 -0400
You can usually commit a subtransaction to get a _p_jar and oid (I think)=
set.=20
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.
>=20
> Background:
> This Product is a dynamic content object for CMF. Its behavior depends =
on=20
> another CMF type instances, which it keeps a path to. So I need to ensu=
re
> 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.
>=20
> So my test suite sets up a dummy CMF instance. I do this by swiping=20
> stuff from the CMFCore and CMFDefault tests; I subclass SecurityRequest=
Test
> and then do
>=20
> manage_addCMFSite(self.root, 'cmf_test_site' )
> self.site =3D self.root.cmf_test_site
>=20
> I've also got a portal folder in the site which I keep a handy=20
> reference to as self.fol1.=20
>=20
> All tests are passing, now I move on to writing the export / import tes=
ts.
>=20
> 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=3D1)
>=20
> ... and once that works, I'll use the same data to do an import.
>=20
> But the export fails. Using pdb and browsing some source I've learned=20
> that cp1 needs a _p_jar and _p_oid in order to be exported. =20
> The _p_jar I've already dealt with in my move / rename tests, by swipin=
g
> a hack from CMFCore/tests/test_portalFolder.py:
>=20
> id =3D self.cp1.getId()
>=20
> # WAAAA! must get _p_jar set
> old, self.cp1._p_jar =3D self.cp1._p_jar, self.root._p_jar
> try:
> data =3D self.fol1.manage_exportObject(id, download=3D1)
> finally:
> self.cp1._p_jar =3D old
>=20
> That seems to work fine.=20
>=20
> 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 ap=
p=20
> root :-P
>=20
> I must say that using pyunit to write functional tests for zope 2 / CMF=
=20
> 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.
>=20
> --=20
>=20
> Paul Winkler
> http://www.slinkp.com
>=20
>=20
> _______________________________________________
> Zope-Dev maillist - Zope-Dev@zope.org
> http://mail.zope.org/mailman/listinfo/zope-dev
> ** No cross posts or HTML encoding! **
> (Related lists -=20
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope )
>=20