Exemplo n.º 1
0
 def test_add_workflow(self):
     workflow = Workflow('wf_name', 0)
     playbook = Playbook('test', [workflow])
     playbook.add_workflow(Workflow('test2', 0))
     orderless_list_compare(
         self, [workflow.name for workflow in playbook.workflows],
         ['wf_name', 'test2'])
 def test_load_playbook(self):
     workflows = [Workflow('something'), Workflow('something2')]
     playbook = Playbook('test', workflows=workflows)
     filepath = os.path.join(test_data_path, 'test.json')
     with open(filepath, 'w') as file_out:
         file_out.write(json.dumps(playbook.read()))
     loaded = Loader.load_playbook(filepath)
     self.assertIsInstance(loaded, Playbook)
     self.assertEqual(loaded.name, 'test')
 def test_load_playbooks_some_invalid_playbooks_in_directory(self):
     workflows = [Workflow('something'), Workflow('something2')]
     playbook = Playbook('test', workflows=workflows)
     filepath = os.path.join(test_data_path, 'test.playbook')
     with open(filepath, 'w') as file_out:
         file_out.write(json.dumps(playbook.read()))
     test_invalid_json = 'something not json'
     filepath = os.path.join(test_data_path, 'test2.playbook')
     with open(filepath, 'w') as file_out:
         file_out.write(test_invalid_json)
     loaded = Loader.load_playbooks(test_data_path)
     self.assertEqual(len(loaded), 1)
     self.assertEqual(loaded[0].name, 'test')
Exemplo n.º 4
0
    def test_delete_workflow(self):
        execution_db_help.standard_load()

        workflows = [Workflow('wf{}'.format(i), uuid4()) for i in range(2)]

        for workflow in workflows:
            self.app.running_context.execution_db.session.add(workflow)

        target_playbook = Playbook('play1', workflows=workflows)
        self.app.running_context.execution_db.session.add(target_playbook)
        self.app.running_context.execution_db.session.flush()
        workflow_ids = [workflow.id for workflow in workflows]
        original_num_playbooks = len(
            self.app.running_context.execution_db.session.query(
                Playbook).all())
        self.delete_with_status_check('/api/workflows/{}'.format(
            workflow_ids[0]),
                                      headers=self.headers,
                                      status_code=NO_CONTENT)
        self.assertEqual(len(list(target_playbook.workflows)),
                         len(workflow_ids) - 1)
        self.assertNotIn(
            workflow_ids[0],
            [workflow.id for workflow in target_playbook.workflows])
        self.assertEqual(
            len(
                self.app.running_context.execution_db.session.query(
                    Playbook).all()), original_num_playbooks)
Exemplo n.º 5
0
def upgrade_playbook(playbook):
    workflows = []
    for workflow in playbook['workflows']:
        workflows.append(upgrade_workflow(workflow))

    playbook_obj = Playbook(name=playbook['name'], workflows=workflows, id=playbook.get('uid', None))

    executiondb.execution_db.session.add(playbook_obj)
    executiondb.execution_db.session.commit()
    def test_delete_last_workflow(self):
        execution_db_help.standard_load()

        workflow = Workflow('wf', uuid4())
        executiondb.execution_db.session.add(workflow)
        target_playbook = Playbook('play1', workflows=[workflow])
        executiondb.execution_db.session.add(target_playbook)
        executiondb.execution_db.session.flush()
        original_num_playbooks = len(
            executiondb.execution_db.session.query(Playbook).all())
        self.delete_with_status_check('/api/workflows/{}'.format(workflow.id),
                                      headers=self.headers,
                                      status_code=NO_CONTENT)
        self.assertIsNone(
            executiondb.execution_db.session.query(Playbook).filter_by(
                name='play1').first())
        self.assertEqual(
            len(executiondb.execution_db.session.query(Playbook).all()),
            original_num_playbooks - 1)
 def test_load_multiple_workflows(self):
     workflows = [Workflow('something'), Workflow('something2')]
     playbook = Playbook('test', workflows=workflows)
     filepath = os.path.join(test_data_path, 'test.playbook')
     with open(filepath, 'w') as file_out:
         file_out.write(json.dumps(playbook.read()))
     workflows = [Workflow('something'), Workflow('something2')]
     playbook = Playbook('test2', workflows=workflows)
     filepath = os.path.join(test_data_path, 'test2.playbook')
     with open(filepath, 'w') as file_out:
         file_out.write(json.dumps(playbook.read()))
     loaded = Loader.load_playbooks(test_data_path)
     self.assertEqual(len(loaded), 2)
     self.assertSetEqual({playbook.name for playbook in loaded}, {'test', 'test2'})
