2020-01-17 14:20:20 +00:00
|
|
|
"""OpenAPI core testing requests module"""
|
2020-02-11 14:54:36 +00:00
|
|
|
from six.moves.urllib.parse import urljoin
|
2020-01-17 14:20:20 +00:00
|
|
|
from werkzeug.datastructures import ImmutableMultiDict
|
|
|
|
|
|
|
|
from openapi_core.validation.request.datatypes import (
|
|
|
|
RequestParameters, OpenAPIRequest,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class MockRequestFactory(object):
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def create(
|
|
|
|
cls, host_url, method, path, path_pattern=None, args=None,
|
|
|
|
view_args=None, headers=None, cookies=None, data=None,
|
|
|
|
mimetype='application/json'):
|
|
|
|
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 ''
|
2020-02-11 14:54:36 +00:00
|
|
|
full_url_pattern = urljoin(host_url, path_pattern)
|
2020-01-17 14:20:20 +00:00
|
|
|
return OpenAPIRequest(
|
2020-02-11 14:54:36 +00:00
|
|
|
full_url_pattern=full_url_pattern,
|
2020-01-17 14:20:20 +00:00
|
|
|
method=method,
|
|
|
|
parameters=parameters,
|
|
|
|
body=body,
|
|
|
|
mimetype=mimetype,
|
|
|
|
)
|