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
This commit is contained in:
Sharat Sharma 2016-12-09 17:42:14 +05:30
parent 317e4f333e
commit 52c20c402b

View File

@ -266,6 +266,20 @@ class TestTasksController(base.APITest):
self.assertIn('faultstring', resp.json) self.assertIn('faultstring', resp.json)
self.assertIn('execution must be in ERROR', resp.json['faultstring']) 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_workflow_execution', MOCK_WF_EX)
@mock.patch.object(db_api, 'get_task_execution', MOCK_ERROR_TASK) @mock.patch.object(db_api, 'get_task_execution', MOCK_ERROR_TASK)
def test_put_invalid_state(self): def test_put_invalid_state(self):
@ -299,6 +313,20 @@ class TestTasksController(base.APITest):
self.assertIn('faultstring', resp.json) self.assertIn('faultstring', resp.json)
self.assertIn('Only with-items task', resp.json['faultstring']) 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_workflow_execution', MOCK_WF_EX)
@mock.patch.object(db_api, 'get_task_execution', MOCK_ERROR_TASK) @mock.patch.object(db_api, 'get_task_execution', MOCK_ERROR_TASK)
def test_put_mismatch_task_name(self): def test_put_mismatch_task_name(self):
@ -316,6 +344,21 @@ class TestTasksController(base.APITest):
self.assertIn('faultstring', resp.json) self.assertIn('faultstring', resp.json)
self.assertIn('Task name does not match', resp.json['faultstring']) 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_workflow_execution', MOCK_WF_EX)
@mock.patch.object(db_api, 'get_task_execution', MOCK_ERROR_TASK) @mock.patch.object(db_api, 'get_task_execution', MOCK_ERROR_TASK)
def test_put_mismatch_workflow_name(self): def test_put_mismatch_workflow_name(self):