From 93438705d6ae5d519af5e8c2ef641afbf44289a5 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Fri, 19 Jan 2024 10:58:57 +0100 Subject: [PATCH] Remove dependency to kinto-signer (#452) * Remove obsolete events binding https://github.com/mozilla/remote-settings/blob/15776cebb18d3ae0fb633335417af89ceafff40f/kinto-remote-settings/src/kinto_remote_settings/signer/__init__.py#L264-L271 * Remove useless mentions of kinto-signer --- README.rst | 4 +- src/kinto_emailer/__init__.py | 9 ----- tests/test_includeme.py | 74 +---------------------------------- 3 files changed, 4 insertions(+), 83 deletions(-) diff --git a/README.rst b/README.rst index dc4c4e8..b27da3a 100644 --- a/README.rst +++ b/README.rst @@ -138,8 +138,8 @@ The possible filters are: * ``collection_id`` (default: all) * ``record_id`` (default: all) * ``event``: ``kinto.core.events.AfterResourceChanged`` (default), or - ``kinto_signer.events.ReviewRequested``, ``kinto_signer.events.ReviewApproved``, - ``kinto_signer.events.ReviewRejected`` + ``kinto_remote_settings.signer.events.ReviewRequested``, ``kinto_remote_settings.signer.events.ReviewApproved``, + ``kinto_remote_settings.signer.events.ReviewRejected`` If a filter value starts with the special character ``^``, then the matching will consider the filter value to be a regular expression. diff --git a/src/kinto_emailer/__init__.py b/src/kinto_emailer/__init__.py index d3f325f..b3dc515 100644 --- a/src/kinto_emailer/__init__.py +++ b/src/kinto_emailer/__init__.py @@ -210,12 +210,3 @@ def includeme(config): config.add_subscriber( send_notification, AfterResourceChanged, for_resources=("record", "collection") ) - # In case kinto-signer is installed, plug events. - try: - from kinto_signer.events import ReviewApproved, ReviewRejected, ReviewRequested - - config.add_subscriber(send_notification, ReviewRequested) - config.add_subscriber(send_notification, ReviewApproved) - config.add_subscriber(send_notification, ReviewRejected) - except ImportError: # pragma: no cover - pass diff --git a/tests/test_includeme.py b/tests/test_includeme.py index 7009f76..137539e 100644 --- a/tests/test_includeme.py +++ b/tests/test_includeme.py @@ -237,7 +237,7 @@ def test_get_messages_can_filter_by_event_class(self): "kinto-emailer": { "hooks": [ { - "event": "kinto_signer.events.ReviewRequested", + "event": "mylib.MyEvent", "template": "Poll changed.", "recipients": ["me@you.com"], } @@ -248,7 +248,7 @@ def test_get_messages_can_filter_by_event_class(self): messages = get_messages(self.storage, self.payload) assert len(messages) == 0 - self.payload.update({"event": "kinto_signer.events.ReviewRequested"}) + self.payload.update({"event": "mylib.MyEvent"}) messages = get_messages(self.storage, self.payload) assert len(messages) == 1 @@ -378,76 +378,6 @@ def test_context_contains_settings(self): assert "{settings[project_name]}".format(**context) == "Kinto DEV" -class SignerEventsTest(EmailerTest): - @classmethod - def get_app_settings(cls, extras=None): - settings = super().get_app_settings(extras) - settings["kinto.includes"] += " kinto_signer" - settings["kinto.signer.resources"] = ( - "/buckets/staging/collections/addons;" "/buckets/blocklists/collections/addons" - ) - settings["kinto.signer.group_check_enabled"] = "false" - settings["kinto.signer.to_review_enabled"] = "true" - settings["kinto.signer.signer_backend"] = "kinto_signer.signer.autograph" - settings["kinto.signer.autograph.server_url"] = "http://localhost:8000" - settings["kinto.signer.autograph.hawk_id"] = "not-used-because-mocked" - settings["kinto.signer.autograph.hawk_secret"] = "not-used-because-mocked" - return settings - - def setUp(self): - self._patch_autograph() - collection = { - "kinto-emailer": { - "hooks": [ - { - "event": "kinto_signer.events.ReviewRequested", - "subject": "[{settings[project_name]}]", - "template": "{user_id} requested review on {uri}.", - "recipients": ["me@you.com"], - } - ] - } - } - self.headers = dict(self.headers, **get_user_headers("nous")) - self.app.put("/buckets/staging", headers=self.headers) - self.app.put_json( - "/buckets/staging/collections/addons", {"data": collection}, headers=self.headers - ) - self.app.post_json( - "/buckets/staging/collections/addons/records", - {"data": {"age": 42}}, - headers=self.headers, - ) - - def _patch_autograph(self): - # Patch calls to Autograph. - patch = mock.patch("kinto_signer.signer.autograph.requests") - self.addCleanup(patch.stop) - mocked = patch.start() - mocked.post.return_value.json.return_value = [ - { - "ref": "", - "signature": "", - "hash_algorithm": "", - "signature_encoding": "", - "content-signature": "", - "x5u": "", - } - ] - return patch - - def test_email_is_when_review_is_requested(self): - with mock.patch("kinto_emailer.get_mailer") as get_mailer: - self.app.patch_json( - "/buckets/staging/collections/addons", - {"data": {"status": "to-review"}}, - headers=self.headers, - ) - args, _ = get_mailer().send_immediately.call_args_list[0] - message = args[0] - assert message.subject == "[Emailer DEV]" - - class BatchRequestTest(EmailerTest): def setUp(self): bucket = {