From e15fba5967e451ddc067dc60333b172e65ef2115 Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Thu, 9 Jun 2016 20:13:33 +0100 Subject: [PATCH] Rename the to_string method to to_json to clarify it's purpose While technically accurate, it was returning a string, it would be good to explicitly state that it is a JSON string. Change-Id: I8527395bf99f92105027e2e8aeb54a0e5f7dc02d --- mistral/api/controllers/resource.py | 2 +- mistral/api/controllers/v2/action.py | 4 ++-- mistral/api/controllers/v2/workbook.py | 4 ++-- mistral/api/controllers/v2/workflow.py | 6 +++--- mistral/tests/unit/api/v2/test_environment.py | 10 +++++----- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/mistral/api/controllers/resource.py b/mistral/api/controllers/resource.py index 4052a1d5..af7b16f9 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 c4ad56f7..c1c90d74 100644 --- a/mistral/api/controllers/v2/action.py +++ b/mistral/api/controllers/v2/action.py @@ -131,7 +131,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") @@ -158,7 +158,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 ef299010..7e4b911b 100644 --- a/mistral/api/controllers/v2/workbook.py +++ b/mistral/api/controllers/v2/workbook.py @@ -95,7 +95,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") @@ -107,7 +107,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 1e6dcc54..39846ac1 100644 --- a/mistral/api/controllers/v2/workflow.py +++ b/mistral/api/controllers/v2/workflow.py @@ -189,8 +189,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") @@ -217,7 +217,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 92b823fc..28d7d7cb 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)