コード例 #1
0
 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())
コード例 #2
0
 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())
コード例 #3
0
 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'])
コード例 #4
0
 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'])
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
0
 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)
コード例 #8
0
 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)