Skip to content

Commit

Permalink
Remove dependency to kinto-signer (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem authored Jan 19, 2024
1 parent 2082194 commit 9343870
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 83 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 0 additions & 9 deletions src/kinto_emailer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 2 additions & 72 deletions tests/test_includeme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": ["[email protected]"],
}
Expand All @@ -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

Expand Down Expand Up @@ -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": ["[email protected]"],
}
]
}
}
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 = {
Expand Down

0 comments on commit 9343870

Please sign in to comment.