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
This commit is contained in:
Dougal Matthews 2016-06-09 20:13:33 +01:00
parent 468bd83b29
commit e15fba5967
5 changed files with 13 additions and 13 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)