def test_reorder_parents(self):
     parent1, parent2 = Group(name='par1'), Group(name='par2')
     a = Group('a')
     a.add_parent(parent1)
     a.add_parent(parent2)
     a.reorder_parents(1, 0)
     assert a.parents[0].name == 'par2'
     assert a.parents[1].name == 'par1'
 def test_delete_reparent_hosts(self):
     g1, g2 = Group(name='todelete'), Group(name='parent')
     host1 = Host(name='host')
     host1.add_group(g1)
     g1.add_parent(g2)
     g1.delete(reparent_hosts=True)
     assert g2 in host1.groups
     assert g1 not in host1.groups
 def test_remove_self_as_parent(self):
     """
     Removing yourself as parent should
     not throw any exception.
     """
     groupa, groupb = Group('groupa'), Group('groupb')
     groupa.add_parent(groupb)
     groupb.del_parent(groupb)
 def test_delete_reparent_vars(self):
     child1, child2 = Group(name='child1'), Group(name='child2')
     mid = Group(name='mid')
     mid.vars['groupvarname'] = 'value'
     parent1, parent2 = Group(name='par'), Group(name='par2')
     for child in [child1, child2]:
         child.add_parent(mid)
     for par in [parent1, parent2]:
         mid.add_parent(par)
     mid.delete(reparent_vars=True)
     for parent in [parent1, parent2]:
         assert parent.vars['groupvarname'] == 'value'
 def test_delete_reparent_groups(self):
     child1, child2 = Group(name='child1'), Group(name='child2')
     mid = Group(name='mid')
     parent1, parent2 = Group(name='par'), Group(name='par2')
     for child in [child1, child2]:
         child.add_parent(mid)
     for par in [parent1, parent2]:
         mid.add_parent(par)
     mid.delete(reparent_groups=True)
     for child in [child1, child2]:
         assert parent1 in child.parents
         assert parent2 in child.parents
         assert mid not in child.parents
 def test_replace_parent_to_self(self):
     """ You tricky basterd. Should fail """
     groupa, groupb = Group('groupa'), Group('groupb')
     groupa.add_parent(groupb)
     with pytest.raises(Exception):
         groupa.replace_parent(groupb, groupa)
 def test_add_invild_parent(self):
     groupa = Group('groupa')
     with pytest.raises(TypeError):
         groupa.add_parent("babar")
 def test_add_self_as_parent(self):
     """ You should not create direct loops.
         That's not good """
     groupa = Group('groupa')
     with pytest.raises(Exception):
         groupa.add_parent(groupa)