Exemple #1
0
    def test_load_alerts(self):
        actual = run.load_alerts()
        expected = (Alert1, )
        self.assertEqual(actual, expected)

        with mock.patch("corral.conf.settings.ALERTS", new=["os.open"]):
            with self.assertRaises(exceptions.ImproperlyConfigured):
                run.load_alerts()
Exemple #2
0
    def test_load_alerts(self):
        actual = run.load_alerts()
        expected = (Alert1,)
        self.assertEqual(actual, expected)

        with mock.patch("corral.conf.settings.ALERTS", new=["os.open"]):
            with self.assertRaises(exceptions.ImproperlyConfigured):
                run.load_alerts()
Exemple #3
0
 def test_check_alerts_explicit(self, *args):
     with mock.patch("corral.run.execute_alert",
                     return_value=[]) as execute_alert:
         cli.run_from_command_line()
         expected = map(lambda s: mock.call(s, sync=True),
                        run.load_alerts())
         execute_alert.assert_has_calls(expected)
Exemple #4
0
 def test_check_alerts_explicit(self, *args):
     with mock.patch(
         "corral.run.execute_alert", return_value=[]
     ) as execute_alert:
         cli.run_from_command_line()
         expected = map(
             lambda s: mock.call(s, sync=True), run.load_alerts())
         execute_alert.assert_has_calls(expected)
Exemple #5
0
 def test_create_doc(self):
     processors = ([run.load_loader()] + list(run.load_alerts()) +
                   list(run.load_steps()))
     models = db.get_models(False)
     template_path = res.fullpath("doc.md")
     with mock.patch("codecs.open") as copen, \
             mock.patch("jinja2.Template") as template:
         docs.create_doc(processors, models, doc_formatter=None)
         copen.assert_called_with(template_path, encoding="utf8")
         with copen() as fp:
             template.assert_called_with(fp.read())
         template().render.assert_called()
Exemple #6
0
 def test_check_alerts_all_async(self, *args):
     call_count = len(run.load_alerts())
     with mock.patch("corral.run.alert.AlertRunner.start") as proc_start:
         with mock.patch("corral.run.alert.AlertRunner.join") as proc_join:
             with mock.patch("corral.run.alert.AlertRunner.exitcode", 0):
                 with mock.patch("sys.exit") as sys_exit:
                     cli.run_from_command_line()
                     self.assertEquals(proc_start.call_count, call_count)
                     self.assertEquals(proc_join.call_count, call_count)
                     sys_exit.assert_not_called()
     with mock.patch("corral.run.alert.AlertRunner.start") as proc_start:
         with mock.patch("corral.run.alert.AlertRunner.join") as proc_join:
             with mock.patch("corral.run.alert.AlertRunner.exitcode", 1):
                 with mock.patch("sys.exit") as sys_exit:
                     cli.run_from_command_line()
                     self.assertEquals(proc_start.call_count, call_count)
                     self.assertEquals(proc_join.call_count, call_count)
                     sys_exit.assert_called_once_with(call_count)
Exemple #7
0
 def test_check_alerts_all_async(self, *args):
     call_count = len(run.load_alerts())
     with mock.patch("corral.run.alert.AlertRunner.start") as proc_start:
         with mock.patch("corral.run.alert.AlertRunner.join") as proc_join:
             with mock.patch("corral.run.alert.AlertRunner.exitcode", 0):
                 with mock.patch("sys.exit") as sys_exit:
                     cli.run_from_command_line()
                     self.assertEquals(proc_start.call_count, call_count)
                     self.assertEquals(proc_join.call_count, call_count)
                     sys_exit.assert_not_called()
     with mock.patch("corral.run.alert.AlertRunner.start") as proc_start:
         with mock.patch("corral.run.alert.AlertRunner.join") as proc_join:
             with mock.patch("corral.run.alert.AlertRunner.exitcode", 1):
                 with mock.patch("sys.exit") as sys_exit:
                     cli.run_from_command_line()
                     self.assertEquals(proc_start.call_count, call_count)
                     self.assertEquals(proc_join.call_count, call_count)
                     sys_exit.assert_called_once_with(call_count)
Exemple #8
0
 def test_lsalerts_called(self, *args):
     with mock.patch("texttable.Texttable.header") as header, \
          mock.patch("texttable.Texttable.add_row") as row:
         cli.run_from_command_line()
         header.assert_called_with(('Alert Class', 'Groups'))
         self.assertEquals(row.call_count, len(run.load_alerts()))