diff options
| author | Chris McDonough <chrism@agendaless.com> | 2010-02-04 13:02:41 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2010-02-04 13:02:41 +0000 |
| commit | 98e0d06a77fef4cec0266510f2d02975ce56c405 (patch) | |
| tree | 3e59622fe467bc2ac4019c95c956f8ed43ce892c /repoze | |
| parent | cb968d991b5466286aa3d53af20d405c3c48a17c (diff) | |
| download | pyramid-98e0d06a77fef4cec0266510f2d02975ce56c405.tar.gz pyramid-98e0d06a77fef4cec0266510f2d02975ce56c405.tar.bz2 pyramid-98e0d06a77fef4cec0266510f2d02975ce56c405.zip | |
- 1.2b4 introduced a bug whereby views added via a route configuration
that named a view callable and also a ``view_attr`` became broken.
Symptom: ``MyViewClass is not callable`` or the ``__call__`` of a
class was being called instead of the method named via
``view_attr``.
Diffstat (limited to 'repoze')
| -rw-r--r-- | repoze/bfg/configuration.py | 1 | ||||
| -rw-r--r-- | repoze/bfg/tests/restbugapp/__init__.py | 1 | ||||
| -rw-r--r-- | repoze/bfg/tests/restbugapp/configure.zcml | 25 | ||||
| -rw-r--r-- | repoze/bfg/tests/restbugapp/views.py | 18 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_configuration.py | 14 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_integration.py | 10 |
6 files changed, 69 insertions, 0 deletions
diff --git a/repoze/bfg/configuration.py b/repoze/bfg/configuration.py index 8a254bdec..025c6e048 100644 --- a/repoze/bfg/configuration.py +++ b/repoze/bfg/configuration.py @@ -1064,6 +1064,7 @@ class Configurator(object): name='', route_name=name, renderer=view_renderer, + attr=view_attr, _info=_info, ) diff --git a/repoze/bfg/tests/restbugapp/__init__.py b/repoze/bfg/tests/restbugapp/__init__.py new file mode 100644 index 000000000..5bb534f79 --- /dev/null +++ b/repoze/bfg/tests/restbugapp/__init__.py @@ -0,0 +1 @@ +# package diff --git a/repoze/bfg/tests/restbugapp/configure.zcml b/repoze/bfg/tests/restbugapp/configure.zcml new file mode 100644 index 000000000..67954b892 --- /dev/null +++ b/repoze/bfg/tests/restbugapp/configure.zcml @@ -0,0 +1,25 @@ +<configure xmlns="http://namespaces.repoze.org/bfg"> + + <include package="repoze.bfg.includes"/> + + <route + path="/pet" + name="gameactions_pet_get_pets" + view=".views.PetRESTView" + view_attr="GET" + request_method="GET" + permission="view" + renderer="json" + /> + + <route + path="/pet" + name="gameactions_pet_care_for_pet" + view=".views.PetRESTView" + view_attr="POST" + request_method="POST" + permission="view" + renderer="json" + /> + +</configure> diff --git a/repoze/bfg/tests/restbugapp/views.py b/repoze/bfg/tests/restbugapp/views.py new file mode 100644 index 000000000..eb6a6591d --- /dev/null +++ b/repoze/bfg/tests/restbugapp/views.py @@ -0,0 +1,18 @@ +from webob import Response + +class BaseRESTView(object): + def __init__(self, context, request): + self.context = context + self.request = request + +class PetRESTView(BaseRESTView): + """ REST Controller to control action of an avatar """ + def __init__(self, context, request): + super(PetRESTView, self).__init__(context, request) + + def GET(self): + return Response('gotten') + + def POST(self): + return Response('posted') + diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py index 78e1949e4..90413f1d6 100644 --- a/repoze/bfg/tests/test_configuration.py +++ b/repoze/bfg/tests/test_configuration.py @@ -1197,6 +1197,20 @@ class ConfiguratorTests(unittest.TestCase): self._assertRoute(config, 'name', 'path') self.assertEqual(wrapper(None, None).body, 'Hello!') + def test_add_route_with_view_attr(self): + config = self._makeOne() + self._registerRenderer(config) + class View(object): + def __init__(self, context, request): + pass + def alt(self): + return 'OK' + config.add_route('name', 'path', view=View, view_attr='alt') + request_type = self._getRouteRequestIface(config, 'name') + wrapper = self._getViewCallable(config, None, request_type) + self._assertRoute(config, 'name', 'path') + self.assertEqual(wrapper(None, None), 'OK') + def test_add_route_with_view_renderer_alias(self): config = self._makeOne() self._registerRenderer(config) diff --git a/repoze/bfg/tests/test_integration.py b/repoze/bfg/tests/test_integration.py index c033f0e03..35d113c5f 100644 --- a/repoze/bfg/tests/test_integration.py +++ b/repoze/bfg/tests/test_integration.py @@ -141,6 +141,16 @@ class TestHybridApp(TwillBase): self.assertEqual(browser.get_code(), 200) self.assertEqual(browser.get_html(), 'global2') +class TestRestBugApp(TwillBase): + # test bug reported by delijati 2010/2/3 (http://pastebin.com/d4cc15515) + config = 'repoze.bfg.tests.restbugapp:configure.zcml' + def test_it(self): + import twill.commands + browser = twill.commands.get_browser() + browser.go('http://localhost:6543/pet') + self.assertEqual(browser.get_code(), 200) + self.assertEqual(browser.get_html(), 'gotten') + class DummyContext(object): pass |