Exemplo n.º 8
0
 def test_get_all_workflow_ids_no_workflows(self):
     playbook = Playbook('test', [])
     self.assertListEqual(playbook.get_all_workflow_ids(), [])
Exemplo n.º 9
0
 def test_get_workflow_by_name_no_name(self):
     workflow = Workflow('wf_name', 0)
     playbook = Playbook('test', [workflow])
     self.assertIsNone(playbook.get_workflow_by_name('invalid'))
Exemplo n.º 10
0
 def test_get_workflow_by_id(self):
     workflow = Workflow('wf_name', 0)
     playbook = Playbook('test', [workflow])
     self.assertEqual(playbook.get_workflow_by_id(workflow.id), workflow)
Exemplo n.º 11
0
 def test_has_workflow_name_no_workflows(self):
     playbook = Playbook('test', [])
     self.assertFalse(playbook.has_workflow_name('anything'))
Exemplo n.º 12
0
 def test_has_workflow_id_no_workflows(self):
     playbook = Playbook('test', [])
     self.assertFalse(playbook.has_workflow_id(1))
Exemplo n.º 13
0
 def test_add_workflow(self):
     workflow = Workflow('wf_name', 0)
     playbook = Playbook('test', [workflow])
     playbook.add_workflow(Workflow('test2', 0))
     orderless_list_compare(self, [workflow.name for workflow in playbook.workflows], ['wf_name', 'test2'])
