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
real_url: URL
real_url_default() URL[source]
url: URL
class aioresponses.compat.URL(val='', *, encoded=False, strict=None)

Bases: object

authority[source]

Decoded authority part of URL.

Empty string for relative URLs.

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.

fragment[source]

Decoded fragment part of URL.

Empty string if fragment is missing.

host[source]

Decoded host part of URL.

None for relative URLs.

human_repr()[source]

Return decoded human readable string for URL representation.

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.

name[source]

The last part of parts.

origin()[source]

Return an URL with scheme, host and port parts only.

user, password, path, query and fragment are removed.

parent[source]

A new URL with last part of path removed and cleaned up query and fragment.

parts[source]

A tuple containing decoded path parts.

(‘/’,) for absolute URLs if path is missing.

password[source]

Decoded password part of URL.

None if password is missing.

path[source]

Decoded path of URL.

/ for absolute URLs without path part.

path_qs[source]

Decoded path of URL with query.

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.

query_string[source]

Decoded query part of URL.

Empty string if query is missing.

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_name[source]

The last part of raw_parts.

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.

raw_path_qs[source]

Encoded path of URL with query.

property raw_query_string

Encoded query part of URL.

Empty string if query is missing.

raw_suffix[source]
raw_suffixes[source]
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 //

suffix[source]
suffixes[source]
update_query(*args, **kwargs)[source]

Return a new URL with query part updated.

user[source]

Decoded user part of URL.

None if user is missing.

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_path(path, *, encoded=False)[source]

Return a new URL with path replaced.

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.

with_scheme(scheme)[source]

Return a new URL with scheme replaced.

with_suffix(suffix)[source]

Return a new URL with suffix (file extension of name) replaced.

Query and fragment parts are cleaned up.

suffix is encoded if needed.

with_user(user)[source]

Return a new URL with user replaced.

Autoencode user if needed.

Clear user/password if user is None.

aioresponses.compat.merge_params(url: Union[URL, str], params: Optional[Dict] = None) URL[source]
aioresponses.compat.normalize_url(url: Union[URL, str]) URL[source]

Normalize url to make comparisons.

aioresponses.compat.stream_reader_factory(loop: Optional[AbstractEventLoop] = None)[source]

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

async build_response(url: URL, **kwargs: Any) Union[ClientResponse, Exception][source]
match(method: str, url: URL) bool[source]
match_regexp(url: URL) bool[source]
match_str(url: URL) bool[source]
url_or_pattern: Union[URL, Pattern] = None
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()[source]

assert that the mock was called at least once.

assert_called_once()[source]

assert that the mock was called only once.

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.

assert_not_called()[source]

assert that the mock was never called.

clear() None[source]
delete(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
get(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
head(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
static is_exception(resp_or_exc: Union[ClientResponse, Exception]) bool[source]
async match(method: str, url: URL, allow_redirects: bool = True, **kwargs: Any) Optional[ClientResponse][source]
options(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
patch(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
post(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
put(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
requests: Dict = None
start() None[source]
stop() None[source]

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()[source]

assert that the mock was called at least once.

assert_called_once()[source]

assert that the mock was called only once.

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.

assert_not_called()[source]

assert that the mock was never called.

clear() None[source]
delete(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
get(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
head(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
static is_exception(resp_or_exc: Union[ClientResponse, Exception]) bool[source]
async match(method: str, url: URL, allow_redirects: bool = True, **kwargs: Any) Optional[ClientResponse][source]
options(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
patch(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
post(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
put(url: Union[URL, str, Pattern], **kwargs: Any) None[source]
requests: Dict = None
start() None[source]
stop() None[source]