From 4be1e6ccd46adc6c9515d68bee12965cfc7e285e Mon Sep 17 00:00:00 2001 From: tosh Date: Mon, 26 Jun 2017 19:03:45 -0500 Subject: add support for custom category in view_config decorator --- pyramid/tests/test_view.py | 20 ++++++++++++++++++++ pyramid/view.py | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pyramid/tests/test_view.py b/pyramid/tests/test_view.py index e03487a70..43459947c 100644 --- a/pyramid/tests/test_view.py +++ b/pyramid/tests/test_view.py @@ -566,6 +566,26 @@ class TestViewConfigDecorator(unittest.TestCase): decorator(foo) self.assertEqual(venusian.depth, 2) + def test_call_withoutcategory(self): + decorator = self._makeOne() + venusian = DummyVenusian() + decorator.venusian = venusian + def foo(): pass + decorator(foo) + attachments = venusian.attachments + category = attachments[0][2] + self.assertEqual(category, 'pyramid') + + def test_call_withcategory(self): + decorator = self._makeOne(category='not_pyramid') + venusian = DummyVenusian() + decorator.venusian = venusian + def foo(): pass + decorator(foo) + attachments = venusian.attachments + category = attachments[0][2] + self.assertEqual(category, 'not_pyramid') + class Test_append_slash_notfound_view(BaseTest, unittest.TestCase): def _callFUT(self, context, request): from pyramid.view import append_slash_notfound_view diff --git a/pyramid/view.py b/pyramid/view.py index dc4aae3fa..a3f193011 100644 --- a/pyramid/view.py +++ b/pyramid/view.py @@ -215,12 +215,13 @@ class view_config(object): def __call__(self, wrapped): settings = self.__dict__.copy() depth = settings.pop('_depth', 0) + category = settings.pop('category', 'pyramid') def callback(context, name, ob): config = context.config.with_package(info.module) config.add_view(view=ob, **settings) - info = self.venusian.attach(wrapped, callback, category='pyramid', + info = self.venusian.attach(wrapped, callback, category=category, depth=depth + 1) if info.scope == 'class': -- cgit v1.2.3