def test_email_admins(self): """ Test that the `email_admins` handler correctly sends an email. """ request = HttpRequest() report = '{"document-uri": "http://example.com/"}' formatted_report = utils.format_report(report) request._body = report # Note that we are mocking the *Django* mail_admins function here. with patch("cspreports.utils.mail_admins") as mock_mail_admins: utils.email_admins(request) self.assertTrue(mock_mail_admins.called) message = mock_mail_admins.call_args[0][1] self.assertTrue(formatted_report in message)
def test_email_admins(self): """ Test that the `email_admins` handler correctly sends an email. """ request = HttpRequest() report = '{"document-uri": "http://example.com/"}' formatted_report = utils.format_report(report) request._body = report # Note that we are mocking the *Django* mail_admins function here. with mock.patch("cspreports.utils.mail_admins") as mock_mail_admins: utils.email_admins(request) self.assertTrue(mock_mail_admins.called) message = mock_mail_admins.call_args[0][1] self.assertTrue(formatted_report in message)