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_create(self):
        a = Host('a')
        assert a.name == 'a'
        assert a.vars == dict()

        b = Host(name='a')
        assert b.name == 'a'
        assert b.vars == dict()
 def test_remove_group_from_hosts(self):
     groupa = Group('groupa')
     hosta, hostb = Host('a'), Host('b')
     hosta.add_group(groupa)
     hostb.add_group(groupa)
     assert len(groupa.hosts) == 2
     groupa.delete()
     assert len(hosta.groups) == 0
     assert len(hostb.groups) == 0
 def test_remove_no_host_anymore(self):
     groupa = Group('groupa')
     hosta = Host('a')
     groupa.add_host(hosta)
     assert groupa.hosts[0].name == 'a'
     groupa.del_host(hosta)
     groupa.del_host(hosta)
 def test_remove_host(self):
     groupa = Group('groupa')
     hosta = Host('a')
     groupa.add_host(hosta)
     assert groupa.hosts[0].name == 'a'
     groupa.del_host(hosta)
     assert len(groupa.hosts) == 0
 def test_reorder_groups(self):
     a, b = Group('a'), Group('b')
     h1 = Host('h1')
     h1.add_group(a)
     h1.add_group(b)
     h1.reorder_groups(1, 0)
     assert h1.groups[0].name == 'b'
     assert h1.groups[1].name == 'a'
 def test_delete(self):
     hosta = Host('hosta')
     groupa = Group('groupa')
     groupb = Group('groupb')
     hosta.add_group(groupa)
     hosta.add_group(groupb)
     hosta.delete()
     assert len(groupa.hosts) == 0
     assert len(groupb.hosts) == 0
def create_objects():
    groupa, groupb = Group(name='groupa'), Group(name='groupb')
    hosta, hostb = Host('hosta'), Host('hostb')
    return (hosta, hostb, groupa, groupb)
 def test_has_host(self):
     g1, h1 = Group('g1'), Host('h1')
     g1.add_host(h1)
     assert g1.has_host(u'h1')
     assert g1.has_host('h1')
     assert not g1.has_host('u2')
 def test_add_host(self):
     groupa = Group('groupa')
     hosta = Host('a')
     groupa.add_host(hosta)
     assert groupa.hosts[0].name == 'a'
 def test_set_vars(self):
     hostvars = dict(bidule='machin')
     b = Host('b')
     b.set_vars(hostvars)
     assert b.vars['bidule'] == 'machin'
 def test_update_hostvar(self):
     hosta = Host('hosta')
     hosta.set_var('a', 'valuea')
     assert hosta.vars['a'] == 'valuea'
 def test_create_with_no_hostname(self):
     with pytest.raises(Exception):
         Host()
 def test_show_host(self):
     a = Host(name='a')
     assert a.__repr__() == "Host(name='a')"