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))
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))
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))
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))
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))
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))