示例#1
0
 def test_valid_if_mailgun_api_error(self, mock_mailgun_service):
     mock_mailgun_service.side_effect = MailgunAPIError(
         "Mailgun responded with 404")
     try:
         mailgun_email_validator('*****@*****.**')
     except Exception as err:
         raise AssertionError('unexpectedly raised {}'.format(err))
示例#2
0
 def test_valid_if_mailgun_api_error(self, mock_mailgun_service):
     mock_mailgun_service.side_effect = MailgunAPIError(
         "Mailgun responded with 404")
     try:
         mailgun_email_validator('*****@*****.**')
     except Exception as err:
         raise AssertionError('unexpectedly raised {}'.format(err))
示例#3
0
    def test_invalid_if_mailgun_returns_invalid(self, mock_mailgun_service):
        mock_mailgun_service.return_value = (False, None)
        with self.assertRaises(ValidationError) as context:
            mailgun_email_validator('*****@*****.**')

        expected_message = 'The email address you entered does not ' \
                           'appear to exist.'
        self.assertEqual(expected_message, str(context.exception.message))
示例#4
0
    def test_invalid_if_mailgun_returns_invalid(self, mock_mailgun_service):
        mock_mailgun_service.return_value = (False, None)
        with self.assertRaises(ValidationError) as context:
            mailgun_email_validator('*****@*****.**')

        expected_message = 'The email address you entered does not ' \
                           'appear to exist.'
        self.assertEqual(expected_message, str(context.exception.message))
示例#5
0
    def test_updates_error_message_if_mailgun_returns_suggestion(
            self, mock_mailgun_service):
        mock_mailgun_service.return_value = (False, "*****@*****.**")
        with self.assertRaises(ValidationError) as context:
            mailgun_email_validator('*****@*****.**')

        expected_message = 'The email address you entered does not ' \
                           'appear to exist. Did you mean [email protected]?'
        self.assertEqual(expected_message, str(context.exception.message))
示例#6
0
 def test_notifies_admin_if_mailgun_api_error(self, mock_email_admins,
                                              mock_mailgun_service):
     mock_mailgun_service.side_effect = MailgunAPIError(
         "Mailgun responded with 404")
     with self.assertLogs('project.services.logging_service',
                          logging.ERROR) as logs:
         mailgun_email_validator('*****@*****.**')
     assertInLogs(logs, 'mailgun_api_error')
     self.assertEqual(1, len(mock_email_admins.mock_calls))
示例#7
0
 def test_notifies_admin_if_mailgun_api_error(
             self, mock_email_admins, mock_mailgun_service):
     mock_mailgun_service.side_effect = MailgunAPIError(
         "Mailgun responded with 404")
     with self.assertLogs(
             'project.services.logging_service', logging.ERROR) as logs:
         mailgun_email_validator('*****@*****.**')
     assertInLogs(logs, 'mailgun_api_error')
     self.assertEqual(1, len(mock_email_admins.mock_calls))
示例#8
0
    def test_updates_error_message_if_mailgun_returns_suggestion(
            self, mock_mailgun_service):
        mock_mailgun_service.return_value = (False, "*****@*****.**")
        with self.assertRaises(ValidationError) as context:
            mailgun_email_validator('*****@*****.**')

        expected_message = 'The email address you entered does not ' \
                           'appear to exist. Did you mean [email protected]?'
        self.assertEqual(expected_message, str(context.exception.message))
示例#9
0
 def test_valid_if_mailgun_returns_valid(self, mock_mailgun_service):
     mock_mailgun_service.return_value = (True, None)
     try:
         mailgun_email_validator('*****@*****.**')
     except ValidationError as err:
         raise AssertionError('unexpectedly raised {}'.format(err))
示例#10
0
 def test_valid_if_mailgun_returns_valid(self, mock_mailgun_service):
     mock_mailgun_service.return_value = (True, None)
     try:
         mailgun_email_validator('*****@*****.**')
     except ValidationError as err:
         raise AssertionError('unexpectedly raised {}'.format(err))