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
This commit is contained in:
parent
08d3113166
commit
02c67bee3c
@ -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:
|
||||
|
@ -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')
|
||||
|
@ -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:
|
||||
|
@ -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")
|
@ -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")
|
@ -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")
|
@ -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)
|
@ -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)
|
@ -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)
|
@ -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]})
|
||||
|
Loading…
Reference in New Issue
Block a user