class MockPlaybookLoader(object): def __init__(self): self.playbook1 = Playbook( 'play1', workflows=[Workflow('work1'), Workflow('work2')]) self.playbook2 = Playbook( 'play2', workflows=[Workflow('work1'), Workflow('work3')]) def load_workflow(self, resource, workflow_name): if resource == 'play1' and self.playbook1.has_workflow_name( workflow_name): return resource, self.playbook1.get_workflow_by_name(workflow_name) elif resource == 'play2' and self.playbook2.has_workflow_name( workflow_name): return resource, self.playbook2.get_workflow_by_name(workflow_name) else: return None def load_playbook(self, resource): if resource == 'test1': return self.playbook1 elif resource == 'play2': return self.playbook2 else: return None def load_playbooks(self, resource_collection): return [self.playbook1, self.playbook2]
def test_get_workflow_by_name_no_name(self): workflow = MockWorkflow('uid', 'wf_name') playbook = Playbook('test', [workflow]) self.assertIsNone(playbook.get_workflow_by_name('invalid'))
def test_get_workflow_by_name(self): workflow = MockWorkflow('uid', 'wf_name') playbook = Playbook('test', [workflow]) self.assertEqual(playbook.get_workflow_by_name('wf_name'), workflow)
def test_get_workflow_by_name_no_workflows(self): playbook = Playbook('test', []) self.assertIsNone(playbook.get_workflow_by_name('anything'))