summaryrefslogtreecommitdiffstats
path: root/test/unittest
diff options
context:
space:
mode:
authormakkalot <makkalot@gmail.com>2008-07-29 14:33:10 +0300
committermakkalot <makkalot@gmail.com>2008-07-29 14:33:10 +0300
commit4bed3349bb2abd490ca56a4945d7b7fc499bef88 (patch)
tree9672cf9138b9667957d9e29d07ffc5a0c15c1327 /test/unittest
parent35d210ba3da04387c799dbf4f407c53e096eb783 (diff)
downloadfunc-4bed3349bb2abd490ca56a4945d7b7fc499bef88.tar.gz
func-4bed3349bb2abd490ca56a4945d7b7fc499bef88.tar.xz
func-4bed3349bb2abd490ca56a4945d7b7fc499bef88.zip
some beautiful tests for group code :)
Diffstat (limited to 'test/unittest')
-rw-r--r--test/unittest/test_groups.py223
1 files changed, 188 insertions, 35 deletions
diff --git a/test/unittest/test_groups.py b/test/unittest/test_groups.py
index 95dd795..56e7c2a 100644
--- a/test/unittest/test_groups.py
+++ b/test/unittest/test_groups.py
@@ -16,59 +16,212 @@ class GroupFileBuilder(object):
os.unlink(self.filename)
self.cp = ConfigParser.SafeConfigParser()
- def create(self, dict):
+ def create(self, group_dict):
# dict is a dict of section names, whose values
# are a list of tuples of key=value
- # aka foo = {'section1':[(key1, value1), (key2, value2)],
- # "section2":[(key3, value3)]}
- for section in dict.keys():
+ #the dict should be : {'groupname':{'option':(values),'option2':(values)}}
+ for section,section_value in group_dict.iteritems():
self.cp.add_section(section)
- for (option, value) in dict[section]:
- self.cp.set(section, option, value)
-
- fo = open(self.filename, "a+")
+ for host_option,hosts in section_value.iteritems():
+ self.cp.set(section,host_option,",".join(hosts))
+
+ #save the changes
+ fo = open(self.filename, "w")
self.cp.write(fo)
-class GroupsBase(object):
- def __init__(self):
- self.minions = fc.Minions("*", groups_file=GROUP_TEST)
+class TestGroupsBase(object):
+ def setUp(self):
+ self.minions = fc.Minions("*", groups_file=GROUP_TEST)
+ import os
+
+ #we want a fresh copy :)
+ if os.path.exists(GROUP_TEST):
+ os.remove(GROUP_TEST)
- def test_expand_servers(self):
- result = self.minions.get_urls()
- print result
+ self.gfb = GroupFileBuilder()
+ self.the_groups_dict = {
+ "home_group":{'host':['first','second','third']},
+ }
+
+ self.test_dict = {
+ "home_group":['first','second','third']
+ }
+
+
+ #create the file
+ self.gfb.create(self.the_groups_dict)
+
+
+ #def test_expand_servers(self):
+ # result = self.minions.get_urls()
+ # print result
def test_get_groups(self):
+ #will reset on every test
+ self.setUp()
result = self.minions.group_class.get_groups()
- print result
+ assert self.test_dict == result
-class Groups(GroupsBase):
- def get_hosts_by_group_goo(self, group_goo):
- group_dict = fc.get_groups()
- hosts = fc.get_hosts_by_groupgoo(group_dict, group_goo)
- print hosts
+ def test_add_hosts_to_group(self):
+ self.setUp()
+ self.minions.group_class.add_hosts_to_group("home_group","fourth,sixth")
+ result = self.minions.group_class.get_groups()
+ self.test_dict["home_group"].append("fourth")
+ self.test_dict["home_group"].append("sixth")
+
+ #print "The result we got is : ",result
+ #print "The current into memory is : ",self.test_dict
+ assert self.test_dict == result
+
+ self.minions.group_class.add_hosts_to_group("home_group","wormy;troll")
+ self.test_dict["home_group"].append("wormy")
+ self.test_dict["home_group"].append("troll")
+ assert self.test_dict == result
+
-class TestGroups(Groups):
- def __init__(self):
- self.minions = fc.Minions("@blippy", groups_file=GROUP_TEST)
+ def test_add_host_to_group(self):
+ self.setUp()
+
+ self.minions.group_class.add_host_to_group("home_group","bloop")
+ result = self.minions.group_class.get_groups()
+ self.test_dict["home_group"].append("bloop")
+ assert self.test_dict == result
+
- def setUp(self):
- self.gfb = GroupFileBuilder()
- self.gfb.create({'blippy':[('host', 'localhost')]})
+ def test_save_changes(self):
+ self.setUp()
+ self.minions.group_class.add_host_to_group("home_group","bloop")
+ self.minions.group_class.save_changes()
+ result = self.minions.group_class.get_groups()
+
+ assert result == self.util_save_change()
+
+ def test_remove_group(self):
+ self.setUp()
+ self.minions.group_class.add_group("lab_group")
+ self.minions.group_class.add_host_to_group("lab_group","bloop")
+ result = self.minions.group_class.get_groups()
+ self.test_dict["lab_group"]=[]
+ self.test_dict["lab_group"].append("bloop")
+
+ assert self.test_dict == result
+
+ self.minions.group_class.remove_group("lab_group")
+ result = self.minions.group_class.get_groups()
+ del self.test_dict["lab_group"]
+ assert self.test_dict == result
+
+ #what if activated the save changes
+ self.minions.group_class.add_group("lab_group")
+ self.minions.group_class.add_host_to_group("lab_group","bloop")
+ self.minions.group_class.save_changes()
+ self.minions.group_class.remove_group("lab_group",save = True)
+ result = self.minions.group_class.get_groups()
+ assert result == self.util_save_change()
+
- def test_get_host_by_group_goo(self):
- results = self.minions.get_urls()
- print results
+ def test_remove_host(self):
+ self.setUp()
+ self.minions.group_class.remove_host("home_group","first")
+ self.test_dict["home_group"].remove("first")
+ result = self.minions.group_class.get_groups()
+ assert self.test_dict == result
+
+ #if activated the save changes ON
+ self.minions.group_class.remove_host("home_group","second",save = True)
+ result = self.minions.group_class.get_groups()
+ #print "The result we got is : ",result
+ #print "The data from file is :i ",self.util_save_change()
+ assert result == self.util_save_change()
+
+ def test_add_group(self):
+ self.setUp()
+ self.minions.group_class.add_group("lab_group")
+ self.test_dict["lab_group"]=[]
+ result = self.minions.group_class.get_groups()
+
+ #print "The result after adding the group is : ",result
+ #print "The current test dict is : ",self.test_dict
+ #if you have chosen to save the changes ?
+ assert self.test_dict == result
+
+ self.minions.group_class.add_group("data_group",save = True)
+ self.test_dict["data_group"]=[]
+ result = self.minions.group_class.get_groups()
+ #print "The result we got is : ",result
+ #print "The data from file is :i ",self.util_save_change()
+ assert result == self.util_save_change()
+
+ def util_save_change(self):
+ """
+ Will create a tmp object of groups to pull
+ current changes from conf file
+
+ """
+ tmp_minions = fc.Minions("*", groups_file=GROUP_TEST)
+ result = tmp_minions.group_class.get_groups()
+ del tmp_minions
+ #result tobe tested
+ return result
+
+ def test_get_hosts_by_group_glob(self):
+
+ self.setUp()
+ spec = "@home_group;some*.com"
+ tmp_minions = fc.Minions(spec, groups_file=GROUP_TEST)
+ result = tmp_minions.group_class.get_hosts_by_group_glob(spec)
+ #print "test_get_hosts_by_group_glob result is : ",result
+ assert result == self.test_dict["home_group"]
+
+
+class TestMinionGroups(object):
+ """
+ Test the minion methods that wraps the group classes
+ """
+ def setUp(self):
+ from certmaster.certmaster import CertMaster
+ cm = CertMaster()
+
+ #firstly create a group of some real ones
+ self.signed_certs = cm.get_signed_certs()
-# FIXME: comment this out till I setup a way to test with a speciic
-# test config -akl
+ #we want a fresh copy :)
+ if os.path.exists(GROUP_TEST):
+ os.remove(GROUP_TEST)
-# def test_get_hosts_by_groupgoo(self):
-# group_dict = fc.get_groups()
-# hosts = fc.get_hosts_by_groupgoo(group_dict, "@blippy")
-# print hosts
+ self.gfb = GroupFileBuilder()
+ self.the_groups_dict = {
+ "home_group":{'host':self.signed_certs},
+ }
+
+ self.test_dict = {
+ "home_group":self.signed_certs
+ }
+
+
+ #create the file
+ self.gfb.create(self.the_groups_dict)
+
+
+ #print "The signet certs are : ",cm.get_signed_certs()
+ #self.spec = "@home_group;some*.com"
+ self.spec = "*"
+ self.test_minions = fc.Minions(self.spec, groups_file=GROUP_TEST)
+
+
+ def test_get_urls(self):
+ the_urls = self.test_minions.get_urls()
+ print the_urls
+
+ def test_get_all_hosts(self):
+ self.setUp()
+ result = self.test_minions.get_all_hosts()
+ #print "The result is : ",result
+ #print "The home group is : ",self.test_dict["home_group"]
+ assert result == self.test_dict["home_group"]