Commit 56eeac5e authored by Romain Courteaud's avatar Romain Courteaud

erp5_json_rpc_api: WIP 2 actions

parent 81215fb0
......@@ -26,11 +26,11 @@
##############################################################################
import base64
import binascii
# import base64
# import binascii
import json
import typing
import six
# import six
from six.moves.urllib.parse import unquote
if typing.TYPE_CHECKING:
......@@ -40,7 +40,7 @@ if typing.TYPE_CHECKING:
_ = (
OpenAPIOperation, OpenAPIParameter, HTTPRequest, Any, Callable, Optional)
import jsonschema
# import jsonschema
from AccessControl import ClassSecurityInfo
from zExceptions import NotFound
from zope.publisher.browser import BrowserView
......@@ -51,9 +51,6 @@ import zope.interface
from Products.ERP5Type import Permissions, PropertySheet
from erp5.component.document.JsonRpcAPITypeInformation import (
NoMethodForOperationError,
ParameterValidationError,
SchemaDefinitionError,
byteify
)
from erp5.component.document.OpenAPIService import OpenAPIService
......@@ -119,6 +116,15 @@ class JsonRpcAPIService(OpenAPIService):
request_method = request.method.lower()
matched_operation = None
if (request_method == 'post') and (len(request_path_parts) == 1):
matched_operation = None
if request_path_parts[0] == 'WIP.create.installation':
matched_operation = 'jIOWebSection_createSoftwareInstallationFromJSON'
elif request_path_parts[0] == 'WIP.request':
matched_operation = 'jIOWebSection_requestSoftwareInstanceFromJSON'
self.log('ROMAIN %s' % str(request_path_parts))
"""
for operation in self.getTypeInfo().getOpenAPIOperationIterator():
if operation.request_method != request_method:
continue
......@@ -149,9 +155,11 @@ class JsonRpcAPIService(OpenAPIService):
# > their templated counterparts
matched_operation = operation
continue
"""
request.other['traverse_subpath'] = request_path_parts
return matched_operation
'''
def getMethodForOperation(self, operation):
# type: (OpenAPIOperation) -> Optional[Callable]
operation_id = operation.get('operationId')
......@@ -242,26 +250,15 @@ class JsonRpcAPIService(OpenAPIService):
{},
schema,
)
'''
def executeMethod(self, request):
self.log('XXX ROMAIN execute method')
if 1:
# jIOWebSection_requestSoftwareInstanceFromJSON
json_data = byteify(request.get('BODY'))
self.log(json_data)
return self.jIOWebSection_requestSoftwareInstanceFromJSON(json_data=byteify(json.loads(request.get('BODY'))))
#return 'nope'
#return self._asjIOStyle(mode="post", text_content=self.REQUEST.get('BODY'))
#raise NotImplementedError('plop')
# type: (HTTPRequest) -> Any
operation = self.getMatchingOperation(request)
if operation is None:
raise NotFound()
method = self.getMethodForOperation(operation)
parameters = self.extractParametersFromRequest(operation, request)
result = method(**parameters)
method = getattr(self, operation)#self.getMethodForOperation(operation)
# parameters = self.extractParametersFromRequest(operation, request)
result = method(json_data=byteify(json.loads(request.get('BODY'))))#**parameters)
response = request.RESPONSE
if response.getHeader('Content-Type'):
return result
......
......@@ -165,9 +165,26 @@ class TestJsonRpcAPIConnectorView(JsonRpcAPITestCase):
class TestJsonRpcAPIDemoDemoDemoXXXTOMoveTODO(JsonRpcAPITestCase):
def test_21_createSoftwareInstallation(self):
response = self.publish(
self.connector.getPath() + '/WIP.create.installation',
user='ERP5TypeTestCase',
request_method='POST',
stdin=io.BytesIO(
json.dumps(
{
"software_release_uri": "https://example.org/foobar",
"reference": "XXX",
"portal_type": "Software Instance",
"title": "new_name"
}).encode()),
env={'CONTENT_TYPE': 'application/json'})
self.assertEqual(response.getBody(), b'"ok"')
self.assertEqual(response.getStatus(), 200)
def test_21_request(self):
response = self.publish(
self.connector.getPath() + '/XXXcallAPIEndpointXXX',
self.connector.getPath() + '/WIP.request',
user='ERP5TypeTestCase',
request_method='POST',
stdin=io.BytesIO(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment