diff options
| author | Chris McDonough <chrism@agendaless.com> | 2008-07-04 07:07:27 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2008-07-04 07:07:27 +0000 |
| commit | d6cb3c1b68e752922a149d37a8d208b7d01dbe14 (patch) | |
| tree | bc92681568dfe333e3e83bf2c371bfdafe323f1f /repoze | |
| parent | 612d7478492b8c96cb138b7ee6f9b1829d046fc8 (diff) | |
| download | pyramid-d6cb3c1b68e752922a149d37a8d208b7d01dbe14.tar.gz pyramid-d6cb3c1b68e752922a149d37a8d208b7d01dbe14.tar.bz2 pyramid-d6cb3c1b68e752922a149d37a8d208b7d01dbe14.zip | |
Complete tests.
Diffstat (limited to 'repoze')
| -rw-r--r-- | repoze/bfg/tests/test_zodb.py | 66 | ||||
| -rw-r--r-- | repoze/bfg/zodb.py | 2 |
2 files changed, 68 insertions, 0 deletions
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 diff --git a/repoze/bfg/zodb.py b/repoze/bfg/zodb.py index 976c687fb..c13d5fc58 100644 --- a/repoze/bfg/zodb.py +++ b/repoze/bfg/zodb.py @@ -28,6 +28,8 @@ class ZODBGetitemPolicy: element = path.pop(0) try: ob = ob[element] + except AttributeError, what: + raise AttributeError(str(what[0]) + ' (element: '+element+')') except KeyError: if path: name = path.pop(0) |