Exemplo n.º 14
0
 def test_init_with_workflows(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     self.assertEqual(playbook.name, 'test')
     self.assertListEqual(playbook.workflows, workflows)
Exemplo n.º 15
0
 def test_get_workflow_by_id_no_workflows(self):
     playbook = Playbook('test', [])
     self.assertIsNone(playbook.get_workflow_by_id('anything'))
Exemplo n.º 16
0
 def test_get_workflow_by_id(self):
     workflow = Workflow('wf_name', 0)
     playbook = Playbook('test', [workflow])
     self.assertEqual(playbook.get_workflow_by_id(workflow.id), workflow)
Exemplo n.º 17
0
 def test_has_workflow_id(self):
     workflow = Workflow('wf_name', 0)
     playbook = Playbook('test', [workflow])
     self.assertTrue(playbook.has_workflow_id(workflow.id))
Exemplo n.º 18
0
 def test_get_workflow_by_name_no_name(self):
     workflow = Workflow('wf_name', 0)
     playbook = Playbook('test', [workflow])
     self.assertIsNone(playbook.get_workflow_by_name('invalid'))
Exemplo n.º 19
0
 def test_has_workflow_id_no_workflows(self):
     playbook = Playbook('test', [])
     self.assertFalse(playbook.has_workflow_id(1))
Exemplo n.º 20
0
 def test_has_workflow_name_no_name(self):
     workflow = Workflow('wf_name', 0)
     playbook = Playbook('test', [workflow])
     self.assertFalse(playbook.has_workflow_name('invalid'))
Exemplo n.º 21
0
 def test_has_workflow_name_no_workflows(self):
     playbook = Playbook('test', [])
     self.assertFalse(playbook.has_workflow_name('anything'))
Exemplo n.º 22
0
 def test_rename_workflow(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     playbook.rename_workflow('2', 'new_name')
     self.assertTrue(playbook.has_workflow_name('new_name'))
     self.assertFalse(playbook.has_workflow_name('2'))
Exemplo n.º 23
0
 def test_get_all_workflow_names(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     orderless_list_compare(self, playbook.get_all_workflow_names(), ['0', '1', '2'])
Exemplo n.º 24
0
 def test_rename_workflow_no_workflows(self):
     playbook = Playbook('test', [])
     playbook.rename_workflow('anything', 'renamed')
     self.assertListEqual(playbook.workflows, [])
Exemplo n.º 25
0
 def test_get_all_workflow_ids_no_workflows(self):
     playbook = Playbook('test', [])
     self.assertListEqual(playbook.get_all_workflow_ids(), [])
Exemplo n.º 26
0
 def test_init(self):
     playbook = Playbook('test')
     self.assertEqual(playbook.name, 'test')
     self.assertListEqual(playbook.workflows, [])
Exemplo n.º 27
0
 def test_get_all_workflow_ids(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     orderless_list_compare(self, playbook.get_all_workflow_ids(),
                            list(workflow.id for workflow in workflows))
Exemplo n.º 28
0
 def test_remove_workflow_by_name_workflow_not_found(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     playbook.remove_workflow_by_name('invalid')
     self.assertEqual(len(playbook.workflows), 3)
Exemplo n.º 29
0
 def test_get_all_workflows_as_json_no_workflows(self):
     playbook = Playbook('test', [])
     self.assertListEqual(playbook.get_all_workflow_representations(), [])
Exemplo n.º 30
0
 def test_has_workflow_name_no_name(self):
     workflow = Workflow('wf_name', 0)
     playbook = Playbook('test', [workflow])
     self.assertFalse(playbook.has_workflow_name('invalid'))
Exemplo n.º 31
0
 def test_rename_workflow_no_workflows(self):
     playbook = Playbook('test', [])
     playbook.rename_workflow('anything', 'renamed')
     self.assertListEqual(playbook.workflows, [])
Exemplo n.º 32
0
 def test_has_workflow_id(self):
     workflow = Workflow('wf_name', 0)
     playbook = Playbook('test', [workflow])
     self.assertTrue(playbook.has_workflow_id(workflow.id))
 def test_load_workflow_with_workflow_not_in_playbook(self):
     playbook = Playbook('test')
     filepath = os.path.join(test_data_path, 'test.json')
     with open(filepath, 'w') as file_out:
         file_out.write(json.dumps(playbook.read()))
     self.assertIsNone(Loader.load_workflow(filepath, 'something'))
Exemplo n.º 34
0
 def test_get_workflow_by_id_no_workflows(self):
     playbook = Playbook('test', [])
     self.assertIsNone(playbook.get_workflow_by_id('anything'))
Exemplo n.º 35
0
 def test_get_all_workflows_as_json_no_workflows(self):
     playbook = Playbook('test', [])
     self.assertListEqual(playbook.get_all_workflow_representations(), [])
Exemplo n.º 36
0
 def test_get_all_workflow_names(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     orderless_list_compare(self, playbook.get_all_workflow_names(),
                            ['0', '1', '2'])
Exemplo n.º 37
0
 def test_remove_workflow_by_name_no_workflows(self):
     playbook = Playbook('test', [])
     playbook.remove_workflow_by_name('something')
     self.assertListEqual(playbook.workflows, [])
Exemplo n.º 38
0
 def test_remove_workflow_by_name_no_workflows(self):
     playbook = Playbook('test', [])
     playbook.remove_workflow_by_name('something')
     self.assertListEqual(playbook.workflows, [])
Exemplo n.º 39
0
 def test_remove_workflow_by_name_workflow_not_found(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     playbook.remove_workflow_by_name('invalid')
     self.assertEqual(len(playbook.workflows), 3)
Exemplo n.º 40
0
 def test_rename_workflow_not_found(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     playbook.rename_workflow('invalid', 'new_name')
     self.assertFalse(playbook.has_workflow_name('invalid'))
Exemplo n.º 41
0
 def test_remove_workflow_by_name(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     playbook.remove_workflow_by_name('2')
     self.assertEqual(len(playbook.workflows), 2)
     self.assertFalse(playbook.has_workflow_name('2'))
Exemplo n.º 42
0
 def test_rename_workflow_not_found(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     playbook.rename_workflow('invalid', 'new_name')
     self.assertFalse(playbook.has_workflow_name('invalid'))
Exemplo n.º 43
0
 def test_remove_workflow_by_name(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     playbook.remove_workflow_by_name('2')
     self.assertEqual(len(playbook.workflows), 2)
     self.assertFalse(playbook.has_workflow_name('2'))
Exemplo n.º 44
0
 def test_rename_workflow(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     playbook.rename_workflow('2', 'new_name')
     self.assertTrue(playbook.has_workflow_name('new_name'))
     self.assertFalse(playbook.has_workflow_name('2'))
Exemplo n.º 45
0
 def test_get_all_workflow_ids(self):
     workflows = [Workflow(str(i), 0) for i in range(3)]
     playbook = Playbook('test', workflows)
     orderless_list_compare(self, playbook.get_all_workflow_ids(), list(workflow.id for workflow in workflows))