From 52c20c402b4095209587c3942193527daf15f7c2 Mon Sep 17 00:00:00 2001 From: Sharat Sharma Date: Fri, 9 Dec 2016 17:42:14 +0530 Subject: [PATCH] Added test cases for a few possible scenarios There are a few possible scenarios for which the test cases are missing. Adding test-cases to cover those possible scenarios. Change-Id: I892fab69e640de7b3dd68b338dc7fa3fdf40a997 --- mistral/tests/unit/api/v2/test_tasks.py | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/mistral/tests/unit/api/v2/test_tasks.py b/mistral/tests/unit/api/v2/test_tasks.py index f7f816703..b062f4988 100644 --- a/mistral/tests/unit/api/v2/test_tasks.py +++ b/mistral/tests/unit/api/v2/test_tasks.py @@ -266,6 +266,20 @@ class TestTasksController(base.APITest): self.assertIn('faultstring', resp.json) self.assertIn('execution must be in ERROR', resp.json['faultstring']) + @mock.patch.object(db_api, 'get_workflow_execution', MOCK_WF_EX) + @mock.patch.object(db_api, 'get_task_execution', MOCK_ERROR_TASK) + def test_put_current_task_in_error(self): + params = copy.deepcopy(RERUN_TASK) + params['reset'] = True + params['env'] = '{"k1": "def"}' + + resp = self.app.put_json( + '/v2/tasks/123', + params=params, + ) + + self.assertEqual(200, resp.status_int) + @mock.patch.object(db_api, 'get_workflow_execution', MOCK_WF_EX) @mock.patch.object(db_api, 'get_task_execution', MOCK_ERROR_TASK) def test_put_invalid_state(self): @@ -299,6 +313,20 @@ class TestTasksController(base.APITest): self.assertIn('faultstring', resp.json) self.assertIn('Only with-items task', resp.json['faultstring']) + @mock.patch.object(db_api, 'get_workflow_execution', MOCK_WF_EX) + @mock.patch.object(db_api, 'get_task_execution', MOCK_ERROR_TASK) + def test_put_valid_state(self): + params = copy.deepcopy(RERUN_TASK) + params['state'] = states.RUNNING + params['reset'] = True + + resp = self.app.put_json( + '/v2/tasks/123', + params=params + ) + + self.assertEqual(200, resp.status_int) + @mock.patch.object(db_api, 'get_workflow_execution', MOCK_WF_EX) @mock.patch.object(db_api, 'get_task_execution', MOCK_ERROR_TASK) def test_put_mismatch_task_name(self): @@ -316,6 +344,21 @@ class TestTasksController(base.APITest): self.assertIn('faultstring', resp.json) self.assertIn('Task name does not match', resp.json['faultstring']) + @mock.patch.object(db_api, 'get_workflow_execution', MOCK_WF_EX) + @mock.patch.object(db_api, 'get_task_execution', MOCK_ERROR_TASK) + def test_put_match_task_name(self): + params = copy.deepcopy(RERUN_TASK) + params['name'] = 'task' + params['reset'] = True + + resp = self.app.put_json( + '/v2/tasks/123', + params=params, + expect_errors=True + ) + + self.assertEqual(200, resp.status_int) + @mock.patch.object(db_api, 'get_workflow_execution', MOCK_WF_EX) @mock.patch.object(db_api, 'get_task_execution', MOCK_ERROR_TASK) def test_put_mismatch_workflow_name(self):