def test_send_test_email(self): """Ensure we send a test email if test=True""" self._set_args(test=True) alerts = Alerts() with mock.patch(self.REQ_FUNC, return_value=(200, dict(response='emailSentOK'))) as req: alerts.send_test_email() self.assertTrue(req.called)
def test_send_test_email_fail_connection(self): """Ensure we fail cleanly if we hit a connection failure""" self._set_args(test=True) alerts = Alerts() with self.assertRaisesRegexp(AnsibleFailJson, r"failed to send"): with mock.patch(self.REQ_FUNC, side_effect=Exception) as req: alerts.send_test_email() self.assertTrue(req.called)
def test_send_test_email_check(self): """Ensure we handle check_mode correctly""" self._set_args(test=True) alerts = Alerts() alerts.check_mode = True with mock.patch(self.REQ_FUNC) as req: with mock.patch.object(alerts, 'update_configuration', return_value=True): alerts.send_test_email() self.assertFalse(req.called)
def test_send_test_email_fail(self): """Ensure we fail if the test returned a failure status""" self._set_args(test=True) alerts = Alerts() ret_msg = 'fail' with self.assertRaisesRegexp(AnsibleFailJson, ret_msg): with mock.patch(self.REQ_FUNC, return_value=(200, dict(response=ret_msg))) as req: alerts.send_test_email() self.assertTrue(req.called)