Commit b6eaa442 authored by Godefroid Chapelle's avatar Godefroid Chapelle

actually test the ability to __getstate__

parent 7f89ec0e
......@@ -13,6 +13,13 @@
##############################################################################
import unittest
from OFS.SimpleItem import SimpleItem
from Testing.ZopeTestCase import base
class ToBreak(SimpleItem):
pass
class TestsOfBroken(unittest.TestCase):
"""Tests for the factory for "broken" classes.
......@@ -103,18 +110,45 @@ class TestsOfBroken(unittest.TestCase):
for meth_name in PERSISTENCE_METHODS:
meth = getattr(inst, meth_name) # doesn't raise
class TestsIntegratedBroken(base.TestCase):
def test_Broken_instance___getstate___gives_access_to_its_state(self):
from OFS.Uninstalled import Broken
OID = '\x01' * 8
inst = Broken(self, OID, ('Products.MyProduct.MyClass', 'MyClass'))
inst.__setstate__({'x': 1})
self.assertEqual(inst.__getstate__(), {'x': 1})
from Acquisition import aq_base
from OFS.Uninstalled import BrokenClass
from OFS.tests import test_Uninstalled
import transaction
# store an instance
tr = ToBreak()
tr.id = 'tr'
self.app._setObject('tr', tr)
# commit to allow access in another connection
transaction.commit()
# remove class from namespace to ensure broken object
del test_Uninstalled.ToBreak
# get new connection that will give access to broken object
app = base.app()
inst = aq_base(app.tr)
self.failUnless(isinstance(inst, BrokenClass))
state = inst.__getstate__()
self.assertEqual(state, {'id': 'tr'})
# cleanup
app.manage_delObjects('tr')
transaction.commit()
# check that object is not left over
app = base.app()
self.failIf('tr' in app.objectIds())
def test_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite(TestsOfBroken))
suite.addTest(unittest.makeSuite(TestsOfBroken))
suite.addTest(unittest.makeSuite(TestsIntegratedBroken))
return suite
def main():
unittest.main(defaultTest='test_suite')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment