summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-09-28 02:17:36 +0000
committerChris McDonough <chrism@agendaless.com>2008-09-28 02:17:36 +0000
commitcbdc36976c18a0812f921ee3b7b92ed2dd823ed0 (patch)
treec428c9b0e4357ecf3b5903359594dc6f2bf27a8b /repoze/bfg/tests
parentcd6899ed4d0eba4b114d04058470528c9a167d6e (diff)
downloadpyramid-cbdc36976c18a0812f921ee3b7b92ed2dd823ed0.tar.gz
pyramid-cbdc36976c18a0812f921ee3b7b92ed2dd823ed0.tar.bz2
pyramid-cbdc36976c18a0812f921ee3b7b92ed2dd823ed0.zip
Features
- A ``repoze.bfg.location`` API module was added. Backwards incompatibilities - Applications must now use the ``repoze.bfg.interfaces.ILocation`` interface rather than ``zope.location.interfaces.ILocation`` to represent that a model object is "location-aware". We've removed a dependency on ``zope.location`` for cleanliness purposes: as new versions of zope libraries are released which have improved dependency information, getting rid of our dependence on ``zope.location`` will prevent a newly installed repoze.bfg application from requiring the ``zope.security``, egg, which not truly used at all in a "stock" repoze.bfg setup. These dependencies are still required by the stack at this time; this is purely a futureproofing move. The security and model documentation for previous versions of ``repoze.bfg`` recommended using the ``zope.location.interfaces.ILocation`` interface to represent that a model object is "location-aware". This documentation has been changed to reflect that this interface should now be imported from ``repoze.bfg.interfaces.ILocation`` instead.
Diffstat (limited to 'repoze/bfg/tests')
-rw-r--r--repoze/bfg/tests/test_location.py82
-rw-r--r--repoze/bfg/tests/test_traversal.py2
-rw-r--r--repoze/bfg/tests/test_zcml.py6
3 files changed, 86 insertions, 4 deletions
diff --git a/repoze/bfg/tests/test_location.py b/repoze/bfg/tests/test_location.py
new file mode 100644
index 000000000..fc8f8c621
--- /dev/null
+++ b/repoze/bfg/tests/test_location.py
@@ -0,0 +1,82 @@
+import unittest
+
+class TestLocation(unittest.TestCase):
+ def test_inside(self):
+ o1 = Location()
+ o2 = Location(); o2.__parent__ = o1
+ o3 = Location(); o3.__parent__ = o2
+ o4 = Location(); o4.__parent__ = o3
+
+ from repoze.bfg.location import inside
+ self.assertEqual(inside(o1, o1), True)
+ self.assertEqual(inside(o2, o1), True)
+ self.assertEqual(inside(o3, o1), True)
+ self.assertEqual(inside(o4, o1), True)
+ self.assertEqual(inside(o1, o4), False)
+ self.assertEqual(inside(o1, None), False)
+
+ def test_locate(self):
+ from repoze.bfg.location import locate
+ from repoze.bfg.location import LocationProxy
+
+ a = Location()
+ parent = Location()
+ a_located = locate(a, parent, 'a')
+ self.failUnless(a_located is a)
+ self.failUnless(a_located.__parent__ is parent)
+ self.assertEqual(a_located.__name__, 'a')
+ # If we locate the object again, nothing special happens:
+
+ a_located_2 = locate(a_located, parent, 'a')
+ self.failUnless(a_located_2 is a_located)
+
+ # If the object does not provide ILocation a LocationProxy is returned:
+
+ l = [1, 2, 3]
+ parent = Location()
+ l_located = locate(l, parent, 'l')
+ self.assertEqual(l_located, [1, 2, 3])
+ self.failUnless(l_located.__parent__ is parent)
+ self.assertEqual(l_located.__name__, 'l')
+ self.failIf(l_located is l)
+ self.assertEqual(type(l_located), LocationProxy)
+
+ l_located_2 = locate(l_located, parent, 'l')
+ self.failUnless(l_located_2 is l_located)
+ # When changing the name, we still do not get a different proxied
+ # object:
+
+ l_located_3 = locate(l_located, parent, 'new-name')
+ self.failUnless(l_located_3 is l_located_2)
+
+ def test_LocationProxy(self):
+ from repoze.bfg.location import LocationProxy
+ from repoze.bfg.interfaces import ILocation
+ l = [1, 2, 3]
+ self.assertEqual(ILocation.providedBy(l), False)
+ p = LocationProxy(l, "Dad", "p")
+ self.assertEqual(p, [1, 2, 3])
+ self.assertEqual(ILocation.providedBy(p), True)
+ self.assertEqual(p.__parent__, 'Dad')
+ self.assertEqual(p.__name__, 'p')
+ import pickle
+ self.assertRaises(TypeError, pickle.dumps, p)
+ # Proxies should get their doc strings from the object they proxy:
+ self.assertEqual(p.__doc__, l.__doc__)
+
+ def test_lineage(self):
+ from repoze.bfg.location import lineage
+ o1 = Location()
+ o2 = Location(); o2.__parent__ = o1
+ o3 = Location(); o3.__parent__ = o2
+ o4 = Location(); o4.__parent__ = o3
+ result = list(lineage(o3))
+ self.assertEqual(result, [o3, o2, o1])
+ result = list(lineage(o1))
+ self.assertEqual(result, [o1])
+
+from repoze.bfg.interfaces import ILocation
+from zope.interface import implements
+class Location(object):
+ implements(ILocation)
+ __name__ = __parent__ = None
diff --git a/repoze/bfg/tests/test_traversal.py b/repoze/bfg/tests/test_traversal.py
index 8034cf39b..4dced41ca 100644
--- a/repoze/bfg/tests/test_traversal.py
+++ b/repoze/bfg/tests/test_traversal.py
@@ -112,7 +112,7 @@ class ModelGraphTraverserTests(unittest.TestCase, PlacelessSetup):
foo = DummyContext(bar)
root = DummyContext(foo)
from zope.interface import directlyProvides
- from zope.location.interfaces import ILocation
+ from repoze.bfg.interfaces import ILocation
directlyProvides(root, ILocation)
root.__name__ = None
root.__parent__ = None
diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py
index 158743c64..6d79606ad 100644
--- a/repoze/bfg/tests/test_zcml.py
+++ b/repoze/bfg/tests/test_zcml.py
@@ -32,7 +32,7 @@ class TestViewDirective(unittest.TestCase, PlacelessSetup):
from repoze.bfg.interfaces import IView
from repoze.bfg.interfaces import IViewPermission
from repoze.bfg.security import ViewPermissionFactory
- from zope.component.zcml import handler
+ from repoze.bfg.zcml import handler
from zope.component.interface import provideInterface
self.assertEqual(len(actions), 3)
@@ -79,7 +79,7 @@ class TestViewDirective(unittest.TestCase, PlacelessSetup):
from repoze.bfg.interfaces import IView
from repoze.bfg.interfaces import IViewPermission
from repoze.bfg.security import ViewPermissionFactory
- from zope.component.zcml import handler
+ from repoze.bfg.zcml import handler
from zope.component.interface import provideInterface
self.assertEqual(len(actions), 3)
@@ -125,7 +125,7 @@ class TestViewDirective(unittest.TestCase, PlacelessSetup):
cacheable=False)
actions = context.actions
from repoze.bfg.interfaces import IView
- from zope.component.zcml import handler
+ from repoze.bfg.zcml import handler
from repoze.bfg.zcml import Uncacheable
self.assertEqual(len(actions), 3)