# HG changeset patch # User Sylvain Thénault # Date 1299604900 -3600 # Node ID f26a1cbddc9143db8df3b433aa5ce4875b533330 # Parent ea22892e82d4d508344a6022baa675e3206b856d [testlib] New assertion method assertSentEmail() to test presence of emails in system mailbox diff -r ea22892e82d4 -r f26a1cbddc91 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)')