|
1 | | -"""OpenAPI core wrappers module""" |
| 1 | +"""OpenAPI core testing mock module""" |
2 | 2 | from werkzeug.datastructures import ImmutableMultiDict |
3 | 3 |
|
4 | | -from openapi_core.wrappers.base import BaseOpenAPIRequest, BaseOpenAPIResponse |
| 4 | +from openapi_core.validation.request.datatypes import ( |
| 5 | + RequestParameters, OpenAPIRequest, |
| 6 | +) |
| 7 | +from openapi_core.validation.response.datatypes import OpenAPIResponse |
5 | 8 |
|
6 | 9 |
|
7 | | -class MockRequest(BaseOpenAPIRequest): |
| 10 | +class MockRequestFactory(object): |
8 | 11 |
|
9 | | - def __init__( |
10 | | - self, host_url, method, path, path_pattern=None, args=None, |
| 12 | + @classmethod |
| 13 | + def create( |
| 14 | + cls, host_url, method, path, path_pattern=None, args=None, |
11 | 15 | view_args=None, headers=None, cookies=None, data=None, |
12 | 16 | mimetype='application/json'): |
13 | | - self.host_url = host_url |
14 | | - self.path = path |
15 | | - self.path_pattern = path_pattern or path |
16 | | - self.method = method.lower() |
17 | | - |
18 | | - self.parameters = { |
19 | | - 'path': view_args or {}, |
20 | | - 'query': ImmutableMultiDict(args or []), |
21 | | - 'header': headers or {}, |
22 | | - 'cookie': cookies or {}, |
23 | | - } |
24 | | - |
25 | | - self.body = data or '' |
26 | | - |
27 | | - self.mimetype = mimetype |
28 | | - |
29 | | - |
30 | | -class MockResponse(BaseOpenAPIResponse): |
31 | | - |
32 | | - def __init__(self, data, status_code=200, mimetype='application/json'): |
33 | | - self.data = data |
34 | | - |
35 | | - self.status_code = status_code |
36 | | - self.mimetype = mimetype |
| 17 | + parameters = RequestParameters( |
| 18 | + path=view_args or {}, |
| 19 | + query=ImmutableMultiDict(args or []), |
| 20 | + header=headers or {}, |
| 21 | + cookie=cookies or {}, |
| 22 | + ) |
| 23 | + path_pattern = path_pattern or path |
| 24 | + method = method.lower() |
| 25 | + body = data or '' |
| 26 | + return OpenAPIRequest( |
| 27 | + host_url=host_url, |
| 28 | + path=path, |
| 29 | + path_pattern=path_pattern, |
| 30 | + method=method, |
| 31 | + parameters=parameters, |
| 32 | + body=body, |
| 33 | + mimetype=mimetype, |
| 34 | + ) |
| 35 | + |
| 36 | + |
| 37 | +class MockResponseFactory(object): |
| 38 | + |
| 39 | + @classmethod |
| 40 | + def create(cls, data, status_code=200, mimetype='application/json'): |
| 41 | + return OpenAPIResponse( |
| 42 | + data=data, |
| 43 | + status_code=status_code, |
| 44 | + mimetype=mimetype, |
| 45 | + ) |
0 commit comments