[Checkins] SVN: zc.intid/trunk/src/zc/intid/tests.py test that certain bad subclass behavior is handled to avoid data loss
Fred Drake
fdrake at gmail.com
Fri Nov 20 13:23:34 EST 2009
Log message for revision 105918:
test that certain bad subclass behavior is handled to avoid data loss
Changed:
U zc.intid/trunk/src/zc/intid/tests.py
-=-
Modified: zc.intid/trunk/src/zc/intid/tests.py
===================================================================
--- zc.intid/trunk/src/zc/intid/tests.py 2009-11-20 18:14:29 UTC (rev 105917)
+++ zc.intid/trunk/src/zc/intid/tests.py 2009-11-20 18:23:34 UTC (rev 105918)
@@ -209,7 +209,30 @@
self.assertEquals(obj.id2, uid2)
self.assert_(u2.getObject(uid2) is obj)
+ def test_duplicate_id_generation(self):
+ # If an overridden ``generateId`` method generates an id that's
+ # already used, the ``register`` method will detect that an
+ # raise an exception.
+ u = self.createIntIds()
+ u.generateId = lambda ob: 42
+
+ # Register an object, consuming the id our generator provides:
+ obj = P()
+ uid = u.register(obj)
+ self.assertEquals(uid, 42)
+ self.assertEquals(obj.iid, 42)
+
+ # Check that the exception is raised:
+ self.assertRaises(ValueError, u.register, P())
+
+ # Verify that the original registration isn't compromised:
+ self.assert_(u.getObject(42) is obj)
+ self.assert_(u.queryObject(42) is obj)
+ self.assertEquals(u.getId(obj), uid)
+ self.assertEquals(u.queryId(obj), uid)
+
+
class TestIntIds64(TestIntIds):
def createIntIds(self, attribute="iid"):
More information about the checkins
mailing list