[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 08 Mar 2011 18:21:40 +0100
branchstable
changeset 7060 f26a1cbddc91
parent 7058 ea22892e82d4
child 7061 bb2080547722
child 7063 b07ee816bffb
[testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox
devtools/testlib.py
--- a/devtools/testlib.py	Tue Mar 08 18:16:44 2011 +0100
+++ b/devtools/testlib.py	Tue Mar 08 18:21:40 2011 +0100
@@ -853,6 +853,27 @@
             raise self.failureException("doctest file '%s' failed"
                                         % testfile)
 
+    # notifications ############################################################
+
+    def assertSentEmail(self, subject, recipients=None, nb_msgs=None):
+        """test recipients in system mailbox for given email subject
+
+        :param subject: email subject to find in mailbox
+        :param recipients: list of email recipients
+        :param nb_msgs: expected number of entries
+        :returns: list of matched emails
+        """
+        messages = [email for email in MAILBOX
+                    if email.message.get('Subject') == subject]
+        if recipients is not None:
+            sent_to = set()
+            for msg in messages:
+                sent_to.update(msg.recipients)
+            self.assertSetEqual(set(recipients), sent_to)
+        if nb_msgs is not None:
+            self.assertEqual(len(MAILBOX), nb_msgs)
+        return messages
+
     # deprecated ###############################################################
 
     @deprecated('[3.8] use self.execute(...).get_entity(0, 0)')