Commit bc40dfa5 authored by Jérome Perrin's avatar Jérome Perrin

open_api: py3

parent 3a08100d
...@@ -90,7 +90,7 @@ ModuleSecurityInfo(__name__).declarePublic( ...@@ -90,7 +90,7 @@ ModuleSecurityInfo(__name__).declarePublic(
) )
# On python2, make sure we use UTF-8 strings for the json schemas, so that we don't # On python2, make sure we use UTF-8 strings for the json schemas, so that we don't
# have ugly u' prefixs in the reprs. This also transforms the collections.OrderedDict # have ugly u' prefixes in the reprs. This also transforms the collections.OrderedDict
# to simple dicts, because the former also have an ugly representation. # to simple dicts, because the former also have an ugly representation.
# http://stackoverflow.com/a/13105359 # http://stackoverflow.com/a/13105359
if six.PY2: if six.PY2:
...@@ -340,7 +340,10 @@ class OpenAPITypeInformation(ERP5TypeInformation): ...@@ -340,7 +340,10 @@ class OpenAPITypeInformation(ERP5TypeInformation):
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
def getSchema(self): def getSchema(self):
stream = io.BytesIO(self.getTextContent() or b'{}') text_content = self.getTextContent() or '{}'
if six.PY3:
text_content = text_content.encode()
stream = io.BytesIO(text_content)
if self.getContentType() == 'application/x-yaml': if self.getContentType() == 'application/x-yaml':
try: try:
import yaml # pylint:disable=import-error import yaml # pylint:disable=import-error
......
...@@ -39,7 +39,7 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase ...@@ -39,7 +39,7 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
class OpenAPITestCase(ERP5TypeTestCase): class OpenAPITestCase(ERP5TypeTestCase):
_type_id = NotImplemented # type: str _type_id = NotImplemented # type: str
_open_api_schema = NotImplemented # type: bytes _open_api_schema = NotImplemented # type: str
_open_api_schema_content_type = 'application/json' _open_api_schema_content_type = 'application/json'
_public_api = True _public_api = True
...@@ -375,7 +375,7 @@ class TestOpenAPIServicePetController(OpenAPIPetStoreTestCase): ...@@ -375,7 +375,7 @@ class TestOpenAPIServicePetController(OpenAPIPetStoreTestCase):
class TestOpenAPIServiceYaml(OpenAPITestCase): class TestOpenAPIServiceYaml(OpenAPITestCase):
_type_id = 'Test Open API YAML' _type_id = 'Test Open API YAML'
_open_api_schema_content_type = 'application/x-yaml' _open_api_schema_content_type = 'application/x-yaml'
_open_api_schema = b''' _open_api_schema = '''
openapi: 3.0.3 openapi: 3.0.3
info: info:
title: TestOpenAPIServiceYaml title: TestOpenAPIServiceYaml
...@@ -456,7 +456,7 @@ class TestPathParameterSerialization(OpenAPITestCase): ...@@ -456,7 +456,7 @@ class TestPathParameterSerialization(OpenAPITestCase):
} }
} }
} }
}).encode() })
def test_primitive_parameter_serialization(self): def test_primitive_parameter_serialization(self):
self.addPythonScript( self.addPythonScript(
...@@ -532,7 +532,7 @@ class TestQueryParameterSerialization(OpenAPITestCase): ...@@ -532,7 +532,7 @@ class TestQueryParameterSerialization(OpenAPITestCase):
} }
} }
} }
}).encode() })
def test_array_parameter_serialization(self): def test_array_parameter_serialization(self):
self.addPythonScript( self.addPythonScript(
...@@ -707,7 +707,7 @@ class TestOpenAPINonAsciiParameters(OpenAPIPetStoreTestCase): ...@@ -707,7 +707,7 @@ class TestOpenAPINonAsciiParameters(OpenAPIPetStoreTestCase):
class TestOpenAPICommonParameters(OpenAPIPetStoreTestCase): class TestOpenAPICommonParameters(OpenAPIPetStoreTestCase):
_type_id = 'Test Open API Common Parameters' _type_id = 'Test Open API Common Parameters'
_open_api_schema = ( _open_api_schema = (
b''' '''
{ {
"openapi": "3.0.3", "openapi": "3.0.3",
"info": { "info": {
...@@ -718,7 +718,7 @@ class TestOpenAPICommonParameters(OpenAPIPetStoreTestCase): ...@@ -718,7 +718,7 @@ class TestOpenAPICommonParameters(OpenAPIPetStoreTestCase):
''' '''
# https://swagger.io/docs/specification/describing-parameters/#common-for-path # https://swagger.io/docs/specification/describing-parameters/#common-for-path
b''' '''
"/common-for-path": { "/common-for-path": {
"parameters": [ "parameters": [
{ {
...@@ -749,7 +749,7 @@ class TestOpenAPICommonParameters(OpenAPIPetStoreTestCase): ...@@ -749,7 +749,7 @@ class TestOpenAPICommonParameters(OpenAPIPetStoreTestCase):
},''' },'''
# https://swagger.io/docs/specification/describing-parameters/#common-for-various-paths # https://swagger.io/docs/specification/describing-parameters/#common-for-various-paths
b''' '''
"/common-for-various-paths": { "/common-for-various-paths": {
"get": { "get": {
"operationId": "testGET2", "operationId": "testGET2",
...@@ -761,7 +761,7 @@ class TestOpenAPICommonParameters(OpenAPIPetStoreTestCase): ...@@ -761,7 +761,7 @@ class TestOpenAPICommonParameters(OpenAPIPetStoreTestCase):
''' '''
# here we also excercice $refs in parameter schemas # here we also excercice $refs in parameter schemas
b''' '''
"$ref": "#/components/schemas/custom-number" "$ref": "#/components/schemas/custom-number"
} }
}, },
...@@ -781,7 +781,7 @@ class TestOpenAPICommonParameters(OpenAPIPetStoreTestCase): ...@@ -781,7 +781,7 @@ class TestOpenAPICommonParameters(OpenAPIPetStoreTestCase):
# https://spec.openapis.org/oas/v3.1.0#fixed-fields-6 # https://spec.openapis.org/oas/v3.1.0#fixed-fields-6
# $refs: Allows for a referenced definition of this path item. # $refs: Allows for a referenced definition of this path item.
# The referenced structure MUST be in the form of a Path Item Object. # The referenced structure MUST be in the form of a Path Item Object.
b''' '''
"/alias": { "/alias": {
"$ref": "#/paths/~1common-for-path" "$ref": "#/paths/~1common-for-path"
} }
...@@ -895,7 +895,7 @@ class TestOpenAPIMissingParameters(OpenAPIPetStoreTestCase): ...@@ -895,7 +895,7 @@ class TestOpenAPIMissingParameters(OpenAPIPetStoreTestCase):
} }
} }
} }
}).encode() })
def test_required_query(self): def test_required_query(self):
self.addPythonScript( self.addPythonScript(
...@@ -980,7 +980,7 @@ class TestOpenAPIErrorHandling(OpenAPIPetStoreTestCase): ...@@ -980,7 +980,7 @@ class TestOpenAPIErrorHandling(OpenAPIPetStoreTestCase):
self.addPythonScript( self.addPythonScript(
'TestPetStoreOpenAPI_findPetsByStatus', 'TestPetStoreOpenAPI_findPetsByStatus',
'status', 'status',
'1/0', '1//0',
) )
response = self.publish( response = self.publish(
self.connector.getPath() + '/pet/findByStatus?status=available') self.connector.getPath() + '/pet/findByStatus?status=available')
...@@ -1097,7 +1097,7 @@ class TestPathParameterAndAcquisition(OpenAPIPetStoreTestCase): ...@@ -1097,7 +1097,7 @@ class TestPathParameterAndAcquisition(OpenAPIPetStoreTestCase):
""" """
def afterSetUp(self): def afterSetUp(self):
super(TestPathParameterAndAcquisition, self).afterSetUp() super(TestPathParameterAndAcquisition, self).afterSetUp()
if not '789' in self.portal.portal_web_services.objectIds(): if '789' not in self.portal.portal_web_services.objectIds():
self.portal.portal_web_services.newContent( self.portal.portal_web_services.newContent(
id='789', id='789',
portal_type=self.portal.portal_web_services.allowedContentTypes() portal_type=self.portal.portal_web_services.allowedContentTypes()
......
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