2019-10-19 12:01:56 +00:00
|
|
|
"""OpenAPI core testing mock module"""
|
2018-04-17 14:37:52 +00:00
|
|
|
from werkzeug.datastructures import ImmutableMultiDict
|
|
|
|
|
2019-10-19 12:01:56 +00:00
|
|
|
from openapi_core.validation.request.datatypes import (
|
|
|
|
RequestParameters, OpenAPIRequest,
|
|
|
|
)
|
|
|
|
from openapi_core.validation.response.datatypes import OpenAPIResponse
|
2018-04-17 14:37:52 +00:00
|
|
|
|
|
|
|
|
2019-10-19 12:01:56 +00:00
|
|
|
class MockRequestFactory(object):
|
2018-04-17 14:37:52 +00:00
|
|
|
|
2019-10-19 12:01:56 +00:00
|
|
|
@classmethod
|
|
|
|
def create(
|
|
|
|
cls, host_url, method, path, path_pattern=None, args=None,
|
2018-04-17 14:37:52 +00:00
|
|
|
view_args=None, headers=None, cookies=None, data=None,
|
|
|
|
mimetype='application/json'):
|
2019-10-19 12:01:56 +00:00
|
|
|
parameters = RequestParameters(
|
|
|
|
path=view_args or {},
|
|
|
|
query=ImmutableMultiDict(args or []),
|
|
|
|
header=headers or {},
|
|
|
|
cookie=cookies or {},
|
|
|
|
)
|
|
|
|
path_pattern = path_pattern or path
|
|
|
|
method = method.lower()
|
|
|
|
body = data or ''
|
|
|
|
return OpenAPIRequest(
|
|
|
|
host_url=host_url,
|
|
|
|
path=path,
|
|
|
|
path_pattern=path_pattern,
|
|
|
|
method=method,
|
|
|
|
parameters=parameters,
|
|
|
|
body=body,
|
|
|
|
mimetype=mimetype,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class MockResponseFactory(object):
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def create(cls, data, status_code=200, mimetype='application/json'):
|
|
|
|
return OpenAPIResponse(
|
|
|
|
data=data,
|
|
|
|
status_code=status_code,
|
|
|
|
mimetype=mimetype,
|
|
|
|
)
|