Restructure flask and mock

This commit is contained in:
p1c2u 2019-10-19 12:01:50 +01:00
parent 06041458e0
commit 8a614de0bb
11 changed files with 37 additions and 28 deletions

View file

@ -86,7 +86,7 @@ Request object should implement BaseOpenAPIRequest interface. You can use FlaskO
.. code-block:: python
from openapi_core.shortcuts import RequestValidator
from openapi_core.wrappers.flask import FlaskOpenAPIRequest
from openapi_core.contrib.flask import FlaskOpenAPIRequest
openapi_request = FlaskOpenAPIRequest(flask_request)
validator = RequestValidator(spec)
@ -141,7 +141,7 @@ Response object should implement BaseOpenAPIResponse interface. You can use Flas
.. code-block:: python
from openapi_core.shortcuts import ResponseValidator
from openapi_core.wrappers.flask import FlaskOpenAPIResponse
from openapi_core.contrib.flask import FlaskOpenAPIResponse
openapi_response = FlaskOpenAPIResponse(flask_response)
validator = ResponseValidator(spec)

View file

View file

@ -0,0 +1,4 @@
from openapi_core.contrib.flask.requests import FlaskOpenAPIRequest
from openapi_core.contrib.flask.responses import FlaskOpenAPIResponse
__all__ = ['FlaskOpenAPIRequest', 'FlaskOpenAPIResponse']

View file

@ -1,7 +1,7 @@
"""OpenAPI core wrappers module"""
"""OpenAPI core contrib flask requests module"""
import re
from openapi_core.wrappers.base import BaseOpenAPIRequest, BaseOpenAPIResponse
from openapi_core.wrappers.base import BaseOpenAPIRequest
# http://flask.pocoo.org/docs/1.0/quickstart/#variable-rules
PATH_PARAMETER_PATTERN = r'<(?:(?:string|int|float|path|uuid):)?(\w+)>'
@ -49,21 +49,3 @@ class FlaskOpenAPIRequest(BaseOpenAPIRequest):
@property
def mimetype(self):
return self.request.mimetype
class FlaskOpenAPIResponse(BaseOpenAPIResponse):
def __init__(self, response):
self.response = response
@property
def data(self):
return self.response.data
@property
def status_code(self):
return self.response._status_code
@property
def mimetype(self):
return self.response.mimetype

View file

@ -0,0 +1,22 @@
"""OpenAPI core contrib flask responses module"""
import re
from openapi_core.wrappers.base import BaseOpenAPIResponse
class FlaskOpenAPIResponse(BaseOpenAPIResponse):
def __init__(self, response):
self.response = response
@property
def data(self):
return self.response.data
@property
def status_code(self):
return self.response._status_code
@property
def mimetype(self):
return self.response.mimetype

View file

View file

@ -1,14 +1,15 @@
from flask.wrappers import Request, Response
import pytest
from werkzeug.datastructures import EnvironHeaders, ImmutableMultiDict
from werkzeug.routing import Map, Rule, Subdomain
from werkzeug.test import create_environ
import pytest
from openapi_core.shortcuts import create_spec
from openapi_core.validation.response.validators import ResponseValidator
from openapi_core.validation.request.validators import RequestValidator
from openapi_core.wrappers.flask import (FlaskOpenAPIRequest,
FlaskOpenAPIResponse)
from openapi_core.contrib.flask import (
FlaskOpenAPIRequest, FlaskOpenAPIResponse,
)
@pytest.fixture

View file

@ -3,8 +3,8 @@ import pytest
from openapi_core.schema.operations.exceptions import InvalidOperation
from openapi_core.schema.paths.exceptions import InvalidPath
from openapi_core.shortcuts import create_spec
from openapi_core.testing.mock import MockRequest
from openapi_core.validation.request.validators import RequestValidator
from openapi_core.wrappers.mock import MockRequest
class TestMinimal(object):

View file

@ -16,10 +16,10 @@ from openapi_core.schema.schemas.enums import SchemaType
from openapi_core.schema.schemas.exceptions import InvalidSchemaValue
from openapi_core.schema.servers.exceptions import InvalidServer
from openapi_core.shortcuts import create_spec
from openapi_core.testing.mock import MockRequest, MockResponse
from openapi_core.validation.request.datatypes import RequestParameters
from openapi_core.validation.request.validators import RequestValidator
from openapi_core.validation.response.validators import ResponseValidator
from openapi_core.wrappers.mock import MockRequest, MockResponse
class TestPetstore(object):

View file

@ -17,10 +17,10 @@ from openapi_core.schema.responses.exceptions import (
)
from openapi_core.schema.servers.exceptions import InvalidServer
from openapi_core.shortcuts import create_spec
from openapi_core.testing.mock import MockRequest, MockResponse
from openapi_core.validation.request.datatypes import RequestParameters
from openapi_core.validation.request.validators import RequestValidator
from openapi_core.validation.response.validators import ResponseValidator
from openapi_core.wrappers.mock import MockRequest, MockResponse
class TestRequestValidator(object):