def test_load_from_empty_dict(self): """ Loading empty state results in empty dictionaries. """ self.settings = Settings.load_from_dict({}) for key in Settings.KEYS: eq_({}, getattr(self.settings, key, {}))
def test_extension_paths(self): """ Test loading of templates and data from extension entry points. """ settings_ = Settings.load_from_dict( dict(environmentdefs={'any': ['host1']}, roledefs={'role1': ['host1']})) # use an empty dir as the user's templates dir to make sure # only the test templates and data are loaded with TempDir() as tmp_dir: makedirs(join(tmp_dir.path, 'templates')) makedirs(join(tmp_dir.path, 'data')) # mock entry point loading to return one entry point with the test templates mock_entry_point = Mock() mock_entry_point.load.return_value = lambda: join( dirname(__file__), 'extension') with patch('confab.iter.iter_entry_points', Mock(return_value=[mock_entry_point])): with settings(environmentdef=settings_.for_env('any')): for conffiles in iter_conffiles(tmp_dir.path): conffiles.generate(tmp_dir.path) self.assertEquals('foo', tmp_dir.read('generated/host1/foo.txt'))
def test_multiple_directories(self): """ Generate templates for roles with components where templates and data are in multiple directories. """ settings = Settings.load_from_dict( dict(environmentdefs={'any': ['host1']}, roledefs={ 'role1': ['host1'], 'role2': ['host1'] }, componentdefs={'role1': ['comp1', 'comp2']})) subdirs = ['roles', 'components'] template_dirs = map( lambda d: join(dirname(__file__), 'templates/multidir', d), subdirs) data_dirs = map(lambda d: join(dirname(__file__), 'data/multidir', d), subdirs) with TempDir() as tmp_dir: for host_and_role in settings.for_env('any').all(): conffiles = ConfFiles( host_and_role, FileSystemEnvironmentLoader(*template_dirs), DataLoader(data_dirs)) conffiles.generate(tmp_dir.path) self.assertEquals('foo', tmp_dir.read('generated/host1/foo.txt')) self.assertEquals('bar', tmp_dir.read('generated/host1/bar.txt')) self.assertEquals('baz', tmp_dir.read('generated/host1/baz.conf'))
def test_load_from_dict(self): """ Loading empty state results in empty dictionaries. """ dct = { "environmentdefs": { "environment1": ["host1", "host2"], }, "roledefs": { "role1": ["host1"], }, "componentdefs": { "role1": ["component1"], } } self.settings = Settings.load_from_dict(dct) eq_(["host1", "host2"], self.settings.environmentdefs["environment1"]) eq_(["host1"], self.settings.roledefs["role1"]) eq_(["component1"], self.settings.componentdefs["role1"])
def test_multiple_directories(self): """ Generate templates for roles with components where templates and data are in multiple directories. """ settings = Settings.load_from_dict(dict(environmentdefs={'any': ['host1']}, roledefs={'role1': ['host1'], 'role2': ['host1']}, componentdefs={'role1': ['comp1', 'comp2']})) subdirs = ['roles', 'components'] template_dirs = map(lambda d: join(dirname(__file__), 'templates/multidir', d), subdirs) data_dirs = map(lambda d: join(dirname(__file__), 'data/multidir', d), subdirs) with TempDir() as tmp_dir: for host_and_role in settings.for_env('any').all(): conffiles = ConfFiles(host_and_role, FileSystemEnvironmentLoader(*template_dirs), DataLoader(data_dirs)) conffiles.generate(tmp_dir.path) self.assertEquals('foo', tmp_dir.read('generated/host1/foo.txt')) self.assertEquals('bar', tmp_dir.read('generated/host1/bar.txt')) self.assertEquals('baz', tmp_dir.read('generated/host1/baz.conf'))
def test_extension_paths(self): """ Test loading of templates and data from extension entry points. """ settings_ = Settings.load_from_dict(dict(environmentdefs={'any': ['host1']}, roledefs={'role1': ['host1']})) # use an empty dir as the user's templates dir to make sure # only the test templates and data are loaded with TempDir() as tmp_dir: makedirs(join(tmp_dir.path, 'templates')) makedirs(join(tmp_dir.path, 'data')) # mock entry point loading to return one entry point with the test templates mock_entry_point = Mock() mock_entry_point.load.return_value = lambda: join(dirname(__file__), 'extension') with patch('confab.iter.iter_entry_points', Mock(return_value=[mock_entry_point])): with settings(environmentdef=settings_.for_env('any')): for conffiles in iter_conffiles(tmp_dir.path): conffiles.generate(tmp_dir.path) self.assertEquals('foo', tmp_dir.read('generated/host1/foo.txt'))