def test_get_serial_detects_new_objects(self): # Verifies the behavior of _get_serial() and _set_serial(). conn1 = self.db.open() try: ob = self._write_basic_object(conn1) self.assertNotEqual(conn1._get_serial(ob), '\0' * 8) # Replace the object and verify it gets a new serial. ob1 = PersistentMapping() ob1.strdata = 'cba' ob1._p_oid = conn1.root()['TestRoot']._p_oid conn1.root()['TestRoot'] = ob1 self.assertEqual(conn1._get_serial(ob1), '\0' * 8) finally: conn1.close()
def test_copy_of(self): # Verifies the functionality of zodb_copy(). ob1 = PersistentMapping() ob1._p_oid = 'xxx' self.assertEqual(ob1._p_oid, 'xxx') # Precondition ob1['fish'] = PersistentMapping() ob1['fish']['trout'] = 1 ob1['fish']['herring'] = 2 ob2 = zodb_copy(ob1) self.assert_(ob2 is not ob1) self.assert_(ob2['fish'] is not ob1['fish']) self.assert_(ob2._p_oid is None) self.assertEqual(list(ob2.keys()), ['fish']) self.assertEqual(len(ob2['fish'].keys()), 2)
def _prepare_root(self): osio = self._get_osio() oid = osio.conf.oid_gen.root_oid try: self[oid] except (KeyError, LoadError): # Create the root object. from Persistence import PersistentMapping root = PersistentMapping() root._p_jar = self root._p_changed = 1 root._p_oid = oid t = transaction.Transaction() t.note('Initial database creation') self.tpc_begin(t) self.commit(root, t) self.tpc_vote(t) self.tpc_finish(t)
def test_serial_cleanup(self): # Verify that _set_serial() cleans up. conn1 = self.db.open() try: conn1.serial_cleanup_threshold = 10 for n in range(conn1.serial_cleanup_threshold + 1): new_ob = PersistentMapping() new_ob._p_oid = 'fake_oid_' + str(n) old_size = len(conn1._serials or ()) conn1._set_serial(new_ob, '01234567') new_size = len(conn1._serials) if new_size < old_size: # Cleaned up. Success. break else: self.fail("_set_serial() did not clean up") finally: conn1.close()