diff --git a/mistral/api/controllers/resource.py b/mistral/api/controllers/resource.py index 4052a1d53..af7b16f9f 100644 --- a/mistral/api/controllers/resource.py +++ b/mistral/api/controllers/resource.py @@ -58,7 +58,7 @@ class Resource(wtypes.Base): return res + "]" - def to_string(self): + def to_json(self): return json.dumps(self.to_dict()) @classmethod diff --git a/mistral/api/controllers/v2/action.py b/mistral/api/controllers/v2/action.py index 4e4d87196..29bd6551c 100644 --- a/mistral/api/controllers/v2/action.py +++ b/mistral/api/controllers/v2/action.py @@ -135,7 +135,7 @@ class ActionsController(rest.RestController, hooks.HookController): action_list = [Action.from_dict(act) for act in models_dicts] - return Actions(actions=action_list).to_string() + return Actions(actions=action_list).to_json() @rest_utils.wrap_pecan_controller_exception @pecan.expose(content_type="text/plain") @@ -163,7 +163,7 @@ class ActionsController(rest.RestController, hooks.HookController): action_list = [Action.from_dict(act) for act in models_dicts] - return Actions(actions=action_list).to_string() + return Actions(actions=action_list).to_json() @rest_utils.wrap_wsme_controller_exception @wsme_pecan.wsexpose(None, wtypes.text, status_code=204) diff --git a/mistral/api/controllers/v2/workbook.py b/mistral/api/controllers/v2/workbook.py index 961b2a899..08123d9bd 100644 --- a/mistral/api/controllers/v2/workbook.py +++ b/mistral/api/controllers/v2/workbook.py @@ -99,7 +99,7 @@ class WorkbooksController(rest.RestController, hooks.HookController): wb_db = workbooks.update_workbook_v2(definition) - return Workbook.from_dict(wb_db.to_dict()).to_string() + return Workbook.from_dict(wb_db.to_dict()).to_json() @rest_utils.wrap_pecan_controller_exception @pecan.expose(content_type="text/plain") @@ -112,7 +112,7 @@ class WorkbooksController(rest.RestController, hooks.HookController): wb_db = workbooks.create_workbook_v2(definition) pecan.response.status = 201 - return Workbook.from_dict(wb_db.to_dict()).to_string() + return Workbook.from_dict(wb_db.to_dict()).to_json() @rest_utils.wrap_wsme_controller_exception @wsme_pecan.wsexpose(None, wtypes.text, status_code=204) diff --git a/mistral/api/controllers/v2/workflow.py b/mistral/api/controllers/v2/workflow.py index c80d671c9..bfcc65fb1 100644 --- a/mistral/api/controllers/v2/workflow.py +++ b/mistral/api/controllers/v2/workflow.py @@ -193,8 +193,8 @@ class WorkflowsController(rest.RestController, hooks.HookController): models_dicts = [db_wf.to_dict() for db_wf in db_wfs] workflow_list = [Workflow.from_dict(wf) for wf in models_dicts] - return (workflow_list[0].to_string() if identifier - else Workflows(workflows=workflow_list).to_string()) + return (workflow_list[0].to_json() if identifier + else Workflows(workflows=workflow_list).to_json()) @rest_utils.wrap_pecan_controller_exception @pecan.expose(content_type="text/plain") @@ -222,7 +222,7 @@ class WorkflowsController(rest.RestController, hooks.HookController): workflow_list = [Workflow.from_dict(wf) for wf in models_dicts] - return Workflows(workflows=workflow_list).to_string() + return Workflows(workflows=workflow_list).to_json() @rest_utils.wrap_wsme_controller_exception @wsme_pecan.wsexpose(None, wtypes.text, status_code=204) diff --git a/mistral/tests/unit/api/v2/test_environment.py b/mistral/tests/unit/api/v2/test_environment.py index 92b823fc5..28d7d7cb9 100644 --- a/mistral/tests/unit/api/v2/test_environment.py +++ b/mistral/tests/unit/api/v2/test_environment.py @@ -121,7 +121,7 @@ def _convert_vars_to_dict(env_dict): return env_dict -def _convert_vars_to_string(env_dict): +def _convert_vars_to_json(env_dict): """Converts 'variables' in the given environment dict into string.""" if ('variables' in env_dict and isinstance(env_dict.get('variables'), dict)): @@ -179,7 +179,7 @@ class TestEnvironmentController(base.APITest): def test_post(self): resp = self.app.post_json( '/v2/environments', - _convert_vars_to_string(copy.deepcopy(ENVIRONMENT_FOR_CREATE)) + _convert_vars_to_json(copy.deepcopy(ENVIRONMENT_FOR_CREATE)) ) self.assertEqual(201, resp.status_int) @@ -190,7 +190,7 @@ class TestEnvironmentController(base.APITest): def test_post_with_illegal_field(self): resp = self.app.post_json( '/v2/environments', - _convert_vars_to_string( + _convert_vars_to_json( copy.deepcopy(ENVIRONMENT_WITH_ILLEGAL_FIELD)), expect_errors=True ) @@ -200,7 +200,7 @@ class TestEnvironmentController(base.APITest): def test_post_dup(self): resp = self.app.post_json( '/v2/environments', - _convert_vars_to_string(copy.deepcopy(ENVIRONMENT_FOR_CREATE)), + _convert_vars_to_json(copy.deepcopy(ENVIRONMENT_FOR_CREATE)), expect_errors=True ) @@ -208,7 +208,7 @@ class TestEnvironmentController(base.APITest): @mock.patch.object(db_api, 'create_environment', MOCK_ENVIRONMENT) def test_post_default_scope(self): - env = _convert_vars_to_string(copy.deepcopy(ENVIRONMENT_FOR_CREATE)) + env = _convert_vars_to_json(copy.deepcopy(ENVIRONMENT_FOR_CREATE)) resp = self.app.post_json('/v2/environments', env)