[Repoze-checkins] r1229 - in repoze.bfg/trunk/repoze/bfg: . tests

Chris McDonough chrism at agendaless.com
Fri Jul 4 03:07:27 EDT 2008


Author: Chris McDonough <chrism at agendaless.com>
Date: Fri Jul  4 03:07:27 2008
New Revision: 1229

Log:
Complete tests.


Modified:
   repoze.bfg/trunk/repoze/bfg/tests/test_zodb.py
   repoze.bfg/trunk/repoze/bfg/zodb.py

Modified: repoze.bfg/trunk/repoze/bfg/tests/test_zodb.py
==============================================================================
--- repoze.bfg/trunk/repoze/bfg/tests/test_zodb.py	(original)
+++ repoze.bfg/trunk/repoze/bfg/tests/test_zodb.py	Fri Jul  4 03:07:27 2008
@@ -24,6 +24,72 @@
         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
 
     

Modified: repoze.bfg/trunk/repoze/bfg/zodb.py
==============================================================================
--- repoze.bfg/trunk/repoze/bfg/zodb.py	(original)
+++ repoze.bfg/trunk/repoze/bfg/zodb.py	Fri Jul  4 03:07:27 2008
@@ -28,6 +28,8 @@
             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)


More information about the Repoze-checkins mailing list