Commit bfd0b7de authored by Jason Madden's avatar Jason Madden

More functional tests from ZODB: test persistent class invalidation, and...

More functional tests from ZODB: test persistent class invalidation, and changing the _p_oid and _p_jar when not in a jar's cache.
parent 567a985b
...@@ -127,6 +127,15 @@ class _Persistent_Base(object): ...@@ -127,6 +127,15 @@ class _Persistent_Base(object):
self.assertTrue(inst._p_jar is jar) self.assertTrue(inst._p_jar is jar)
inst._p_jar = jar # reassign only to same DM inst._p_jar = jar # reassign only to same DM
def test_assign_p_jar_not_in_cache_allowed(self):
jar = self._makeJar()
inst = self._makeOne()
inst._p_jar = jar
# Both of these are allowed
inst._p_jar = self._makeJar()
inst._p_jar = None
self.assertEqual(inst._p_jar, None)
def test_assign_p_oid_w_invalid_oid(self): def test_assign_p_oid_w_invalid_oid(self):
inst, jar, OID = self._makeOneWithJar() inst, jar, OID = self._makeOneWithJar()
def _test(): def _test():
...@@ -166,6 +175,15 @@ class _Persistent_Base(object): ...@@ -166,6 +175,15 @@ class _Persistent_Base(object):
inst._p_oid = new_OID inst._p_oid = new_OID
self.assertRaises(ValueError, _test) self.assertRaises(ValueError, _test)
def test_assign_p_oid_not_in_cache_allowed(self):
jar = self._makeJar()
inst = self._makeOne()
inst._p_jar = jar
inst._p_oid = 1 # anything goes
inst._p_oid = 42
self.assertEqual(inst._p_oid, 42)
def test_delete_p_oid_wo_jar(self): def test_delete_p_oid_wo_jar(self):
from persistent.timestamp import _makeOctets from persistent.timestamp import _makeOctets
OID = _makeOctets('\x01' * 8) OID = _makeOctets('\x01' * 8)
......
...@@ -1025,6 +1025,25 @@ class PickleCacheTests(unittest.TestCase): ...@@ -1025,6 +1025,25 @@ class PickleCacheTests(unittest.TestCase):
# sanity check # sanity check
self.assertTrue(cache.total_estimated_size >= 0) self.assertTrue(cache.total_estimated_size >= 0)
def test_invalidate_persistent_class_calls_p_invalidate(self):
from persistent._compat import _b
KEY = _b('pclass')
class pclass(object):
_p_oid = KEY
invalidated = False
@classmethod
def _p_invalidate(cls):
cls.invalidated = True
cache = self._makeOne()
cache[KEY] = pclass
cache.invalidate(KEY)
self.assertTrue(pclass.invalidated)
class DummyPersistent(object): class DummyPersistent(object):
def _p_invalidate(self): def _p_invalidate(self):
......
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