예제 #1
0
    def test_run_pass(self):
        """Test run with passing config."""
        with open(os.devnull, "w") as fd:
            checker = PolicyChecker(self.p, "tests/checker/checker-valid.ini")

            # create additional disabled mock test
            newcheck = Mock()
            newcheck.checkname = "disabled"
            newcheck.disable = True
            newcheck.validate_config.return_value = None
            newcheck.run.return_value = []
            checker.checks.append(newcheck)

            self.assertEqual(4, len(checker.checks))
            result = checker.run(output=fd)
            self.assertEqual(0, result)
            newcheck.run.assert_not_called()
예제 #2
0
    def test_run_fail(self):
        """Test run with failing config."""
        with open(os.devnull, "w") as fd:
            checker = PolicyChecker(self.p, "tests/checker/checker-valid.ini")

            # create additional failing mock test
            newcheck = Mock()
            newcheck.checkname = "failing test"
            newcheck.disable = False
            newcheck.validate_config.return_value = None
            newcheck.run.return_value = list(range(13))
            checker.checks.append(newcheck)

            self.assertEqual(4, len(checker.checks))

            result = checker.run(output=fd)
            newcheck.run.assert_called()
            self.assertEqual(13, result)
예제 #3
0
 def test_config_check_invalid_value(self):
     """Test check invalid check type"""
     with self.assertRaises(InvalidCheckValue):
         PolicyChecker(self.p, "tests/checker/checker-invalidvalue.ini")
예제 #4
0
 def test_config_check_invalid_option(self):
     """Test check invalid check option"""
     with self.assertRaises(InvalidCheckOption):
         PolicyChecker(self.p, "tests/checker/checker-invalidoption.ini")
예제 #5
0
 def test_config_check_missing_type(self):
     """Test check missing check type"""
     with self.assertRaises(InvalidCheckerModule):
         PolicyChecker(self.p, "tests/checker/checker-missingtype.ini")
예제 #6
0
 def test_config_empty(self):
     """Test empty config file"""
     with self.assertRaises(InvalidCheckerConfig):
         PolicyChecker(self.p, "/dev/null")