Example #1
0
    def test_load_steps(self):
        actual = run.load_steps()
        expected = (Step1, Step2)
        self.assertEqual(actual, expected)

        with mock.patch("corral.conf.settings.STEPS", new=["os.open"]):
            with self.assertRaises(exceptions.ImproperlyConfigured):
                run.load_steps()
Example #2
0
    def test_load_steps(self):
        actual = run.load_steps()
        expected = (Step1, Step2)
        self.assertEqual(actual, expected)

        with mock.patch("corral.conf.settings.STEPS", new=["os.open"]):
            with self.assertRaises(exceptions.ImproperlyConfigured):
                run.load_steps()
Example #3
0
 def test_run_explicit(self, *args):
     with mock.patch(
         "corral.run.execute_step", return_value=[]
     ) as execute_step:
         cli.run_from_command_line()
         expected = map(lambda s: mock.call(s, sync=True), run.load_steps())
         execute_step.assert_has_calls(expected)
Example #4
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()
Example #5
0
 def test_run_all_async(self, *args):
     call_count = len(run.load_steps())
     with mock.patch("corral.run.step.StepRunner.start") as proc_start:
         with mock.patch("corral.run.step.StepRunner.join") as proc_join:
             with mock.patch("sys.exit") as sys_exit:
                 with mock.patch("corral.run.step.StepRunner.exitcode", 0):
                     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.step.StepRunner.start") as proc_start:
         with mock.patch("corral.run.step.StepRunner.join") as proc_join:
             with mock.patch("sys.exit") as sys_exit:
                 with mock.patch("corral.run.step.StepRunner.exitcode", 1):
                     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_with(call_count)
Example #6
0
 def test_run_all_async(self, *args):
     call_count = len(run.load_steps())
     with mock.patch("corral.run.step.StepRunner.start") as proc_start:
         with mock.patch("corral.run.step.StepRunner.join") as proc_join:
             with mock.patch("sys.exit") as sys_exit:
                 with mock.patch("corral.run.step.StepRunner.exitcode", 0):
                     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.step.StepRunner.start") as proc_start:
         with mock.patch("corral.run.step.StepRunner.join") as proc_join:
             with mock.patch("sys.exit") as sys_exit:
                 with mock.patch("corral.run.step.StepRunner.exitcode", 1):
                     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_with(call_count)
Example #7
0
 def test_run_explicit(self, *args):
     with mock.patch("corral.run.execute_step",
                     return_value=[]) as execute_step:
         cli.run_from_command_line()
         expected = map(lambda s: mock.call(s, sync=True), run.load_steps())
         execute_step.assert_has_calls(expected)
Example #8
0
 def test_lssteps_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(('Step Class', 'Groups'))
         self.assertEquals(row.call_count, len(run.load_steps()))