summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-07-04 17:50:59 +0000
committerChris McDonough <chrism@agendaless.com>2008-07-04 17:50:59 +0000
commit8b2c67309a9a3f9cf709bf3003dc3275f17c709e (patch)
tree1b20d5b000e4333cf50b2c2305dbb03e8b312144 /repoze/bfg/tests
parentd6cb3c1b68e752922a149d37a8d208b7d01dbe14 (diff)
downloadpyramid-8b2c67309a9a3f9cf709bf3003dc3275f17c709e.tar.gz
pyramid-8b2c67309a9a3f9cf709bf3003dc3275f17c709e.tar.bz2
pyramid-8b2c67309a9a3f9cf709bf3003dc3275f17c709e.zip
Don't depend on ZODB; shuffle policy responsibilities around a little.
Diffstat (limited to 'repoze/bfg/tests')
-rw-r--r--repoze/bfg/tests/test_policy.py94
-rw-r--r--repoze/bfg/tests/test_zodb.py95
2 files changed, 94 insertions, 95 deletions
diff --git a/repoze/bfg/tests/test_policy.py b/repoze/bfg/tests/test_policy.py
new file mode 100644
index 000000000..e8752d1a1
--- /dev/null
+++ b/repoze/bfg/tests/test_policy.py
@@ -0,0 +1,94 @@
+import unittest
+
+class SplitPathTests(unittest.TestCase):
+ def _getFUT(self):
+ from repoze.bfg.policy import split_path
+ return split_path
+
+ def test_cleanPath_path_startswith_endswith(self):
+ f = self._getFUT()
+ self.assertEqual(f('/foo/'), ['foo'])
+
+ def test_cleanPath_empty_elements(self):
+ f = self._getFUT()
+ self.assertEqual(f('foo///'), ['foo'])
+
+ def test_cleanPath_onedot(self):
+ f = self._getFUT()
+ self.assertEqual(f('foo/./bar'), ['foo', 'bar'])
+
+ def test_cleanPath_twodots(self):
+ f = self._getFUT()
+ self.assertEqual(f('foo/../bar'), ['bar'])
+
+ def test_cleanPath_element_urllquoted(self):
+ f = self._getFUT()
+ self.assertEqual(f('/foo/space%20thing/bar'), ['foo', 'space thing',
+ 'bar'])
+
+class NaivePolicyTests(unittest.TestCase):
+ def _getTargetClass(self):
+ from repoze.bfg.policy import NaivePolicy
+ return NaivePolicy
+
+ def _makeOne(self, *arg, **kw):
+ klass = self._getTargetClass()
+ return klass(*arg, **kw)
+
+ def test_class_conforms_to_IPolicy(self):
+ from zope.interface.verify import verifyClass
+ from repoze.bfg.interfaces import IPolicy
+ verifyClass(IPolicy, self._getTargetClass())
+
+ def test_instance_conforms_to_IPolicy(self):
+ from zope.interface.verify import verifyObject
+ from repoze.bfg.interfaces import IPolicy
+ verifyObject(IPolicy, self._makeOne())
+
+ def test_call_nonkeyerror_raises(self):
+ policy = self._makeOne()
+ environ = {'PATH_INFO':'/foo'}
+ root = None
+ self.assertRaises(TypeError, policy, environ, root)
+
+ def test_call_withconn_getitem_emptypath_nosubpath(self):
+ policy = self._makeOne()
+ context = DummyContext()
+ environ = {'PATH_INFO':''}
+ root = context
+ ctx, name, subpath = policy(environ, root)
+ self.assertEqual(context, ctx)
+ self.assertEqual(name, '')
+ self.assertEqual(subpath, [])
+
+ def test_call_withconn_getitem_withpath_nosubpath(self):
+ policy = self._makeOne()
+ context = DummyContext()
+ context2 = DummyContext(context)
+ environ = {'PATH_INFO':'/foo/bar'}
+ root = context
+ ctx, name, subpath = policy(environ, root)
+ self.assertEqual(context, ctx)
+ self.assertEqual(name, 'bar')
+ self.assertEqual(subpath, [])
+
+ def test_call_withconn_getitem_withpath_withsubpath(self):
+ policy = self._makeOne()
+ context = DummyContext()
+ context2 = DummyContext(context)
+ environ = {'PATH_INFO':'/foo/bar/baz/buz'}
+ root = context
+ ctx, name, subpath = policy(environ, root)
+ self.assertEqual(context, ctx)
+ self.assertEqual(name, 'bar')
+ self.assertEqual(subpath, ['baz', 'buz'])
+
+class DummyContext:
+ def __init__(self, next=None):
+ self.next = next
+
+ def __getitem__(self, name):
+ if self.next is None:
+ raise KeyError, name
+ return self.next
+
diff --git a/repoze/bfg/tests/test_zodb.py b/repoze/bfg/tests/test_zodb.py
deleted file mode 100644
index d28622953..000000000
--- a/repoze/bfg/tests/test_zodb.py
+++ /dev/null
@@ -1,95 +0,0 @@
-import unittest
-
-class ZODBGetitemPolicyTests(unittest.TestCase):
- def _getTargetClass(self):
- from repoze.bfg.zodb import ZODBGetitemPolicy
- return ZODBGetitemPolicy
-
- def _makeOne(self, *arg, **kw):
- klass = self._getTargetClass()
- return klass(*arg, **kw)
-
- def test_class_conforms_to_IPolicy(self):
- from zope.interface.verify import verifyClass
- from repoze.bfg.interfaces import IPolicy
- verifyClass(IPolicy, self._getTargetClass())
-
- def test_instance_conforms_to_IPolicy(self):
- from zope.interface.verify import verifyObject
- from repoze.bfg.interfaces import IPolicy
- verifyObject(IPolicy, self._makeOne('dbname'))
-
- def test_call_noconn(self):
- mw = self._makeOne('dbname')
- environ = {}
- self.assertRaises(ValueError, mw, environ)
-
- def test_call_withconn_attributeerror(self):
- mw = self._makeOne('dbname')
- environ = {'repoze.zodbconn.dbname': DummyConnection(DummyNoGetitem()),
- 'PATH_INFO':''}
- self.assertRaises(AttributeError, mw, environ)
-
- def test_call_withconn_getitem_emptypath_nosubpath(self):
- mw = self._makeOne('dbname')
- context = DummyContext()
- environ = {'repoze.zodbconn.dbname': DummyConnection(context),
- 'PATH_INFO':''}
- ctx, name, subpath = mw(environ)
- self.assertEqual(context, ctx)
- self.assertEqual(name, '')
- self.assertEqual(subpath, [])
-
- def test_call_withconn_getitem_withpath_nosubpath(self):
- mw = self._makeOne('dbname')
- context = DummyContext()
- context2 = DummyContext(context)
- environ = {'repoze.zodbconn.dbname': DummyConnection(context2),
- 'PATH_INFO':'/foo/bar'}
- ctx, name, subpath = mw(environ)
- self.assertEqual(context, ctx)
- self.assertEqual(name, 'bar')
- self.assertEqual(subpath, [])
-
- def test_call_withconn_getitem_withpath_withsubpath(self):
- mw = self._makeOne('dbname')
- context = DummyContext()
- context2 = DummyContext(context)
- environ = {'repoze.zodbconn.dbname': DummyConnection(context2),
- 'PATH_INFO':'/foo/bar/baz/buz'}
- ctx, name, subpath = mw(environ)
- self.assertEqual(context, ctx)
- self.assertEqual(name, 'bar')
- self.assertEqual(subpath, ['baz', 'buz'])
-
- def test_call_withprefix(self):
- mw = self._makeOne('dbname', ['a', 'b'])
- context = DummyContext()
- context2 = DummyContext(context)
- context3 = DummyContext(context2)
- environ = {'repoze.zodbconn.dbname': DummyConnection(context3),
- 'PATH_INFO':'/foo/bar/baz/buz'}
- ctx, name, subpath = mw(environ)
- self.assertEqual(context, ctx)
- self.assertEqual(name, 'foo')
- self.assertEqual(subpath, ['bar', 'baz', 'buz'])
-
-class DummyNoGetitem:
- pass
-
-class DummyContext:
- def __init__(self, next=None):
- self.next = next
-
- def __getitem__(self, name):
- if self.next is None:
- raise KeyError, name
- return self.next
-
-class DummyConnection:
- def __init__(self, result):
- self.result = result
- def open(self):
- return self.result
-
-