Skip to content

Proposal: implement aioresponses.assert_has_calls #253

@KeNaCo

Description

@KeNaCo

First, thank you for your effort in maintaining the library.

Context

I would like to assert, that a series of requests happen in a particular order. With current API it's not possible to do such assertion. So I propose to extend aioresponses with the assert_has_calls(calls) method.

Problem

In my case, I need to assert that various URLs are called (multiple times each) in a particular order.
aioresponses currently doesn't provide any method that can help. The class has the public attribute aioresponses.requests,
but it's implemented as a dict, and the exact call order cannot be determined.

Solution

I propose the implementation of aioresponses.assert_has_calls(calls, any_order=False) method, that behaves similarly to the standard Mock implementation.
I would suggest that the method will accept unittest.mock.call objects, but dedicated request(...) object is an option.

Example of use:

calls = [
    call("http://domian.com/"),
    call("http://domain.com/", method="GET"),
    call("http://domain.com/", params={"a":1, "b":2}),
    call(URL("http://domain.com/")),
]
aioresponses.assert_has_calls(calls)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions