diff options
| author | Chris McDonough <chrism@agendaless.com> | 2008-11-19 02:21:37 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2008-11-19 02:21:37 +0000 |
| commit | 65dcf305794feffb1da33c15b5af8d4964580d72 (patch) | |
| tree | 0ebad53fed1b951458aabda0741e71bcaeb4a17d /repoze/bfg/tests | |
| parent | 5483348a58f8c3adcc2dec7b2e6b188a588c04cf (diff) | |
| download | pyramid-65dcf305794feffb1da33c15b5af8d4964580d72.tar.gz pyramid-65dcf305794feffb1da33c15b5af8d4964580d72.tar.bz2 pyramid-65dcf305794feffb1da33c15b5af8d4964580d72.zip | |
- Fix ModelGraphTraverser; don't try to change the ``__name__`` or
``__parent__`` of an object that claims it implements ILocation
during traversal even if the ``__name__`` or ``__parent__`` of the
object traversed does not match the name used in the traversal
step or the or the traversal parent . Rationale: it was insane to
do so. This bug was only found due to a misconfiguration in an
application that mistakenly had intermediate persistent
non-ILocation objects; traversal was causing a persistent write on
every request under this setup.
- ``repoze.bfg.location.locate`` now unconditionally sets
``__name__`` and ``__parent__`` on objects which provide ILocation
(it previously only set them conditionally if they didn't match
attributes already present on the object via equality).
Prep for 0.5.0.
Diffstat (limited to 'repoze/bfg/tests')
| -rw-r--r-- | repoze/bfg/tests/test_traversal.py | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/repoze/bfg/tests/test_traversal.py b/repoze/bfg/tests/test_traversal.py index 90e64dc97..2c02d7d63 100644 --- a/repoze/bfg/tests/test_traversal.py +++ b/repoze/bfg/tests/test_traversal.py @@ -101,34 +101,67 @@ class ModelGraphTraverserTests(unittest.TestCase, PlacelessSetup): self.assertEqual(name, 'foo') self.assertEqual(subpath, []) - def test_call_with_ILocation_root(self): + def test_call_with_ILocation_root_proxies(self): baz = DummyContext() bar = DummyContext(baz) foo = DummyContext(bar) root = DummyContext(foo) from zope.interface import directlyProvides from repoze.bfg.interfaces import ILocation + from zope.proxy import isProxy directlyProvides(root, ILocation) root.__name__ = None root.__parent__ = None - # give bar a direct parent and name to mix things up a bit - bar.__name__ = 'bar' - bar.__parent__ = foo policy = self._makeOne(root) environ = self._getEnviron(PATH_INFO='/foo/bar/baz') ctx, name, subpath = policy(environ) - self.assertEqual(ctx, baz) self.assertEqual(name, '') self.assertEqual(subpath, []) + self.assertEqual(ctx, baz) + self.failUnless(isProxy(ctx)) self.assertEqual(ctx.__name__, 'baz') self.assertEqual(ctx.__parent__, bar) + self.failUnless(isProxy(ctx.__parent__)) self.assertEqual(ctx.__parent__.__name__, 'bar') self.assertEqual(ctx.__parent__.__parent__, foo) + self.failUnless(isProxy(ctx.__parent__.__parent__)) self.assertEqual(ctx.__parent__.__parent__.__name__, 'foo') self.assertEqual(ctx.__parent__.__parent__.__parent__, root) + self.failIf(isProxy(ctx.__parent__.__parent__.__parent__)) self.assertEqual(ctx.__parent__.__parent__.__parent__.__name__, None) self.assertEqual(ctx.__parent__.__parent__.__parent__.__parent__, None) + def test_call_with_ILocation_root_proxies_til_next_ILocation(self): + # This is a test of an insane setup; it tests the case where + # intermediate objects (foo and bar) do not implement + # ILocation, and so are returned as proxies to the traverser, + # but when we reach the "baz" object, it *does* implement + # ILocation, and its parent should be the *real* "bar" object + # rather than the proxied bar. + from zope.interface import directlyProvides + from repoze.bfg.interfaces import ILocation + baz = DummyContext() + directlyProvides(baz, ILocation) + baz.__name__ = 'baz' + bar = DummyContext(baz) + baz.__parent__ = bar + foo = DummyContext(bar) + root = DummyContext(foo) + from zope.proxy import isProxy + directlyProvides(root, ILocation) + root.__name__ = None + root.__parent__ = None + policy = self._makeOne(root) + environ = self._getEnviron(PATH_INFO='/foo/bar/baz') + ctx, name, subpath = policy(environ) + self.assertEqual(name, '') + self.assertEqual(subpath, []) + self.assertEqual(ctx, baz) + self.failIf(isProxy(ctx)) + self.assertEqual(ctx.__name__, 'baz') + self.assertEqual(ctx.__parent__, bar) + self.failIf(isProxy(ctx.__parent__)) + class FindInterfaceTests(unittest.TestCase): def _callFUT(self, context, iface): from repoze.bfg.traversal import find_interface |
