def test_nested_subgroup_loop(self): repo = Repository() repo.add_group(Group("group1", {'subgroups': ["group2"]})) repo.add_group(Group("group2", {'subgroups': ["group1"]})) group = repo.get_group("group1") with self.assertRaises(RepositoryError): list(group.subgroups)
def test_apply(self, apply_items, NodeLock, ApplyResult): repo = Repository() n = Node("node1", {}) repo.add_node(n) result = MagicMock() ApplyResult.return_value = result NodeLock.__enter__ = lambda x: x NodeLock.__exit__ = lambda x: x self.assertEqual(n.apply(), result) self.assertEqual(apply_items.call_count, 1) ApplyResult.assert_called_once()
def test_static_members(self): repo = Repository() node1 = Node("node1") node2 = Node("node2") repo.add_node(node1) repo.add_node(node2) group = Group("group1", {'members': ("node2", "node1")}) repo.add_group(group) self.assertEqual( set(group._nodes_from_static_members), set((node1, node2)), )
def test_static_subgroup_members(self, *args): repo = Repository() group1 = Group("group1", {'subgroups': ("group2",)}) node3 = Node("node3") node4 = Node("node4") repo.add_group(group1) repo.add_group(Group("group2", {'members': ("node3", "node4")})) repo.add_node(node3) repo.add_node(node4) repo.add_node(Node("node5")) self.assertEqual( set(group1._nodes_from_subgroups), set((node3, node4)), )
def test_bundles(self): repo = Repository() repo.bundle_names = ("bundle1", "bundle2", "bundle3") n = Node("node1", {}) repo.add_node(n) g1 = Group("group1", {"bundles": ("bundle1", "bundle2")}) repo.add_group(g1) g2 = Group("group2", {"bundles": ("bundle3",)}) repo.add_group(g2) with patch("tests.unit.node_tests.Node.groups", new=(g1, g2)): self.assertEqual(tuple(names(n.bundles)), ("bundle1", "bundle2", "bundle3"))
def test_repo_create(self, *args): bundles = ("bundle1", "bundle2") r = Repository.create(self.tmpdir) for bundle in bundles: mkdir(join(r.bundles_dir, bundle)) r.populate_from_path(self.tmpdir) self.assertEqual( set(r.bundle_names), set(bundles), )
def test_simple_subgroups(self): repo = Repository() repo.add_group(Group("group1", {'subgroups': ["group2", "group3"]})) repo.add_group(Group("group2")) repo.add_group(Group("group3")) group = repo.get_group("group1") self.assertEqual(list(names(group.subgroups)), ["group2", "group3"])
def test_nested_subgroups(self): repo = Repository() repo.add_group(Group("group1", {'subgroups': ["group2"]})) repo.add_group(Group("group2", {'subgroups': ["group3"]})) repo.add_group(Group("group3", {'subgroups': []})) group = repo.get_group("group1") self.assertEqual( set(names(group.subgroups)), set(["group2", "group3"]), )
def test_with_custom(self): r = Repository.create(self.tmpdir) with open(join(r.items_dir, "good1.py"), 'w') as f: f.write("from blockwart.items import Item\n" "class GoodTestItem(Item): bad = False\n") with open(join(r.items_dir, "_bad1.py"), 'w') as f: f.write("from blockwart.items import Item\n" "class BadTestItem(Item): bad = True\n") with open(join(r.items_dir, "bad2.py"), 'w') as f: f.write("from blockwart.items import Item\n" "class _BadTestItem(Item): bad = True\n") r.populate_from_path(self.tmpdir) self.assertGreater(len(r.item_classes), 0) for cls in r.item_classes: if hasattr(cls, 'bad'): self.assertFalse(cls.bad) self.assertTrue(issubclass(cls, Item))
def test_pattern_members(self, *args): repo = Repository() repo.add_node(Node("node1")) repo.add_node(Node("node2")) group = Group("all", { 'member_patterns': (r".*",) }) repo.add_group(group) self.assertEqual( list(names(group.nodes)), ["node1", "node2"], ) group2 = Group("group2", { 'member_patterns': (r".*2",)} ) repo.add_group(group2) self.assertEqual( list(names(group2.nodes)), ["node2"], )
def test_no_subgroups(self): repo = Repository() repo.add_group(Group("group1", {'subgroups': []})) group = repo.get_group("group1") self.assertEqual(list(names(group.subgroups)), [])