launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26450
[Merge] ~cjwatson/launchpad:py3-test-simple-sendmail into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-test-simple-sendmail into launchpad:master.
Commit message:
Fix email sorting in test_simple_sendmail
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/398782
Sorting by the message bodies isn't reliable enough, so sort the test messages by their From: field instead.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-test-simple-sendmail into launchpad:master.
diff --git a/lib/lp/services/mail/tests/test_stub.py b/lib/lp/services/mail/tests/test_stub.py
index fedb7d2..f3b1c01 100644
--- a/lib/lp/services/mail/tests/test_stub.py
+++ b/lib/lp/services/mail/tests/test_stub.py
@@ -60,17 +60,19 @@ def test_simple_sendmail():
We have two emails, but we have no idea what order they are in!
- Let's sort them, and verify that the first one is the one we want
- because only the first one contains the string 'nobody@xxxxxxxxxxx'
- in its raw message.
+ Let's sort them by their From: fields, and verify that the second one is
+ the one we want because only the second one contains the string
+ 'nobody@xxxxxxxxxxx' in its raw message.
- >>> sorted_test_emails = sorted(list(stub.test_emails))
+ >>> sorted_test_emails = sorted(
+ ... list(stub.test_emails),
+ ... key=lambda email: message_from_bytes(email[2])['From'])
>>> for from_addr, to_addrs, raw_message in sorted_test_emails:
... print(from_addr, to_addrs, b'nobody@xxxxxxxxxxx' in raw_message)
- bounces@xxxxxxxxxxxxx ['nobody2@xxxxxxxxxxx'] True
bounces@xxxxxxxxxxxxx ['nobody2@xxxxxxxxxxx'] False
+ bounces@xxxxxxxxxxxxx ['nobody2@xxxxxxxxxxx'] True
- >>> from_addr, to_addrs, raw_message = sorted_test_emails[0]
+ >>> from_addr, to_addrs, raw_message = sorted_test_emails[1]
>>> from_addr
'bounces@xxxxxxxxxxxxx'
>>> to_addrs