From 02c67bee3c60cf8d13f17ab6d43a785a248e89cc Mon Sep 17 00:00:00 2001 From: Nikolay Mahotkin Date: Thu, 20 Nov 2014 16:33:58 +0300 Subject: [PATCH] Use YAML text instead of JSON in HTTP body (client side) * Use YAML text instead of JSON for workbooks, workflows and actions in HTTP body. Implements blueprint mistral-yaml-request-body Change-Id: I344b6522b25bf51f52bb0db864be5a48625e3d18 --- mistralclient/api/v2/actions.py | 8 +++--- mistralclient/api/v2/workbooks.py | 22 +++++++++++++-- mistralclient/api/v2/workflows.py | 8 +++--- mistralclient/commands/v2/actions.py | 2 +- mistralclient/commands/v2/workbooks.py | 2 +- mistralclient/commands/v2/workflows.py | 2 +- .../tests/unit/v2/test_cli_actions.py | 2 +- .../tests/unit/v2/test_cli_workbooks.py | 2 +- .../tests/unit/v2/test_cli_workflows.py | 2 +- mistralclient/tests/unit/v2/test_workbooks.py | 28 +++++++++---------- 10 files changed, 48 insertions(+), 30 deletions(-) diff --git a/mistralclient/api/v2/actions.py b/mistralclient/api/v2/actions.py index 7b4e8202..44d573c4 100644 --- a/mistralclient/api/v2/actions.py +++ b/mistralclient/api/v2/actions.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json - from mistralclient.api import base @@ -29,7 +27,8 @@ class ActionManager(base.ResourceManager): resp = self.client.http_client.post( '/actions', - json.dumps({'definition': definition}) + definition, + headers={'content-type': 'text/plain'} ) if resp.status_code != 201: @@ -43,7 +42,8 @@ class ActionManager(base.ResourceManager): resp = self.client.http_client.put( '/actions', - json.dumps({'definition': definition}) + definition, + headers={'content-type': 'text/plain'} ) if resp.status_code != 200: diff --git a/mistralclient/api/v2/workbooks.py b/mistralclient/api/v2/workbooks.py index 19edadb0..03f005ed 100644 --- a/mistralclient/api/v2/workbooks.py +++ b/mistralclient/api/v2/workbooks.py @@ -25,12 +25,30 @@ class WorkbookManager(base.ResourceManager): def create(self, definition): self._ensure_not_empty(definition=definition) - return self._create('/workbooks', {'definition': definition}) + resp = self.client.http_client.post( + '/workbooks', + definition, + headers={'content-type': 'text/plain'} + ) + + if resp.status_code != 201: + self._raise_api_exception(resp) + + return self.resource_class(self, base.extract_json(resp, None)) def update(self, definition): self._ensure_not_empty(definition=definition) - return self._update('/workbooks', {'definition': definition}) + resp = self.client.http_client.put( + '/workbooks', + definition, + headers={'content-type': 'text/plain'} + ) + + if resp.status_code != 200: + self._raise_api_exception(resp) + + return self.resource_class(self, base.extract_json(resp, None)) def list(self): return self._list('/workbooks', response_key='workbooks') diff --git a/mistralclient/api/v2/workflows.py b/mistralclient/api/v2/workflows.py index 6ec89773..d7f5a863 100644 --- a/mistralclient/api/v2/workflows.py +++ b/mistralclient/api/v2/workflows.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json - from mistralclient.api import base @@ -29,7 +27,8 @@ class WorkflowManager(base.ResourceManager): resp = self.client.http_client.post( '/workflows', - json.dumps({'definition': definition}) + definition, + headers={'content-type': 'text/plain'} ) if resp.status_code != 201: @@ -43,7 +42,8 @@ class WorkflowManager(base.ResourceManager): resp = self.client.http_client.put( '/workflows', - json.dumps({'definition': definition}) + definition, + headers={'content-type': 'text/plain'} ) if resp.status_code != 200: diff --git a/mistralclient/commands/v2/actions.py b/mistralclient/commands/v2/actions.py index 01ea0af2..b025daeb 100644 --- a/mistralclient/commands/v2/actions.py +++ b/mistralclient/commands/v2/actions.py @@ -169,4 +169,4 @@ class GetDefinition(command.Command): definition = actions.ActionManager(self.app.client).get( parsed_args.name).definition - self.app.stdout.write(definition or "\n") + self.app.stdout.write(definition or "\n") \ No newline at end of file diff --git a/mistralclient/commands/v2/workbooks.py b/mistralclient/commands/v2/workbooks.py index 5fce58e2..3f20ba24 100644 --- a/mistralclient/commands/v2/workbooks.py +++ b/mistralclient/commands/v2/workbooks.py @@ -152,4 +152,4 @@ class GetDefinition(command.Command): definition = workbooks.WorkbookManager(self.app.client).get( parsed_args.name).definition - self.app.stdout.write(definition or "\n") + self.app.stdout.write(definition or "\n") \ No newline at end of file diff --git a/mistralclient/commands/v2/workflows.py b/mistralclient/commands/v2/workflows.py index 2c2ea3fe..d4b94b1f 100644 --- a/mistralclient/commands/v2/workflows.py +++ b/mistralclient/commands/v2/workflows.py @@ -163,4 +163,4 @@ class GetDefinition(command.Command): definition = workflows.WorkflowManager(self.app.client).get( parsed_args.name).definition - self.app.stdout.write(definition or "\n") + self.app.stdout.write(definition or "\n") \ No newline at end of file diff --git a/mistralclient/tests/unit/v2/test_cli_actions.py b/mistralclient/tests/unit/v2/test_cli_actions.py index dfae6dff..e48e9bfc 100644 --- a/mistralclient/tests/unit/v2/test_cli_actions.py +++ b/mistralclient/tests/unit/v2/test_cli_actions.py @@ -105,4 +105,4 @@ class TestCLIActionsV2(base.BaseCommandTest): self.call(action_cmd.GetDefinition, app_args=['name']) - self.app.stdout.write.assert_called_with(ACTION_DEF) + self.app.stdout.write.assert_called_with(ACTION_DEF) \ No newline at end of file diff --git a/mistralclient/tests/unit/v2/test_cli_workbooks.py b/mistralclient/tests/unit/v2/test_cli_workbooks.py index 46d28fdc..d651b6f3 100644 --- a/mistralclient/tests/unit/v2/test_cli_workbooks.py +++ b/mistralclient/tests/unit/v2/test_cli_workbooks.py @@ -95,4 +95,4 @@ class TestCLIWorkbooksV2(base.BaseCommandTest): self.call(workbook_cmd.GetDefinition, app_args=['name']) - self.app.stdout.write.assert_called_with(WB_DEF) + self.app.stdout.write.assert_called_with(WB_DEF) \ No newline at end of file diff --git a/mistralclient/tests/unit/v2/test_cli_workflows.py b/mistralclient/tests/unit/v2/test_cli_workflows.py index ed141228..625d0417 100644 --- a/mistralclient/tests/unit/v2/test_cli_workflows.py +++ b/mistralclient/tests/unit/v2/test_cli_workflows.py @@ -90,4 +90,4 @@ class TestCLIWorkflowsV2(base.BaseCommandTest): self.call(workflow_cmd.GetDefinition, app_args=['name']) - self.app.stdout.write.assert_called_with(WF_DEF) + self.app.stdout.write.assert_called_with(WF_DEF) \ No newline at end of file diff --git a/mistralclient/tests/unit/v2/test_workbooks.py b/mistralclient/tests/unit/v2/test_workbooks.py index 86f49d85..0ca3d114 100644 --- a/mistralclient/tests/unit/v2/test_workbooks.py +++ b/mistralclient/tests/unit/v2/test_workbooks.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json - from mistralclient.api.v2 import workbooks from mistralclient.tests.unit.v2 import base @@ -54,28 +52,30 @@ class TestWorkbooksV2(base.BaseClientV2Test): def test_create(self): mock = self.mock_http_post(content=WORKBOOK) - wb = self.workbooks.create(WORKBOOK['definition']) + wb = self.workbooks.create(WB_DEF) self.assertIsNotNone(wb) - self.assertEqual( - workbooks.Workbook(self.workbooks, WORKBOOK).__dict__, - wb.__dict__ - ) + self.assertEqual(WB_DEF, wb.definition) - mock.assert_called_once_with(URL_TEMPLATE, json.dumps(WORKBOOK)) + mock.assert_called_once_with( + URL_TEMPLATE, + WB_DEF, + headers={'content-type': 'text/plain'} + ) def test_update(self): mock = self.mock_http_put(content=WORKBOOK) - wb = self.workbooks.update(WORKBOOK['definition']) + wb = self.workbooks.update(WB_DEF) self.assertIsNotNone(wb) - self.assertEqual( - workbooks.Workbook(self.workbooks, WORKBOOK).__dict__, - wb.__dict__ - ) + self.assertEqual(WB_DEF, wb.definition) - mock.assert_called_once_with(URL_TEMPLATE, json.dumps(WORKBOOK)) + mock.assert_called_once_with( + URL_TEMPLATE, + WB_DEF, + headers={'content-type': 'text/plain'} + ) def test_list(self): mock = self.mock_http_get(content={'workbooks': [WORKBOOK]})