def test_defined_path_returns_copy_of_correct_config(self): elementName = 'copy_correct' path = '%s/%s' % (StratusLabEndpointConfiguration.ENDPOINT_PATH, elementName) value = {'a': '1'} gConfig.HOLDER.add_options(path, value) cfg = StratusLabEndpointConfiguration(elementName) self.assertEqual(cfg.config(), value) self.assertIsNot(cfg.config(), value) self.assertFalse(cfg.validate()['OK'])
def test_all_required_parameters(self): all_keys = StratusLabEndpointConfiguration.DIRAC_REQUIRED_KEYS all_keys = all_keys.union(StratusLabEndpointConfiguration.STRATUSLAB_REQUIRED_KEYS) value = {} for key in all_keys: value[key] = key elementName = 'all_req_keys' path = '%s/%s' % (StratusLabEndpointConfiguration.ENDPOINT_PATH, elementName) gConfig.HOLDER.add_options(path, value) cfg = StratusLabEndpointConfiguration(elementName) self.assertEqual(cfg.config(), value) self.assertIsNot(cfg.config(), value) self.assertTrue(cfg.validate()['OK'])
def test_missing_required_parameter(self): all_keys = StratusLabEndpointConfiguration.DIRAC_REQUIRED_KEYS all_keys = all_keys.union(StratusLabEndpointConfiguration.STRATUSLAB_REQUIRED_KEYS) complete = {} for key in all_keys: complete[key] = key for key in all_keys: missing = copy.copy(complete) del missing[key] elementName = 'missing_%s' % key path = '%s/%s' % (StratusLabEndpointConfiguration.ENDPOINT_PATH, elementName) gConfig.HOLDER.add_options(path, missing) cfg = StratusLabEndpointConfiguration(elementName) self.assertEqual(cfg.config(), missing) self.assertIsNot(cfg.config(), missing) self.assertFalse(cfg.validate()['OK'])
def test_invalid_credentials(self): all_keys = StratusLabEndpointConfiguration.DIRAC_REQUIRED_KEYS all_keys = all_keys.union(StratusLabEndpointConfiguration.STRATUSLAB_REQUIRED_KEYS) all_keys = all_keys.union(StratusLabEndpointConfiguration.STRATUSLAB_OPTIONAL_KEYS) complete = {} for key in all_keys: complete[key] = key cred_keys = 'ex_username', 'ex_password', 'ex_pem_key', 'ex_pem_certificate' for key in cred_keys: missing = copy.copy(complete) del missing[key] elementName = 'invalid_cred_%s' % key path = '%s/%s' % (StratusLabEndpointConfiguration.ENDPOINT_PATH, elementName) gConfig.HOLDER.add_options(path, missing) cfg = StratusLabEndpointConfiguration(elementName) self.assertEqual(cfg.config(), missing) self.assertIsNot(cfg.config(), missing) self.assertFalse(cfg.validate()['OK'])
def test_empty_config_from_non_existent_path(self): cfg = StratusLabEndpointConfiguration('non-existent') self.assertEqual(cfg.config(), {})