-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: #895 Signed-off-by: Aurélien Bompard <[email protected]>
- Loading branch information
Showing
11 changed files
with
119 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add a footer to email notifications with a link to the rule that generated it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,7 @@ async def test_consumer_call_tracked( | |
assert n.content == EmailNotificationContent( | ||
body="Body of message on dummy.topic\n", | ||
headers={"Subject": "Message on dummy.topic", "To": "[email protected]"}, | ||
footer="Sent by Fedora Notifications: https://notifications.fedoraproject.org/rules/1", | ||
) | ||
|
||
result = await db_async_session.execute(select(model.Generated)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,31 @@ | |
import httpx | ||
import pytest | ||
|
||
from fmn.database import model | ||
from fmn.database.model.destination import Destination, get_extra | ||
|
||
|
||
async def test_email(make_mocked_message): | ||
d = Destination(id=1, protocol="email", address="[email protected]") | ||
@pytest.fixture | ||
async def rule_obj(db_async_session): | ||
user = model.User(name="allkneelbeforezod") | ||
tracking_rule = model.TrackingRule(name="datrackingrule") | ||
generation_rules = [model.GenerationRule()] | ||
rule = model.Rule(user=user, tracking_rule=tracking_rule, generation_rules=generation_rules) | ||
db_async_session.add(rule) | ||
await db_async_session.flush() | ||
yield rule | ||
await db_async_session.rollback() | ||
|
||
|
||
async def test_email(make_mocked_message, db_async_session, rule_obj): | ||
d = Destination( | ||
id=1, | ||
protocol="email", | ||
address="[email protected]", | ||
generation_rule_id=rule_obj.generation_rules[0].id, | ||
) | ||
db_async_session.add(d) | ||
|
||
message = make_mocked_message( | ||
topic="dummy", | ||
body={ | ||
|
@@ -25,14 +45,21 @@ async def test_email(make_mocked_message): | |
assert result == { | ||
"headers": {"To": "[email protected]", "Subject": "[dummy] dummy summary"}, | ||
"body": "dummy content\nhttps://dummy.org/dummylink", | ||
"footer": "Sent by Fedora Notifications: https://notifications.fedoraproject.org/rules/1", | ||
} | ||
|
||
|
||
async def test_email_with_extra(make_mocked_message, mocker): | ||
async def test_email_with_extra(make_mocked_message, mocker, db_async_session, rule_obj): | ||
mocker.patch( | ||
"fmn.database.model.destination.get_extra", mock.AsyncMock(return_value="DUMMY EXTRA") | ||
) | ||
d = Destination(id=1, protocol="email", address="[email protected]") | ||
d = Destination( | ||
id=1, | ||
protocol="email", | ||
address="[email protected]", | ||
generation_rule_id=rule_obj.generation_rules[0].id, | ||
) | ||
db_async_session.add(d) | ||
message = make_mocked_message( | ||
topic="dummy", | ||
body={ | ||
|
@@ -42,10 +69,13 @@ async def test_email_with_extra(make_mocked_message, mocker): | |
"url": "https://dummy.org/dummylink", | ||
}, | ||
) | ||
|
||
result = await d.generate(message) | ||
|
||
assert result == { | ||
"headers": {"To": "[email protected]", "Subject": "[dummy] dummy summary"}, | ||
"body": "dummy content\nhttps://dummy.org/dummylink\nDUMMY EXTRA", | ||
"footer": "Sent by Fedora Notifications: https://notifications.fedoraproject.org/rules/1", | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# SPDX-FileCopyrightText: Contributors to the Fedora Project | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from fmn.rules.notification import EmailNotificationContent, IRCNotificationContent | ||
|
||
|
||
def test_compare_other(): | ||
content = EmailNotificationContent(headers={"To": "dummy", "Subject": "dummy"}, body="dummy") | ||
other = IRCNotificationContent(to="dummy", message="dummy") | ||
assert content != other |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,25 @@ async def test_email_disconnected(): | |
|
||
assert smtp.send_message.call_count == 2 | ||
smtp.connect.assert_called_once_with() | ||
|
||
|
||
async def test_email_handle_with_footer(): | ||
smtp = MagicMock(spec=SMTP) | ||
handler = EmailHandler({"from": "FMN <[email protected]>"}) | ||
handler._smtp = smtp | ||
|
||
await handler.handle( | ||
{ | ||
"headers": {"To": "[email protected]", "Subject": "Testing"}, | ||
"body": "This is a test", | ||
"footer": "This is a footer.", | ||
} | ||
) | ||
|
||
smtp.send_message.assert_called_once() | ||
|
||
sent = smtp.send_message.call_args[0][0] | ||
assert sent["To"] == "[email protected]" | ||
assert sent["Subject"] == "Testing" | ||
assert sent.get_body().get_content() == "This is a test\n\n-- \nThis is a footer.\n" | ||
assert sent.get_content_type() == "text/plain" |