def init_virt_config_section(self, is_pc=False): """ Method executed before each unit test. """ self.ahv_config = AhvConfigSection(MY_SECTION_NAME, None) if is_pc: self.ahv_config['prism_central'] = True # We need to set values using this way, because we need # to trigger __setitem__ of virt_config. for key, value in PE_SECTION_VALUES.items(): self.ahv_config[key] = value
def create_config(name, wrapper, **kwargs): config = AhvConfigSection(name, wrapper) config.update(**kwargs) config.validate() return config
class TestAhvConfigSection(TestBase): """ Test base for testing class AhvConfigSection. """ def __init__(self, *args, **kwargs): super(TestAhvConfigSection, self).__init__(*args, **kwargs) self.ahv_config = None def init_virt_config_section(self, is_pc=False): """ Method executed before each unit test. """ self.ahv_config = AhvConfigSection(MY_SECTION_NAME, None) if is_pc: self.ahv_config['prism_central'] = True # We need to set values using this way, because we need # to trigger __setitem__ of virt_config. for key, value in PE_SECTION_VALUES.items(): self.ahv_config[key] = value def test_validate_ahv_PE_config(self): """ Test validation of ahv section. """ # PE validation. self.init_virt_config_section() result = self.ahv_config.validate() self.assertEqual(len(result), 0) # PC validation. self.init_virt_config_section(is_pc=True) result = self.ahv_config.validate() self.assertEqual(len(result), 0) def test_validate_ahv_invalid_server_ip(self): """ Test validation of ahv config. Invalid server IP. """ self.init_virt_config_section() self.ahv_config['server'] = '10.0.0.' result = self.ahv_config.validate() expected_result = ['Invalid server IP address provided'] six.assertCountEqual(self, expected_result, result) def test_validate_ahv_config_missing_username_password(self): """ Test validation of ahv config. Username and password is required. """ self.init_virt_config_section() del self.ahv_config['username'] del self.ahv_config['password'] result = self.ahv_config.validate() expected_result = [('error', 'Required option: "username" not set.'), ('error', 'Required option: "password" not set.')] six.assertCountEqual(self, expected_result, result) def test_validate_ahv_config_invalid_internal_debug_flag(self): """ Test validation of ahv config. If update_interval and internal debug are not set then we get a warning message for each flag. """ self.init_virt_config_section() self.ahv_config['update_interval'] = 40 result = self.ahv_config.validate() message = "Interval value can't be lower than {min} seconds. " \ "Default value of {min} " \ "seconds will be used.".format(min=DefaultUpdateInterval) expected_result = [("warning", message)] six.assertCountEqual(self, expected_result, result)
class TestAhvConfigSection(TestBase): """ Test base for testing class AhvConfigSection. """ def __init__(self, *args, **kwargs): super(TestAhvConfigSection, self).__init__(*args, **kwargs) self.ahv_config = None def init_virt_config_section(self, is_pc=False): """ Method executed before each unit test. """ self.ahv_config = AhvConfigSection(MY_SECTION_NAME, None) if is_pc: self.ahv_config['prism_central'] = True # We need to set values using this way, because we need # to trigger __setitem__ of virt_config. for key, value in PE_SECTION_VALUES.items(): self.ahv_config[key] = value def test_validate_ahv_PE_config(self): """ Test validation of ahv section. """ # PE validation. self.init_virt_config_section() result = self.ahv_config.validate() self.assertEqual(len(result), 0) # PC validation. self.init_virt_config_section(is_pc=True) result = self.ahv_config.validate() self.assertEqual(len(result), 0) def test_validate_ahv_invalid_server_ip(self): """ Test validation of ahv config. Invalid server IP. """ self.init_virt_config_section() self.ahv_config['server'] = '10.0.0.' result = self.ahv_config.validate() expected_result = ['Invalid server IP address provided'] six.assertCountEqual(self, expected_result, result) def test_validate_ahv_config_missing_username_password(self): """ Test validation of ahv config. Username and password is required. """ self.init_virt_config_section() del self.ahv_config['username'] del self.ahv_config['password'] result = self.ahv_config.validate() expected_result = [ ('error', 'Required option: "username" not set.'), ('error', 'Required option: "password" not set.') ] six.assertCountEqual(self, expected_result, result) def test_validate_ahv_config_invalid_internal_debug_flag(self): """ Test validation of ahv config. If update_interval and internal debug are not set then we get a warning message for each flag. """ self.init_virt_config_section() self.ahv_config['update_interval'] = 40 result = self.ahv_config.validate() message = "Interval value can't be lower than {min} seconds. " \ "Default value of {min} " \ "seconds will be used.".format(min=DefaultUpdateInterval) expected_result = [("warning", message)] six.assertCountEqual(self, expected_result, result)