Merge "Rename the to_string method to to_json to clarify it's purpose"

This commit is contained in:
Jenkins 2016-06-15 05:28:31 +00:00 committed by Gerrit Code Review
commit 02663c97ac
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

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

View File

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

View File

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

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)