userver: testsuite.mockserver.server.MockserverFixture Class Reference
Loading...
Searching...
No Matches
testsuite.mockserver.server.MockserverFixture Class Reference

Detailed Description

Mockserver handler installer fixture.

Definition at line 377 of file server.py.

Public Member Functions

None __init__ (self, Server mockserver, Session session, str base_prefix='', *, bool strict_default=False)
'MockserverFixturenew (self, str prefix)
 Create mockserver installer with given base prefix.
str base_url (self)
 Mockserver base url.
str|None host (self)
 Mockserver hostname.
int|None port (self)
 Mockserver port.
str trace_id_header (self)
str span_id_header (self)
str trace_id (self)
classes.GenericRequestDecorator handler (self, str path, *, bool prefix=False, bool raw_request=False, bool json_response=False, bool regex=False, typing.Optional[bool] strict=None)
 Register basic http handler for path.
classes.JsonRequestDecorator json_handler (self, str path, *, bool prefix=False, bool raw_request=False, bool regex=False, typing.Optional[bool] strict=None)
 Register json http handler for path.
classes.GenericRequestDecorator aiohttp_handler (self, str path, *, bool prefix=False, bool regex=False, typing.Optional[bool] strict=None)
classes.JsonRequestDecorator aiohttp_json_handler (self, str path, *, bool prefix=False, bool regex=False, typing.Optional[bool] strict=None)
str url (self, str path)
 Builds mockserver url for path.
yarl.URL url_encoded (self, str path)
 Builds mockserver url for path.
str ws_url (self, str path)
typing.ContextManager[None] ignore_trace_id (self)
 tracing (self, bool value=True)
callinfo.AsyncCallQueue get_callqueue_for (self, path)

Public Attributes

 base_url

Static Public Attributes

 make_response = staticmethod(http.make_response)
 TimeoutError = http.TimeoutError
 NetworkError = http.NetworkError

Protected Member Functions

typing.Callable _handler_installer (self, str path, *, typing.Optional[bool] strict, bool prefix=False, bool raw_request=False, bool json_response=False, bool regex=False)
str _build_fullpath (self, path, bool regex=False)

Protected Attributes

 _server = mockserver
 _session = session
 _base_prefix = base_prefix
 _base_prefix_re = re.escape(base_prefix)
 _strict_default = strict_default

Constructor & Destructor Documentation

◆ __init__()

None testsuite.mockserver.server.MockserverFixture.__init__ ( self,
Server mockserver,
Session session,
str base_prefix = '',
* ,
bool strict_default = False )

Definition at line 380 of file server.py.

Member Function Documentation

◆ _build_fullpath()

str testsuite.mockserver.server.MockserverFixture._build_fullpath ( self,
path,
bool regex = False )
protected

Definition at line 620 of file server.py.

◆ _handler_installer()

typing.Callable testsuite.mockserver.server.MockserverFixture._handler_installer ( self,
str path,
* ,
typing.Optional[bool] strict,
bool prefix = False,
bool raw_request = False,
bool json_response = False,
bool regex = False )
protected

Definition at line 589 of file server.py.

◆ aiohttp_handler()

classes.GenericRequestDecorator testsuite.mockserver.server.MockserverFixture.aiohttp_handler ( self,
str path,
* ,
bool prefix = False,
bool regex = False,
typing.Optional[bool] strict = None )

Definition at line 523 of file server.py.

◆ aiohttp_json_handler()

classes.JsonRequestDecorator testsuite.mockserver.server.MockserverFixture.aiohttp_json_handler ( self,
str path,
* ,
bool prefix = False,
bool regex = False,
typing.Optional[bool] strict = None )

Definition at line 540 of file server.py.

◆ base_url()

str testsuite.mockserver.server.MockserverFixture.base_url ( self)

Mockserver base url.

Definition at line 403 of file server.py.

◆ get_callqueue_for()

callinfo.AsyncCallQueue testsuite.mockserver.server.MockserverFixture.get_callqueue_for ( self,
path )

Definition at line 580 of file server.py.

◆ handler()

classes.GenericRequestDecorator testsuite.mockserver.server.MockserverFixture.handler ( self,
str path,
* ,
bool prefix = False,
bool raw_request = False,
bool json_response = False,
bool regex = False,
typing.Optional[bool] strict = None )

Register basic http handler for path.

Returns decorator that registers handler path. Original function is wrapped with :ref:AsyncCallQueue.

