From bbe8f48a468c524da0f00fbef1cb5aaa7bfc0536 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Fri, 10 Jul 2015 02:50:33 -0400 Subject: [PATCH] Update role unit tests for changes made to require a play during loading --- test/units/playbook/test_role.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/test/units/playbook/test_role.py b/test/units/playbook/test_role.py index 031871ce32..208fe9aeda 100644 --- a/test/units/playbook/test_role.py +++ b/test/units/playbook/test_role.py @@ -46,8 +46,11 @@ class TestRole(unittest.TestCase): """, }) + mock_play = MagicMock() + mock_play.ROLE_CACHE = {} + i = RoleInclude.load('foo_tasks', loader=fake_loader) - r = Role.load(i) + r = Role.load(i, play=mock_play) self.assertEqual(str(r), 'foo_tasks') self.assertEqual(len(r._task_blocks), 1) @@ -62,8 +65,11 @@ class TestRole(unittest.TestCase): """, }) + mock_play = MagicMock() + mock_play.ROLE_CACHE = {} + i = RoleInclude.load('foo_handlers', loader=fake_loader) - r = Role.load(i) + r = Role.load(i, play=mock_play) self.assertEqual(len(r._handler_blocks), 1) assert isinstance(r._handler_blocks[0], Block) @@ -79,8 +85,11 @@ class TestRole(unittest.TestCase): """, }) + mock_play = MagicMock() + mock_play.ROLE_CACHE = {} + i = RoleInclude.load('foo_vars', loader=fake_loader) - r = Role.load(i) + r = Role.load(i, play=mock_play) self.assertEqual(r._default_vars, dict(foo='bar')) self.assertEqual(r._role_vars, dict(foo='bam')) @@ -122,8 +131,11 @@ class TestRole(unittest.TestCase): """, }) + mock_play = MagicMock() + mock_play.ROLE_CACHE = {} + i = RoleInclude.load('foo_metadata', loader=fake_loader) - r = Role.load(i) + r = Role.load(i, play=mock_play) role_deps = r.get_direct_dependencies() @@ -141,13 +153,13 @@ class TestRole(unittest.TestCase): self.assertEqual(all_deps[2].get_name(), 'bar_metadata') i = RoleInclude.load('bad1_metadata', loader=fake_loader) - self.assertRaises(AnsibleParserError, Role.load, i) + self.assertRaises(AnsibleParserError, Role.load, i, play=mock_play) i = RoleInclude.load('bad2_metadata', loader=fake_loader) - self.assertRaises(AnsibleParserError, Role.load, i) + self.assertRaises(AnsibleParserError, Role.load, i, play=mock_play) i = RoleInclude.load('recursive1_metadata', loader=fake_loader) - self.assertRaises(AnsibleError, Role.load, i) + self.assertRaises(AnsibleError, Role.load, i, play=mock_play) def test_load_role_complex(self): @@ -160,8 +172,11 @@ class TestRole(unittest.TestCase): """, }) + mock_play = MagicMock() + mock_play.ROLE_CACHE = {} + i = RoleInclude.load(dict(role='foo_complex'), loader=fake_loader) - r = Role.load(i) + r = Role.load(i, play=mock_play) self.assertEqual(r.get_name(), "foo_complex")