diff --git a/test/ai3test/test_mail.py b/test/ai3test/test_mail.py index 06cf2c84b62d54121e18da1a5a3c6765d6b661e0..2ac6df1c729603edbf91282948f5a85d62d21865 100644 --- a/test/ai3test/test_mail.py +++ b/test/ai3test/test_mail.py @@ -81,40 +81,44 @@ class TestMail(TestBase): return unique_id - # Send an email from a to b and find it in c's IMAP account. - def _send_email_and_read_it(self, sender, sender_password, rcpt, - imap_user, imap_password): - unique_id = self._send_email(sender, sender_password, rcpt) - + def _wait_for_message(self, imap_user, imap_password, match_header, match_value, + timeout=300): imap = imaplib.IMAP4_SSL(self.frontend_ip()) imap.login(imap_user, imap_password) imap.select('INBOX') def _check_for_msg(): - logging.info('looking for message <%s>', unique_id) + logging.info('looking for message %s', match_value) typ, data = imap.uid( - 'search', None, 'HEADER', 'X-UniqueID', unique_id) + 'search', None, 'HEADER', match_header, match_value) if typ == 'OK' and data[0]: - logging.info('message <%s> found, fetching uuid "%s"', - unique_id, data[0]) + logging.info('message %s found, fetching uuid "%s"', + match_value, data[0]) typ, msgdata = imap.uid('fetch', data[0], '(RFC822)') if typ != 'OK': raise Exception('error fetching message: %s' % typ) msg = msgdata[0][1] imap.uid('store', data[0], '+FLAGS', r'(\Deleted)') imap.expunge() - logging.info('message <%s> deleted successfully', unique_id) + logging.info('message %s deleted successfully', match_value) return msg return None - deadline = time.time() + 300 - delivered = False + deadline = time.time() + timeout while time.time() < deadline: msg = _check_for_msg() if msg: - delivered = True - break + return True time.sleep(1) + return False + + # Send an email from a to b and find it in c's IMAP account. + def _send_email_and_read_it(self, sender, sender_password, rcpt, + imap_user, imap_password): + unique_id = self._send_email(sender, sender_password, rcpt) + + delivered = self._wait_for_message(imap_user, imap_password, + 'X-UniqueID', unique_id) self.assertTrue(delivered) return msg @@ -230,3 +234,12 @@ class TestMail(TestBase): 'password', 'uno@investici.org', from_addr='uno@investici.org') + + def test_mailman_send_message(self): + # Test user sends an email to a list it is subscribed to. + self._send_email_and_read_it( + self.users['nonpriv']['name'], + self.users['nonpriv']['password'], + 'lista@investici.org', + self.users['nonpriv']['name'], + self.users['nonpriv']['password'])