Example #1
0
 def test_error_on_missing_keys(self):
     """ValueError raised reporting any missing required ntp:config keys"""
     cfg = {}
     match = (r'Invalid ntp configuration:\\nMissing required ntp:config'
              ' keys: check_exe, confpath, packages, service_name')
     with self.assertRaisesRegex(ValueError, match):
         cc_ntp.supplemental_schema_validation(cfg)
 def test_error_on_non_list_values(self):
     """ValueError raised when packages is not of type list."""
     cfg = {'confpath': 'someconf', 'check_exe': '', 'service_name': '',
            'template': 'asdf', 'template_name': None, 'packages': 'NOPE'}
     match = (r'Invalid ntp configuration:\\nExpected a list of required'
              ' package names for ntp:config:packages. Found \\(NOPE\\)')
     with self.assertRaisesRegex(ValueError, match):
         cc_ntp.supplemental_schema_validation(cfg)
 def test_error_requiring_either_template_or_template_name(self):
     """ValueError raised if both template not template_name are None."""
     cfg = {'confpath': 'someconf', 'check_exe': '', 'service_name': '',
            'template': None, 'template_name': None, 'packages': []}
     match = (r'Invalid ntp configuration:\\nEither ntp:config:template'
              ' or ntp:config:template_name values are required')
     with self.assertRaisesRegex(ValueError, match):
         cc_ntp.supplemental_schema_validation(cfg)
Example #4
0
 def test_error_on_non_list_values(self):
     """ValueError raised when packages is not of type list."""
     cfg = {
         "confpath": "someconf",
         "check_exe": "",
         "service_name": "",
         "template": "asdf",
         "template_name": None,
         "packages": "NOPE",
     }
     match = (r"Invalid ntp configuration:\\nExpected a list of required"
              " package names for ntp:config:packages. Found \\(NOPE\\)")
     with self.assertRaisesRegex(ValueError, match):
         cc_ntp.supplemental_schema_validation(cfg)
Example #5
0
 def test_error_requiring_either_template_or_template_name(self):
     """ValueError raised if both template not template_name are None."""
     cfg = {
         "confpath": "someconf",
         "check_exe": "",
         "service_name": "",
         "template": None,
         "template_name": None,
         "packages": [],
     }
     match = (r"Invalid ntp configuration:\\nEither ntp:config:template"
              " or ntp:config:template_name values are required")
     with self.assertRaisesRegex(ValueError, match):
         cc_ntp.supplemental_schema_validation(cfg)
 def test_error_on_non_string_values(self):
     """ValueError raised for any values expected as string type."""
     cfg = {'confpath': 1, 'check_exe': 2, 'service_name': 3,
            'template': 4, 'template_name': 5, 'packages': []}
     errors = [
         'Expected a config file path ntp:config:confpath. Found (1)',
         'Expected a string type for ntp:config:check_exe. Found (2)',
         'Expected a string type for ntp:config:service_name. Found (3)',
         'Expected a string type for ntp:config:template. Found (4)',
         'Expected a string type for ntp:config:template_name. Found (5)']
     with self.assertRaises(ValueError) as context_mgr:
         cc_ntp.supplemental_schema_validation(cfg)
     error_msg = str(context_mgr.exception)
     for error in errors:
         self.assertIn(error, error_msg)
Example #7
0
 def test_error_on_non_string_values(self):
     """ValueError raised for any values expected as string type."""
     cfg = {
         "confpath": 1,
         "check_exe": 2,
         "service_name": 3,
         "template": 4,
         "template_name": 5,
         "packages": [],
     }
     errors = [
         "Expected a config file path ntp:config:confpath. Found (1)",
         "Expected a string type for ntp:config:check_exe. Found (2)",
         "Expected a string type for ntp:config:service_name. Found (3)",
         "Expected a string type for ntp:config:template. Found (4)",
         "Expected a string type for ntp:config:template_name. Found (5)",
     ]
     with self.assertRaises(ValueError) as context_mgr:
         cc_ntp.supplemental_schema_validation(cfg)
     error_msg = str(context_mgr.exception)
     for error in errors:
         self.assertIn(error, error_msg)