userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
classes.py
1
import
dataclasses
2
import
pathlib
3
import
socket
4
import
typing
5
6
import
aiohttp.web
7
8
from
testsuite
import
types
9
from
testsuite.utils
import
callinfo, http, url_util
10
11
GenericRequestHandler = typing.Callable[
12
...,
13
types.MaybeAsyncResult[aiohttp.web.Response],
14
]
15
GenericRequestDecorator = typing.Callable[
16
[GenericRequestHandler],
17
callinfo.AsyncCallQueue,
18
]
19
JsonRequestHandler = typing.Callable[
20
...,
21
types.MaybeAsyncResult[
22
typing.Union[aiohttp.web.Response, types.JsonAnyOptional]
23
],
24
]
25
JsonRequestDecorator = typing.Callable[
26
[JsonRequestHandler],
27
callinfo.AsyncCallQueue,
28
]
29
MockserverRequest = http.Request
30
31
32
@dataclasses.dataclass(frozen=True)
33
class
SslCertInfo
:
34
cert_path: str
35
private_key_path: str
36
37
38
@dataclasses.dataclass(frozen=True)
39
class
MockserverInfo
:
40
host: str
41
port: int
42
base_url: str
43
socket_path: pathlib.Path |
None
=
None
44
https: bool =
False
45
46
def
url
(self, path: str) -> str:
47
"""Concats ``base_url`` and provided ``path``."""
48
return
url_util.join(self.
base_url
, path)
49
50
def
get_host_header(self) -> str:
51
if
self.
socket_path
:
52
return
str(self.
socket_path
)
53
54
if
not
self.
host
and
not
self.
port
:
55
raise
RuntimeError(
56
'either host and port or socket_path must be set in mockserver info'
57
)
58
59
if
self.
port
== 80:
60
return
str(self.
host
)
61
return
f
'{self.host}:{self.port}'
62
63
def
ws_url(self, path: str) -> str:
64
schema =
'wss'
if
self.
https
else
'ws'
65
return
url_util.join(f
'{schema}://{self.host}:{self.port}/'
, path)
66
67
68
@dataclasses.dataclass(frozen=True)
69
class
MockserverSocket
:
70
info: MockserverInfo
71
sockets: list[socket.socket]
72
73
74
@dataclasses.dataclass(frozen=True)
75
class
MockserverConfig
:
76
nofail: bool =
False
77
debug: bool =
False
78
tracing_enabled: bool =
False
79
trace_id_header: str =
''
80
span_id_header: str =
''
81
http_proxy_enabled: bool =
False
82
83
84
MockserverInfoFixture = MockserverInfo
85
MockserverSslInfoFixture = typing.Optional[MockserverInfo]
en
testsuite
mockserver
classes.py
Generated on
for userver by
Doxygen
1.17.0