From d6cb3c1b68e752922a149d37a8d208b7d01dbe14 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 4 Jul 2008 07:07:27 +0000 Subject: Complete tests. --- repoze/bfg/tests/test_zodb.py | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'repoze/bfg/tests') diff --git a/repoze/bfg/tests/test_zodb.py b/repoze/bfg/tests/test_zodb.py index 3e08968b4..d28622953 100644 --- a/repoze/bfg/tests/test_zodb.py +++ b/repoze/bfg/tests/test_zodb.py @@ -24,6 +24,72 @@ class ZODBGetitemPolicyTests(unittest.TestCase): 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 -- cgit v1.2.3