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