From 98e0d06a77fef4cec0266510f2d02975ce56c405 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 4 Feb 2010 13:02:41 +0000 Subject: - 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``. --- CHANGES.txt | 12 ++++++++++++ repoze/bfg/configuration.py | 1 + repoze/bfg/tests/restbugapp/__init__.py | 1 + repoze/bfg/tests/restbugapp/configure.zcml | 25 +++++++++++++++++++++++++ repoze/bfg/tests/restbugapp/views.py | 18 ++++++++++++++++++ repoze/bfg/tests/test_configuration.py | 14 ++++++++++++++ repoze/bfg/tests/test_integration.py | 10 ++++++++++ 7 files changed, 81 insertions(+) create mode 100644 repoze/bfg/tests/restbugapp/__init__.py create mode 100644 repoze/bfg/tests/restbugapp/configure.zcml create mode 100644 repoze/bfg/tests/restbugapp/views.py diff --git a/CHANGES.txt b/CHANGES.txt index 1d5d7ce08..a2039c2c4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,15 @@ +Next release +============ + +Bug Fixes +--------- + +- 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``. + 1.2b4 (2010-02-03) ================== 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 @@ + + + + + + + + + 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 -- cgit v1.2.3