mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fixing up v2 unit tests
This commit is contained in:
parent
361eb29146
commit
1ca8cb8553
4 changed files with 21 additions and 10 deletions
|
@ -66,7 +66,7 @@ class Block(Base, Become, Conditional, Taggable):
|
|||
return all_vars
|
||||
|
||||
@staticmethod
|
||||
def load(data, play, parent_block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None):
|
||||
def load(data, play=None, parent_block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None):
|
||||
b = Block(play=play, parent_block=parent_block, role=role, task_include=task_include, use_handlers=use_handlers)
|
||||
return b.load_data(data, variable_manager=variable_manager, loader=loader)
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ from ansible.compat.tests import unittest
|
|||
from ansible.compat.tests.mock import patch, MagicMock
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleParserError
|
||||
from ansible.executor.connection_info import ConnectionInformation
|
||||
from ansible.executor.play_iterator import PlayIterator
|
||||
from ansible.playbook import Playbook
|
||||
|
||||
|
@ -67,19 +68,28 @@ class TestPlayIterator(unittest.TestCase):
|
|||
inventory.get_hosts.return_value = hosts
|
||||
inventory.filter_hosts.return_value = hosts
|
||||
|
||||
itr = PlayIterator(inventory, p._entries[0])
|
||||
task = itr.get_next_task_for_host(hosts[0])
|
||||
connection_info = ConnectionInformation(play=p._entries[0])
|
||||
|
||||
itr = PlayIterator(
|
||||
inventory=inventory,
|
||||
play=p._entries[0],
|
||||
connection_info=connection_info,
|
||||
all_vars=dict(),
|
||||
)
|
||||
|
||||
(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
print(task)
|
||||
self.assertIsNotNone(task)
|
||||
task = itr.get_next_task_for_host(hosts[0])
|
||||
(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
print(task)
|
||||
self.assertIsNotNone(task)
|
||||
task = itr.get_next_task_for_host(hosts[0])
|
||||
(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
print(task)
|
||||
self.assertIsNotNone(task)
|
||||
task = itr.get_next_task_for_host(hosts[0])
|
||||
(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
print(task)
|
||||
self.assertIsNotNone(task)
|
||||
task = itr.get_next_task_for_host(hosts[0])
|
||||
(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
print(task)
|
||||
self.assertIsNone(task)
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@ from ansible.compat.tests import unittest
|
|||
from ansible.compat.tests.mock import patch, MagicMock
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleParserError
|
||||
from ansible.playbook.block import Block
|
||||
from ansible.playbook.play import Play
|
||||
from ansible.playbook.role import Role
|
||||
from ansible.playbook.task import Task
|
||||
|
||||
from units.mock.loader import DictDataLoader
|
||||
|
||||
|
@ -39,7 +39,7 @@ class TestPlay(unittest.TestCase):
|
|||
|
||||
def test_empty_play(self):
|
||||
p = Play.load(dict())
|
||||
self.assertEqual(str(p), "PLAY: <no name specified>")
|
||||
self.assertEqual(str(p), "PLAY: ")
|
||||
|
||||
def test_basic_play(self):
|
||||
p = Play.load(dict(
|
||||
|
@ -129,4 +129,4 @@ class TestPlay(unittest.TestCase):
|
|||
|
||||
tasks = p.compile()
|
||||
self.assertEqual(len(tasks), 1)
|
||||
self.assertIsInstance(tasks[0], Task)
|
||||
self.assertIsInstance(tasks[0], Block)
|
||||
|
|
|
@ -137,6 +137,7 @@ class TestVariableManager(unittest.TestCase):
|
|||
fake_loader = DictDataLoader({})
|
||||
|
||||
mock_task = MagicMock()
|
||||
mock_task._role = None
|
||||
mock_task.get_vars.return_value = dict(foo="bar")
|
||||
|
||||
v = VariableManager()
|
||||
|
|
Loading…
Reference in a new issue