Skip to content

Commit d00aa65

Browse files
committed
Fix the last tests for ansible 2
1 parent 989d9e5 commit d00aa65

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

tests/test-include/inventory_tests.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,18 @@ class AnsibleInventoryTests(unittest.TestCase):
4848
)
4949

5050
def test_check_include_order(self):
51-
yml = self.yml_inv.get_vars("myhost1.example.com")
51+
host = self.yml_inv.list_hosts("myhost1.example.com")[0]
52+
yml = self.var_manager.get_vars(self.dataloader, host=host)
5253
self.assertEqual(yml['dvar'], 1, msg="Error, dvar include wasn't a DFS")
5354

5455
def test_check_include_twice(self):
55-
yml1 = self.yml_inv.get_vars("www1.example.com")
56-
yml2 = self.yml_inv.get_vars("www1.example.com")
56+
host = self.yml_inv.list_hosts("www1.example.com")[0]
57+
yml = self.var_manager.get_vars(self.dataloader, host=host)
58+
self.assertEqual(yml['myvar1'], 3, msg="Error, failed to include twice!")
5759

58-
self.assertEqual(yml1['myvar1'], 3, msg="Error, failed to include twice!")
59-
self.assertEqual(yml2['myvar1'], 3, msg="Error, failed to include twice!")
60+
host = self.yml_inv.list_hosts("www2.example.com")[0]
61+
yml = self.var_manager.get_vars(self.dataloader, host=host)
62+
self.assertEqual(yml['myvar1'], 3, msg="Error, failed to include twice!")
6063

6164
if __name__ == '__main__':
6265
print("\n### Execute test {}\n".format( __file__))

tests/test-plain/inventory_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def test_check_host_vars_and_groups(self):
6767

6868
def test_list_hosts(self):
6969
yml = sorted(self.yml_inv.list_hosts())
70+
yml = list(map((lambda x : repr(x).decode('utf-8')), yml))
7071
result = [u'myhost1.example.com', u'myhost2.example.com']
7172
self.assertListEqual(yml, result, msg="\nGot: {}\nExpect: {}".format(yml, result))
7273

tests/test-tags/inventory_tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ def test_check_host_with_name_syntax(self):
8888
self.assertDictEqual(yml, result, msg="\nGot: {}\nExpect: {}".format(yml, result))
8989

9090
def test_list_hosts(self):
91-
yml = sorted(self.yml_inv.list_hosts())
91+
yml = self.yml_inv.list_hosts()
92+
yml = list(map((lambda x : repr(x).decode('utf-8')), yml))
93+
yml = sorted(yml)
9294
result = [u'myhost1.example.com', u'myhost2.example.com']
9395
self.assertListEqual(yml, result, msg="\nGot: {}\nExpect: {}".format(yml, result))
9496

tests/test-tagvars/inventory_tests.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,18 @@ class AnsibleInventoryTests(unittest.TestCase):
4848
)
4949

5050
def test_check_tagvar_variable(self):
51-
yml = self.yml_inv.get_vars("myhost1.example.com")
51+
host = self.yml_inv.list_hosts("myhost1.example.com")[0]
52+
yml = self.var_manager.get_vars(self.dataloader, host=host)
5253
self.assertEqual(yml['version'], 1.8, msg="Tagvar variable not set")
5354

5455
def test_that_a_tagvars_supersedes_groupvar(self):
55-
yml = self.yml_inv.get_vars("myhost1.example.com")
56+
host = self.yml_inv.list_hosts("myhost1.example.com")[0]
57+
yml = self.var_manager.get_vars(self.dataloader, host=host)
5658
self.assertEqual(yml['env'], u'stage', msg="env failed, got {}".format(yml['env']))
5759

5860
def test_that_a_hostvars_supersedes_tagvars(self):
59-
yml = self.yml_inv.get_vars("myhost1.example.com")
61+
host = self.yml_inv.list_hosts("myhost1.example.com")[0]
62+
yml = self.var_manager.get_vars(self.dataloader, host=host)
6063
self.assertEqual(yml['app'], u'app1', msg="app failed, got {}".format(yml['app']))
6164

6265
if __name__ == '__main__':

0 commit comments

Comments
 (0)