def test_getDefaults_defaultInYamls_findsIt(self): path = os.getcwd() + "/test/artifacts/roles/role1" sut = Role("role1", path, None) defs = filter(lambda x: x.get_variable_name() == 'test_var_4', sut.get_defaults()) self.assertTrue(len(defs) == 1) self.assertTrue(defs[0].get_default_value() == 'value4')
def test_getReferences_twoProjectFiles_mergesThem(self): p1 = ProjectFile(None, None) p1.add_reference('A') p1.add_reference('B') p2 = ProjectFile(None, None) p2.add_reference('A') p2.add_reference('C') sut = Role("", None, None) sut.add_file(p1) sut.add_file(p2) names = set(map(lambda x: x.get_variable_name(), sut.get_references())) self.assertEquals(set(['A', 'B', 'C']), names)
def find_roles(self, path, config): path = os.path.join(path, 'roles') for f in os.listdir(path): file_name, file_extension = os.path.splitext(f) full_path = os.path.join(path, f) if os.path.isdir(full_path): b = basename(file_name) self.roles[b] = Role(b, full_path, config)
def test_getDefaults_twoProjectFiles_mergesThem(self): p1 = ProjectFile(None, None) p1.add_default('A', '1') p1.add_default('B', '2') p2 = ProjectFile(None, None) p2.add_default('A', '3') p2.add_default('C', '4') sut = Role("", None, None) sut.add_file(p1) sut.add_file(p2) r1 = VariableDefault('A', '1', None) r2 = VariableDefault('B', '2', None) r3 = VariableDefault('A', '3', None) r4 = VariableDefault('C', '4', None) self.assertEquals(set([r1, r2, r3, r4]), sut.get_defaults())
def get_role(self, role_name): role = self.roles[role_name] if role is None: role = Role(role_name) self.roles[role_name] = role return role
def test_getRoleName_constructedWithName_returnsIt(self): name = "123abc" sut = Role(name, None, None) self.assertEqual(name, sut.get_role_name())
def test_getReferences_referenceInYaml_findsIt(self): path = os.getcwd() + "/test/artifacts/roles/role1" sut = Role("role1", path, None) self.assertTrue('test_var_2' in map(lambda x: x.get_variable_name(), sut.get_references()))