Commit b6eaa442 authored by Godefroid Chapelle's avatar Godefroid Chapelle

actually test the ability to __getstate__

parent 7f89ec0e
...@@ -13,6 +13,13 @@ ...@@ -13,6 +13,13 @@
############################################################################## ##############################################################################
import unittest import unittest
from OFS.SimpleItem import SimpleItem
from Testing.ZopeTestCase import base
class ToBreak(SimpleItem):
pass
class TestsOfBroken(unittest.TestCase): class TestsOfBroken(unittest.TestCase):
"""Tests for the factory for "broken" classes. """Tests for the factory for "broken" classes.
...@@ -103,18 +110,45 @@ class TestsOfBroken(unittest.TestCase): ...@@ -103,18 +110,45 @@ class TestsOfBroken(unittest.TestCase):
for meth_name in PERSISTENCE_METHODS: for meth_name in PERSISTENCE_METHODS:
meth = getattr(inst, meth_name) # doesn't raise meth = getattr(inst, meth_name) # doesn't raise
class TestsIntegratedBroken(base.TestCase):
def test_Broken_instance___getstate___gives_access_to_its_state(self): def test_Broken_instance___getstate___gives_access_to_its_state(self):
from OFS.Uninstalled import Broken from Acquisition import aq_base
OID = '\x01' * 8 from OFS.Uninstalled import BrokenClass
inst = Broken(self, OID, ('Products.MyProduct.MyClass', 'MyClass')) from OFS.tests import test_Uninstalled
inst.__setstate__({'x': 1}) import transaction
self.assertEqual(inst.__getstate__(), {'x': 1})
# 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(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite(TestsOfBroken)) suite.addTest(unittest.makeSuite(TestsOfBroken))
suite.addTest(unittest.makeSuite(TestsIntegratedBroken))
return suite return suite
def main(): def main():
unittest.main(defaultTest='test_suite') 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