Beispiel #1
0
 def test_limited_retry_errors_both_fail(self):
     errors = (MAX_ATTEMPTS * 2) * [SMTPServerDisconnected]
     with mock.patch('django.core.mail.EmailMessage.send',
                     side_effect=errors):
         mailusers.Command().handle()
         self.assert_fred_failed()
         self.assert_barney_failed()
Beispiel #2
0
 def test_mail_users_grandfather(self):
     """
     Test sending grandfather emails.
     """
     fut = mailusers.Command().handle
     fut()
     self.assertEqual(json.loads(self.fred.linkedin.emailed_courses),
                      ['TESTX/1/TEST1', 'TESTX/2/TEST2'])
     self.assertEqual(json.loads(self.barney.linkedin.emailed_courses),
                      ['TESTX/3/TEST3'])
     self.assertEqual(json.loads(self.adam.linkedin.emailed_courses),
                      ['TESTX/3/TEST3'])
     self.assertEqual(len(mail.outbox), 3)
     self.assertEqual(mail.outbox[0].to,
                      ['Fred Flintstone <*****@*****.**>'])
     self.assertEqual(
         mail.outbox[0].subject,
         'Fred Flintstone, Add your Achievements to your LinkedIn Profile')
     self.assertEqual(mail.outbox[1].to,
                      ['Barney Rubble <*****@*****.**>'])
     self.assertEqual(
         mail.outbox[1].subject,
         'Barney Rubble, Add your Achievements to your LinkedIn Profile')
     self.assertEqual(
         mail.outbox[2].subject,
         u'Adam (חיים פּלי), Add your Achievements to your LinkedIn Profile')
Beispiel #3
0
 def test_total_failure(self):
     # If we get this error, we just stop, so neither user gets email.
     errors = [SESIdentityNotVerifiedError]
     with mock.patch('django.core.mail.EmailMessage.send',
                     side_effect=errors):
         mailusers.Command().handle()
         self.assert_fred_failed()
         self.assert_barney_failed()
Beispiel #4
0
 def test_single_email_failure(self):
     # Test error that will immediately fail a single user, but not the run
     with mock.patch('django.core.mail.EmailMessage.send',
                     side_effect=[SESIllegalAddressError, None]):
         mailusers.Command().handle()
         # Fred should fail with a send error, but we should still run Barney
         self.assert_fred_failed()
         self.assert_barney_worked()
Beispiel #5
0
 def test_limited_retry_errors_both_succeed(self):
     errors = [
         SMTPServerDisconnected, SMTPServerDisconnected,
         SMTPServerDisconnected, None, SMTPServerDisconnected, None
     ]
     with mock.patch('django.core.mail.EmailMessage.send',
                     side_effect=errors):
         mailusers.Command().handle()
         self.assert_fred_worked()
         self.assert_barney_worked()
Beispiel #6
0
 def test_mail_users_grandfather_mock(self):
     """
     test that we aren't sending anything when in mock_run mode
     """
     fut = mailusers.Command().handle
     fut(mock_run=True)
     self.assertEqual(json.loads(self.fred.linkedin.emailed_courses), [])
     self.assertEqual(json.loads(self.barney.linkedin.emailed_courses), [])
     self.assertEqual(json.loads(self.adam.linkedin.emailed_courses), [])
     self.assertEqual(len(mail.outbox), 0)
Beispiel #7
0
    def test_infinite_retry_errors(self, sleep):
        def _raise_err():
            """Need this because SMTPDataError takes args"""
            raise SMTPDataError("", "")

        errors = (MAX_ATTEMPTS * 2) * [_raise_err] + [None, None]
        with mock.patch('django.core.mail.EmailMessage.send',
                        side_effect=errors):
            mailusers.Command().handle()
            self.assert_fred_worked()
            self.assert_barney_worked()
Beispiel #8
0
 def test_mail_users_with_whitelist(self):
     """
     Test emailing users.
     """
     fut = mailusers.Command().handle
     fut()
     self.assertEqual(json.loads(self.barney.linkedin.emailed_courses),
                      ['TESTX/3/TEST3'])
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].to,
                      ['Barney Rubble <*****@*****.**>'])
Beispiel #9
0
 def test_certificate_url(self):
     self.cert1.created_date = datetime.datetime(2010,
                                                 8,
                                                 15,
                                                 0,
                                                 0,
                                                 tzinfo=utc)
     self.cert1.save()
     fut = mailusers.Command().certificate_url
     self.assertEqual(
         fut(self.cert1), 'http://www.linkedin.com/profile/guided?'
         'pfCertificationName=TEST1&'
         'pfAuthorityId=0000000&'
         'pfCertificationUrl=http%3A%2F%2Ftest.foo%2Ftest&pfLicenseNo=TESTX%2F1%2FTEST1&'
         'pfCertStartDate=201005&_mSplash=1&'
         'trk=eml-prof-edX-1-gf&startTask=CERTIFICATION_NAME&force=true')
Beispiel #10
0
    def test_transaction_semantics(self):
        fut = mailusers.Command().handle
        with mock.patch(
                'linkedin.management.commands.linkedin_mailusers.Command.send_grandfather_email',
                return_value=True,
                side_effect=[True, KeyboardInterrupt]):
            try:
                fut()
            except KeyboardInterrupt:
                # expect that this will be uncaught

                # check that fred's emailed_courses were updated
                self.assertEqual(
                    json.loads(self.fred.linkedin.emailed_courses),
                    ['TESTX/1/TEST1', 'TESTX/2/TEST2'])

                #check that we did not update barney
                self.assertEqual(
                    json.loads(self.barney.linkedin.emailed_courses), [])