From 19ae96b97ea055c2e36c8fb86819c426b37ab6af Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Sat, 27 Jan 2024 17:33:26 -0700 Subject: revert restriction to eventonly predicates, allow a predicate to receive all args --- tests/pkgs/eventonly/__init__.py | 19 +++++++++++++++++++ tests/test_integration.py | 8 +++++++- 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/pkgs/eventonly/__init__.py b/tests/pkgs/eventonly/__init__.py index e45a5691f..f7a9270dc 100644 --- a/tests/pkgs/eventonly/__init__.py +++ b/tests/pkgs/eventonly/__init__.py @@ -15,6 +15,19 @@ class Yup: return getattr(event.response, 'yup', False) +class YupWithAllArgs: + def __init__(self, val, config): + self.val = val + + def text(self): + return f'yup_with_extra_args = {self.val}' + + phash = text + + def __call__(self, event, *args): + return getattr(event.response, 'yup', False) + + class Foo: def __init__(self, response): self.response = response @@ -54,6 +67,11 @@ def foobaryup2(event, context): event.response.text += 'foobaryup2 ' +@subscriber([Foo, Bar], yup=True, yup_with_all_args=True) +def foobaryup3(event, context): + event.response.text += 'foobaryup3 ' + + @view_config(name='sendfoo') def sendfoo(request): response = request.response @@ -72,4 +90,5 @@ def sendfoobar(request): def includeme(config): config.add_subscriber_predicate('yup', Yup) + config.add_subscriber_predicate('yup_with_all_args', YupWithAllArgs) config.scan('tests.pkgs.eventonly') diff --git a/tests/test_integration.py b/tests/test_integration.py index 63a7088e9..7ca11e81e 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -213,7 +213,13 @@ class TestEventOnlySubscribers(IntegrationBase, unittest.TestCase): res = self.testapp.get('/sendfoobar', status=200) self.assertEqual( sorted(res.body.split()), - [b'foobar', b'foobar2', b'foobaryup', b'foobaryup2'], + [ + b'foobar', + b'foobar2', + b'foobaryup', + b'foobaryup2', + b'foobaryup3', + ], ) -- cgit v1.2.3