:param path: match url by prefix if True exact match otherwise :param raw_request: pass aiohttp.web.Response to handler instead of testsuite.utils.http.Request :param regex: set True to match path as regex pattern :param prefix: set True to match path prefix instead of whole path :param json_response: set True to let handler return json object instead of full response object

.. code-block:: python

@mockserver.handler('/service/path') def handler(request: testsuite.utils.http.Request): return mockserver.make_response('Hello, world!')

Definition at line 429 of file server.py.

◆ host()

str | None testsuite.mockserver.server.MockserverFixture.host ( self)

Mockserver hostname.

Definition at line 408 of file server.py.

◆ ignore_trace_id()

typing.ContextManager[None] testsuite.mockserver.server.MockserverFixture.ignore_trace_id ( self)

Definition at line 568 of file server.py.

◆ json_handler()

classes.JsonRequestDecorator testsuite.mockserver.server.MockserverFixture.json_handler ( self,
str path,
* ,
bool prefix = False,
bool raw_request = False,
bool regex = False,
typing.Optional[bool] strict = None )

Register json http handler for path.

Returns decorator that registers handler path. Original function is wrapped with :ref:AsyncCallQueue.

:param path: match url by prefix if True exact match otherwise :param raw_request: pass aiohttp.web.Response to handler instead of testsuite.utils.http.Request :param prefix: set True to match path prefix instead of whole path :param regex: set True to match path as regex pattern

.. code-block:: python

@mockserver.json_handler('/service/path') def handler(request: testsuite.utils.http.Request):

Return JSON document

return {...}

or call to mockserver.make_response()

return mockserver.make_response(...)

Definition at line 479 of file server.py.

◆ new()

'MockserverFixture' testsuite.mockserver.server.MockserverFixture.new ( self,
str prefix )

Create mockserver installer with given base prefix.

Definition at line 394 of file server.py.

◆ port()

int | None testsuite.mockserver.server.MockserverFixture.port ( self)

Mockserver port.

Definition at line 413 of file server.py.

◆ span_id_header()

str testsuite.mockserver.server.MockserverFixture.span_id_header ( self)

Definition at line 422 of file server.py.

◆ trace_id()

str testsuite.mockserver.server.MockserverFixture.trace_id ( self)

Definition at line 426 of file server.py.

◆ trace_id_header()

str testsuite.mockserver.server.MockserverFixture.trace_id_header ( self)

Definition at line 418 of file server.py.

◆ tracing()

testsuite.mockserver.server.MockserverFixture.tracing ( self,
bool value = True )

Definition at line 572 of file server.py.

◆ url()

str testsuite.mockserver.server.MockserverFixture.url ( self,
str path )

Builds mockserver url for path.

Definition at line 557 of file server.py.

◆ url_encoded()

yarl.URL testsuite.mockserver.server.MockserverFixture.url_encoded ( self,
str path )

Builds mockserver url for path.

Definition at line 561 of file server.py.

◆ ws_url()

str testsuite.mockserver.server.MockserverFixture.ws_url ( self,
str path )

Definition at line 565 of file server.py.

Member Data Documentation

◆ _base_prefix

testsuite.mockserver.server.MockserverFixture._base_prefix = base_prefix
protected

Definition at line 390 of file server.py.

◆ _base_prefix_re

testsuite.mockserver.server.MockserverFixture._base_prefix_re = re.escape(base_prefix)
protected

Definition at line 391 of file server.py.

◆ _server

testsuite.mockserver.server.MockserverFixture._server = mockserver
protected

Definition at line 388 of file server.py.

◆ _session

testsuite.mockserver.server.MockserverFixture._session = session
protected

Definition at line 389 of file server.py.

◆ _strict_default

testsuite.mockserver.server.MockserverFixture._strict_default = strict_default
protected

Definition at line 392 of file server.py.

◆ base_url

testsuite.mockserver.server.MockserverFixture.base_url

Definition at line 559 of file server.py.

◆ make_response

testsuite.mockserver.server.MockserverFixture.make_response = staticmethod(http.make_response)
static

Definition at line 584 of file server.py.

◆ NetworkError

testsuite.mockserver.server.MockserverFixture.NetworkError = http.NetworkError
static

Definition at line 587 of file server.py.

◆ TimeoutError

testsuite.mockserver.server.MockserverFixture.TimeoutError = http.TimeoutError
static

Definition at line 586 of file server.py.


The documentation for this class was generated from the following file: