diff --git a/functionaltests/api/v1/test_mistral_basic.py b/functionaltests/api/v1/test_mistral_basic.py index f95cc9812..91b22fe2b 100644 --- a/functionaltests/api/v1/test_mistral_basic.py +++ b/functionaltests/api/v1/test_mistral_basic.py @@ -15,7 +15,6 @@ # under the License. import json -import testtools import uuid from tempest import exceptions @@ -203,7 +202,6 @@ class AdvancedTests(base.TestCaseAdvanced): self.assertRaises(exceptions.NotFound, self.client.update_execution, 'test123', id, put_body) - @testtools.skip('https://bugs.launchpad.net/mistral/+bug/1326287') @test.attr(type='negative') def test_get_tasks_list_of_nonexistent_execution(self): @@ -218,7 +216,6 @@ class AdvancedNegativeTestsWithExecutionCreate(base.TestCaseAdvanced): self.execution = self._create_execution('test123', 'aloha')[1] - @testtools.skip('https://bugs.launchpad.net/mistral/+bug/1326278') @test.attr(type='negative') def test_get_nonexistent_task(self): self.assertRaises(exceptions.NotFound, self.client.get_task, diff --git a/mistral/api/controllers/v1/task.py b/mistral/api/controllers/v1/task.py index 7dafce701..e1aa4de4c 100644 --- a/mistral/api/controllers/v1/task.py +++ b/mistral/api/controllers/v1/task.py @@ -114,9 +114,12 @@ class TasksController(rest.RestController): return Task.from_dict(values) + @rest_utils.wrap_wsme_controller_exception @wsme_pecan.wsexpose(Tasks, wtypes.text, wtypes.text) def get_all(self, workbook_name, execution_id): """Return all tasks within the execution.""" + db_api.ensure_execution_exists(workbook_name, execution_id) + LOG.debug("Fetch tasks [workbook_name=%s, execution_id=%s]" % (workbook_name, execution_id)) diff --git a/mistral/db/api.py b/mistral/db/api.py index 7efa91014..fa54a2060 100644 --- a/mistral/db/api.py +++ b/mistral/db/api.py @@ -98,6 +98,10 @@ def execution_get(workbook_name, id): return IMPL.execution_get(workbook_name, id) +def ensure_execution_exists(workbook_name, execution_id): + return IMPL.ensure_execution_exists(workbook_name, execution_id) + + def execution_create(workbook_name, values): return IMPL.execution_create(workbook_name, values) diff --git a/mistral/db/sqlalchemy/api.py b/mistral/db/sqlalchemy/api.py index 2af3d30ab..7255cf752 100644 --- a/mistral/db/sqlalchemy/api.py +++ b/mistral/db/sqlalchemy/api.py @@ -405,6 +405,10 @@ def execution_get(workbook_name, execution_id): return execution +def ensure_execution_exists(workbook_name, execution_id): + execution_get(workbook_name, execution_id) + + @to_dict def executions_get_all(**kwargs): return _executions_get_all(**kwargs) diff --git a/mistral/tests/api/v1/controllers/test_tasks.py b/mistral/tests/api/v1/controllers/test_tasks.py index ccee35e28..88182a750 100644 --- a/mistral/tests/api/v1/controllers/test_tasks.py +++ b/mistral/tests/api/v1/controllers/test_tasks.py @@ -85,6 +85,8 @@ class TestTasksController(base.FunctionalTest): @mock.patch.object(db_api, "tasks_get", mock.MagicMock(return_value=TASKS)) + @mock.patch.object(db_api, "ensure_execution_exists", + mock.MagicMock(return_value={'id': "abc123"})) def test_get_all(self): resp = self.app.get('/v1/workbooks/my_workbook/executions/123/tasks') @@ -92,3 +94,8 @@ class TestTasksController(base.FunctionalTest): self.assertEqual(len(resp.json), 1) self.assertDictEqual(TASKS[0], canonize(resp.json['tasks'][0])) + + @mock.patch.object(db_api, "tasks_get", + mock.MagicMock(return_value=TASKS)) + def test_get_all_nonexistent_execution(self): + self.assertNotFound('/v1/workbooks/my_workbook/executions/123/tasks')