File: requests.py

package info (click to toggle)
python-openapi-core 0.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,104 kB
  • sloc: python: 19,979; makefile: 44
file content (43 lines) | stat: -rw-r--r-- 1,313 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""OpenAPI core testing requests module"""

from typing import Any
from typing import Dict
from typing import Optional

from werkzeug.datastructures import Headers
from werkzeug.datastructures import ImmutableMultiDict

from openapi_core.datatypes import RequestParameters


class MockRequest:
    def __init__(
        self,
        host_url: str,
        method: str,
        path: str,
        path_pattern: Optional[str] = None,
        args: Optional[Dict[str, Any]] = None,
        view_args: Optional[Dict[str, Any]] = None,
        headers: Optional[Dict[str, Any]] = None,
        cookies: Optional[Dict[str, Any]] = None,
        data: Optional[bytes] = None,
        content_type: str = "application/json",
    ):
        self.host_url = host_url
        self.method = method.lower()
        self.path = path
        self.path_pattern = path_pattern
        self.args = args
        self.view_args = view_args
        self.headers = headers
        self.cookies = cookies
        self.body = data or b""
        self.content_type = content_type

        self.parameters = RequestParameters(
            path=self.view_args or {},
            query=ImmutableMultiDict(self.args or {}),
            header=Headers(self.headers or {}),
            cookie=ImmutableMultiDict(self.cookies or {}),
        )