aioresponses package¶
Submodules¶
aioresponses.compat module¶
- class aioresponses.compat.Pattern¶
Bases:
object
Compiled regular expression object.
- findall(string, pos=0, endpos=9223372036854775807)¶
Return a list of all non-overlapping matches of pattern in string.
- finditer(string, pos=0, endpos=9223372036854775807)¶
Return an iterator over all non-overlapping matches for the RE pattern in string.
For each match, the iterator returns a match object.
- flags¶
The regex matching flags.
- fullmatch(string, pos=0, endpos=9223372036854775807)¶
Matches against all of the string.
- groupindex¶
A dictionary mapping group names to group numbers.
- groups¶
The number of capturing groups in the pattern.
- match(string, pos=0, endpos=9223372036854775807)¶
Matches zero or more characters at the beginning of the string.
- pattern¶
The pattern string from which the RE object was compiled.
- scanner(string, pos=0, endpos=9223372036854775807)¶
- search(string, pos=0, endpos=9223372036854775807)¶
Scan through string looking for a match, and return a corresponding match object instance.
Return None if no position in the string matches.
- split(string, maxsplit=0)¶
Split string by the occurrences of pattern.
- sub(repl, string, count=0)¶
Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl.
- subn(repl, string, count=0)¶
Return the tuple (new_string, number_of_subs_made) found by replacing the leftmost non-overlapping occurrences of pattern with the replacement repl.
- class aioresponses.compat.RequestInfo(url: URL, method: str, headers: CIMultiDictProxy[str], real_url: URL = _Nothing.NOTHING)[source]¶
Bases:
object
- headers: CIMultiDictProxy[str]¶
- method: str¶
- class aioresponses.compat.URL(val='', *, encoded=False, strict=None)¶
Bases:
object
- classmethod build(*, scheme='', authority='', user=None, password=None, host='', port=None, path='', query=None, query_string='', fragment='', encoded=False)[source]¶
Creates and returns a new URL
- property explicit_port¶
Port part of URL, without scheme-based fallback.
None for relative URLs or URLs without explicit port.
- is_absolute()[source]¶
A check for absolute URLs.
Return True for absolute ones (having scheme or starting with //), False otherwise.
- is_default_port()[source]¶
A check for default port.
Return True if port is default for specified scheme, e.g. ‘http://python.org’ or ‘http://python.org:80’, False otherwise.
- join(url)[source]¶
Join URLs
Construct a full (“absolute”) URL by combining a “base URL” (self) with another URL (url).
Informally, this uses components of the base URL, in particular the addressing scheme, the network location and (part of) the path, to provide missing components in the relative URL.
- origin()[source]¶
Return an URL with scheme, host and port parts only.
user, password, path, query and fragment are removed.
- property port¶
Port part of URL, with scheme-based fallback.
None for relative URLs or URLs without explicit port and scheme without default port substitution.
- query[source]¶
A MultiDictProxy representing parsed query parameters in decoded representation.
Empty value if URL has no query part.
- property raw_authority¶
Encoded authority part of URL.
Empty string for relative URLs.
- property raw_fragment¶
Encoded fragment part of URL.
Empty string if fragment is missing.
- property raw_host¶
Encoded host part of URL.
None for relative URLs.
- raw_parts[source]¶
A tuple containing encoded path parts.
(‘/’,) for absolute URLs if path is missing.
- property raw_password¶
Encoded password part of URL.
None if password is missing.
- property raw_path¶
Encoded path of URL.
/ for absolute URLs without path part.
- property raw_query_string¶
Encoded query part of URL.
Empty string if query is missing.
- property raw_user¶
Encoded user part of URL.
None if user is missing.
- relative()[source]¶
Return a relative part of the URL.
scheme, user, password, host and port are removed.
- property scheme¶
Scheme for absolute URLs.
Empty string for relative URLs or URLs starting with //
- with_fragment(fragment)[source]¶
Return a new URL with fragment replaced.
Autoencode fragment if needed.
Clear fragment to default if None is passed.
- with_host(host)[source]¶
Return a new URL with host replaced.
Autoencode host if needed.
Changing host for relative URLs is not allowed, use .join() instead.
- with_name(name)[source]¶
Return a new URL with name (last part of path) replaced.
Query and fragment parts are cleaned up.
Name is encoded if needed.
- with_password(password)[source]¶
Return a new URL with password replaced.
Autoencode password if needed.
Clear password if argument is None.
- with_port(port)[source]¶
Return a new URL with port replaced.
Clear port to default if None is passed.
- with_query(*args, **kwargs)[source]¶
Return a new URL with query part replaced.
Accepts any Mapping (e.g. dict, multidict.MultiDict instances) or str, autoencode the argument if needed.
A sequence of (key, value) pairs is supported as well.
It also can take an arbitrary number of keyword arguments.
Clear query if None is passed.
aioresponses.core module¶
- class aioresponses.core.CallbackResult(method: str = 'GET', status: int = 200, body: Union[str, bytes] = '', content_type: str = 'application/json', payload: Optional[Dict] = None, headers: Optional[Dict] = None, response_class: Optional[Type[ClientResponse]] = None, reason: Optional[str] = None)[source]¶
Bases:
object
- class aioresponses.core.RequestCall(args, kwargs)¶
Bases:
tuple
- args¶
Alias for field number 0
- kwargs¶
Alias for field number 1
- class aioresponses.core.RequestMatch(url: Union[URL, str, Pattern], method: str = 'GET', status: int = 200, body: Union[str, bytes] = '', payload: Optional[Dict] = None, exception: Optional[Exception] = None, headers: Optional[Dict] = None, content_type: str = 'application/json', response_class: Optional[Type[ClientResponse]] = None, timeout: bool = False, repeat: bool = False, reason: Optional[str] = None, callback: Optional[Callable] = None)[source]¶
Bases:
object
- class aioresponses.core.aioresponses(**kwargs: Any)[source]¶
Bases:
object
Mock aiohttp requests made by ClientSession.
- add(url: Union[URL, str, Pattern], method: str = 'GET', status: int = 200, body: Union[str, bytes] = '', exception: Optional[Exception] = None, content_type: str = 'application/json', payload: Optional[Dict] = None, headers: Optional[Dict] = None, response_class: Optional[Type[ClientResponse]] = None, repeat: bool = False, timeout: bool = False, reason: Optional[str] = None, callback: Optional[Callable] = None) None [source]¶
- assert_any_call(url: Union[URL, str, Pattern], method: str = 'GET', *args: Any, **kwargs: Any)[source]¶
assert the mock has been called with the specified arguments. The assert passes if the mock has ever been called, unlike assert_called_with and assert_called_once_with that only pass if the call is the most recent one.
- assert_called_once_with(*args: Any, **kwargs: Any)[source]¶
assert that the mock was called once with the specified arguments. Raises an AssertionError if the args and keyword args passed in are different to the only call to the mock.
- assert_called_with(url: Union[URL, str, Pattern], method: str = 'GET', *args: Any, **kwargs: Any)[source]¶
assert that the last call was made with the specified arguments.
Raises an AssertionError if the args and keyword args passed in are different to the last call to the mock.
- async match(method: str, url: URL, allow_redirects: bool = True, **kwargs: Any) Optional[ClientResponse] [source]¶
- requests: Dict = None¶
Module contents¶
- class aioresponses.CallbackResult(method: str = 'GET', status: int = 200, body: Union[str, bytes] = '', content_type: str = 'application/json', payload: Optional[Dict] = None, headers: Optional[Dict] = None, response_class: Optional[Type[ClientResponse]] = None, reason: Optional[str] = None)[source]¶
Bases:
object
- class aioresponses.aioresponses(**kwargs: Any)[source]¶
Bases:
object
Mock aiohttp requests made by ClientSession.
- add(url: Union[URL, str, Pattern], method: str = 'GET', status: int = 200, body: Union[str, bytes] = '', exception: Optional[Exception] = None, content_type: str = 'application/json', payload: Optional[Dict] = None, headers: Optional[Dict] = None, response_class: Optional[Type[ClientResponse]] = None, repeat: bool = False, timeout: bool = False, reason: Optional[str] = None, callback: Optional[Callable] = None) None [source]¶
- assert_any_call(url: Union[URL, str, Pattern], method: str = 'GET', *args: Any, **kwargs: Any)[source]¶
assert the mock has been called with the specified arguments. The assert passes if the mock has ever been called, unlike assert_called_with and assert_called_once_with that only pass if the call is the most recent one.
- assert_called_once_with(*args: Any, **kwargs: Any)[source]¶
assert that the mock was called once with the specified arguments. Raises an AssertionError if the args and keyword args passed in are different to the only call to the mock.
- assert_called_with(url: Union[URL, str, Pattern], method: str = 'GET', *args: Any, **kwargs: Any)[source]¶
assert that the last call was made with the specified arguments.
Raises an AssertionError if the args and keyword args passed in are different to the last call to the mock.
- async match(method: str, url: URL, allow_redirects: bool = True, **kwargs: Any) Optional[ClientResponse] [source]¶
- requests: Dict = None¶