Esempio n. 1
0
    def test_invalid_validate_plugin_config_options(self):
        """Check passing invalid validate plugin options"""
        args = [DATA]
        kwargs = {
            "criteria": "invalid criteria",
            "engine": "ansible.utils.jsonschema",
            "draft": "draft0",
        }

        with self.assertRaises(AnsibleError) as error:
            validate(*args, **kwargs)
        self.assertIn(
            "value of draft must be one of: draft3, draft4, draft6, draft7, got: draft0",
            str(error.exception),
        )
Esempio n. 2
0
 def test_valid_data(self):
     """Check passing valid data as per criteria"""
     args = [DATA]
     kwargs = {
         "criteria": CRITERIA_IN_RATE_CHECK,
         "engine": "ansible.utils.jsonschema",
     }
     result = validate(*args, **kwargs)
     self.assertEqual(result, True)
Esempio n. 3
0
 def test_invalid_data(self):
     """Check passing invalid data as per criteria"""
     args = [DATA]
     kwargs = {
         "criteria": [
             CRITERIA_ENABLED_CHECK,
             CRITERIA_OPER_STATUS_UP_CHECK,
             CRITERIA_CRC_ERROR_CHECK,
         ],
         "engine":
         "ansible.utils.jsonschema",
     }
     result = validate(*args, **kwargs)
     self.assertEqual(result, False)
Esempio n. 4
0
    def test_invalid_argspec(self):
        """Check passing invalid argspec"""

        # missing required arguments
        args = [DATA]
        kwargs = {}
        with self.assertRaises(AnsibleError) as error:
            validate(*args, **kwargs)
        msg = "missing required arguments: criteria"
        self.assertTrue(
            set(str(error.exception).split()).issuperset(set(msg.split())))

        kwargs = {
            "criteria": CRITERIA_IN_RATE_CHECK,
            "engine": "ansible.utils.sample",
        }
        with self.assertRaises(AnsibleError) as error:
            validate(*args, **kwargs)
        self.assertIn(
            "For engine 'ansible.utils.sample' error loading",
            str(error.exception),
        )

        args = ["invalid data"]
        kwargs = {
            "criteria": [CRITERIA_IN_RATE_CHECK],
            "engine": "ansible.utils.jsonschema",
        }
        with self.assertRaises(AnsibleError) as error:
            validate(*args, **kwargs)
        self.assertIn("'data' option value is invalid", str(error.exception))

        args = [DATA]
        kwargs = {
            "criteria": "invalid criteria",
            "engine": "ansible.utils.jsonschema",
        }
        with self.assertRaises(AnsibleError) as error:
            validate(*args, **kwargs)
        self.assertIn("'criteria' option value is invalid",
                      str(error.exception))