diff options
Diffstat (limited to 'functest/api/resources/v1/tasks.py')
-rw-r--r-- | functest/api/resources/v1/tasks.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/functest/api/resources/v1/tasks.py b/functest/api/resources/v1/tasks.py index e05db51b..f099918f 100644 --- a/functest/api/resources/v1/tasks.py +++ b/functest/api/resources/v1/tasks.py @@ -50,12 +50,15 @@ class V1Task(ApiResource): if status not in ['IN PROGRESS', 'FAIL', 'FINISHED']: return api_utils.result_handler(status=1, data='internal server error') + + switcher = {'IN PROGRESS': 0, 'FAIL': 1, 'FINISHED': 2} if status == 'IN PROGRESS': - result = {'status': status, 'result': ''} + result = {'status': switcher.get(status), 'result': ''} elif status == 'FAIL': - result = {'status': status, 'error': task.error} + result = {'status': switcher.get(status), 'error': task.error} else: - result = {'status': status, 'result': json.loads(task.result)} + result = {'status': switcher.get(status), + 'result': json.loads(task.result)} return jsonify(result) @@ -92,4 +95,7 @@ class V1TaskLog(ApiResource): return_data = {'data': data} - return api_utils.result_handler(status=task.status, data=return_data) + switcher = {'IN PROGRESS': 0, 'FAIL': 1, 'FINISHED': 2} + + return api_utils.result_handler(status=switcher.get(task.status), + data=return_data) |