-
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.
Email sender: improve the Date header, add a Received header
- Set the Date to the message's sent-at header value - Add a Received header because FMN acts as a "gateway" Signed-off-by: Aurélien Bompard <[email protected]>
- Loading branch information
Showing
6 changed files
with
68 additions
and
9 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
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from datetime import datetime | ||
from email.utils import format_datetime | ||
from unittest import mock | ||
|
||
import httpx | ||
|
@@ -42,8 +44,13 @@ async def test_email(make_mocked_message, db_async_session, rule_obj): | |
}, | ||
) | ||
result = await d.generate(message) | ||
date_header = format_datetime(datetime.fromisoformat(message._headers["sent-at"])) | ||
assert result == { | ||
"headers": {"To": "[email protected]", "Subject": "[dummy] dummy summary"}, | ||
"headers": { | ||
"To": "[email protected]", | ||
"Subject": "[dummy] dummy summary", | ||
"Date": date_header, | ||
}, | ||
"body": "dummy content\nhttps://dummy.org/dummylink", | ||
"footer": "Sent by Fedora Notifications: https://notifications.fedoraproject.org/rules/1", | ||
} | ||
|
@@ -72,8 +79,13 @@ async def test_email_with_extra(make_mocked_message, mocker, db_async_session, r | |
|
||
result = await d.generate(message) | ||
|
||
date_header = format_datetime(datetime.fromisoformat(message._headers["sent-at"])) | ||
assert result == { | ||
"headers": {"To": "[email protected]", "Subject": "[dummy] dummy summary"}, | ||
"headers": { | ||
"To": "[email protected]", | ||
"Subject": "[dummy] dummy summary", | ||
"Date": date_header, | ||
}, | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from datetime import date | ||
from email.utils import parsedate_to_datetime | ||
from unittest.mock import MagicMock | ||
|
||
from aiosmtplib import SMTP, SMTPServerDisconnected | ||
|
@@ -40,9 +38,8 @@ async def test_email_handle(): | |
sent = smtp.send_message.call_args[0][0] | ||
assert sent["To"] == "[email protected]" | ||
assert sent["Subject"] == "Testing" | ||
assert "Date" in sent | ||
sent_date = parsedate_to_datetime(sent["Date"]) | ||
assert sent_date.date() == date.today() | ||
assert "Received" in sent | ||
assert sent["Received"].startswith("from fedora-messaging by FMN") | ||
assert sent.get_body().get_content() == "This is a test\n" | ||
assert sent.get_content_type() == "text/plain" | ||
|
||
|