[Zodb-checkins] CVS: Zope3/src/zodb/tests - test_connection.py:1.7
Albertas Agejevas
alga at pov.lt
Wed Oct 8 04:20:31 EDT 2003
Update of /cvs-repository/Zope3/src/zodb/tests
In directory cvs.zope.org:/tmp/cvs-serv9086/tests
Modified Files:
test_connection.py
Log Message:
Connection.add() method with tests and interface changes.
=== Zope3/src/zodb/tests/test_connection.py 1.6 => 1.7 ===
--- Zope3/src/zodb/tests/test_connection.py:1.6 Tue Oct 7 12:00:40 2003
+++ Zope3/src/zodb/tests/test_connection.py Wed Oct 8 04:20:30 2003
@@ -157,6 +157,36 @@
self.assertEqual(getattr(self.obj, "child", None), None)
self.assertEqual(x._p_oid, None)
+ def test_add(self):
+ from zodb.interfaces import InvalidObjectReference
+ self.datamgr.add(self.obj)
+ self.assert_(getattr(self.obj, '_p_oid', None))
+ self.assert_(self.obj._p_jar is self.datamgr)
+ self.assertRaises(TypeError, self.datamgr.add, object())
+
+ # Adding to the same connection does not fail
+ oid = self.obj._p_oid
+ self.datamgr.add(self.obj)
+ self.assertEqual(self.obj._p_oid, oid)
+
+ # Cannot add an object from a diffrerent connection
+ self.obj._p_jar = object()
+ self.assertRaises(InvalidObjectReference, self.datamgr.add, self.obj)
+
+ def testAdding(self):
+ # This is a more 'functional' test than test_add
+ self.datamgr.add(self.obj)
+ oid = self.obj._p_oid
+ self.datamgr.root()["obj"] = self.obj
+ get_transaction().commit()
+
+ cn2 = self.db.open()
+ r2 = cn2.root()
+ obj2 = r2["obj"]
+ self.assertEqual(obj2._p_oid, oid)
+ self.assert_(cn2.get(oid) is obj2, "cn2.get(oid) is not obj2")
+ self.assert_(self.obj is not obj2, "self.obj is obj2")
+
def tearDown(self):
get_transaction().abort()
self.datamgr.close()
More information about the Zodb-checkins
mailing list