def test_send_message(self): self.factory.makePerson(email='*****@*****.**', name='me') user = self.factory.makePerson(email='*****@*****.**', name='him') subject = 'test subject' body = 'test body' recipients_set = NotificationRecipientSet() recipients_set.add(user, 'test reason', 'test rationale') pop_notifications() send_direct_contact_email('*****@*****.**', recipients_set, subject, body) notifications = pop_notifications() notification = notifications[0] self.assertEqual(1, len(notifications)) self.assertEqual('Me <*****@*****.**>', notification['From']) self.assertEqual('Him <*****@*****.**>', notification['To']) self.assertEqual(subject, notification['Subject']) self.assertEqual( 'test rationale', notification['X-Launchpad-Message-Rationale']) self.assertIs(None, notification['Precedence']) self.assertTrue('launchpad' in notification['Message-ID']) self.assertEqual( '\n'.join([ '%s' % body, '-- ', 'This message was sent from Launchpad by', 'Me (http://launchpad.dev/~me)', 'test reason.', 'For more information see', 'https://help.launchpad.net/YourAccount/ContactingPeople']), notification.get_payload())
def test_send_message(self): self.factory.makePerson(email='*****@*****.**', name='me') user = self.factory.makePerson(email='*****@*****.**', name='him') subject = 'test subject' body = 'test body' recipients_set = NotificationRecipientSet() recipients_set.add(user, 'test reason', 'test rationale') pop_notifications() send_direct_contact_email('*****@*****.**', recipients_set, subject, body) notifications = pop_notifications() notification = notifications[0] self.assertEqual(1, len(notifications)) self.assertEqual('Me <*****@*****.**>', notification['From']) self.assertEqual('Him <*****@*****.**>', notification['To']) self.assertEqual(subject, notification['Subject']) self.assertEqual('test rationale', notification['X-Launchpad-Message-Rationale']) self.assertIs(None, notification['Precedence']) self.assertTrue('launchpad' in notification['Message-ID']) self.assertEqual( '\n'.join([ '%s' % body, '-- ', 'This message was sent from Launchpad by', 'Me (http://launchpad.dev/~me)', 'test reason.', 'For more information see', 'https://help.launchpad.net/YourAccount/ContactingPeople' ]), notification.get_payload())
def test_name_utf8_encoding(self): # Names are encoded in the From and To headers. self.factory.makePerson(email='*****@*****.**', displayname=u'sn\xefrf') user = self.factory.makePerson( email='*****@*****.**', displayname=u'pti\xedng') recipients_set = NotificationRecipientSet() recipients_set.add(user, 'test reason', 'test rationale') pop_notifications() send_direct_contact_email('*****@*****.**', recipients_set, 'test', 'test') notifications = pop_notifications() notification = notifications[0] self.assertEqual( '=?utf-8?b?c27Dr3Jm?= <*****@*****.**>', notification['From']) self.assertEqual( '=?utf-8?q?pti=C3=ADng?= <*****@*****.**>', notification['To'])
def test_name_utf8_encoding(self): # Names are encoded in the From and To headers. self.factory.makePerson(email='*****@*****.**', displayname=u'sn\xefrf') user = self.factory.makePerson(email='*****@*****.**', displayname=u'pti\xedng') recipients_set = NotificationRecipientSet() recipients_set.add(user, 'test reason', 'test rationale') pop_notifications() send_direct_contact_email('*****@*****.**', recipients_set, 'test', 'test') notifications = pop_notifications() notification = notifications[0] self.assertEqual('=?utf-8?b?c27Dr3Jm?= <*****@*****.**>', notification['From']) self.assertEqual('=?utf-8?q?pti=C3=ADng?= <*****@*****.**>', notification['To'])
def test_wrapping(self): self.factory.makePerson(email='*****@*****.**') user = self.factory.makePerson() recipients_set = NotificationRecipientSet() recipients_set.add(user, 'test reason', 'test rationale') pop_notifications() body = 'Can you help me? ' * 8 send_direct_contact_email('*****@*****.**', recipients_set, 'subject', body) notifications = pop_notifications() body, footer = notifications[0].get_payload().split('-- ') self.assertEqual( 'Can you help me? Can you help me? Can you help me? ' 'Can you help me? Can\n' 'you help me? Can you help me? Can you help me? ' 'Can you help me?\n', body)
def test_empty_recipient_set(self): # The recipient set can be empty. No messages are sent and the # action does not count toward the daily quota. self.factory.makePerson(email='*****@*****.**', name='me') user = self.factory.makePerson(email='*****@*****.**', name='him') recipients_set = NotificationRecipientSet() old_message = self.factory.makeSignedMessage(email_address='*****@*****.**') authorization = IDirectEmailAuthorization(user) for action in xrange(authorization.message_quota - 1): authorization.record(old_message) pop_notifications() send_direct_contact_email( '*****@*****.**', recipients_set, 'subject', 'body') notifications = pop_notifications() self.assertEqual(0, len(notifications)) self.assertTrue(authorization.is_allowed)
def test_empty_recipient_set(self): # The recipient set can be empty. No messages are sent and the # action does not count toward the daily quota. self.factory.makePerson(email='*****@*****.**', name='me') user = self.factory.makePerson(email='*****@*****.**', name='him') recipients_set = NotificationRecipientSet() old_message = self.factory.makeSignedMessage(email_address='*****@*****.**') authorization = IDirectEmailAuthorization(user) for action in xrange(authorization.message_quota - 1): authorization.record(old_message) pop_notifications() send_direct_contact_email('*****@*****.**', recipients_set, 'subject', 'body') notifications = pop_notifications() self.assertEqual(0, len(notifications)) self.assertTrue(authorization.is_allowed)