How to use the respx.stats.call_count function in respx

To help you get started, we’ve selected a few respx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lundberg / respx / tests / test_stats.py View on Github external
async def test(backend):
        url = "https://foo.bar/1/"
        respx.get(re.compile("https://some.thing"))
        respx.delete("https://some.thing")

        foobar1 = respx.get(url, status_code=202, alias="get_foobar")
        foobar2 = respx.delete(url, status_code=200, alias="del_foobar")

        assert foobar1.called is False
        assert foobar1.call_count == len(foobar1.calls)
        assert foobar1.call_count == 0
        assert respx.stats.call_count == len(respx.calls)
        assert respx.stats.call_count == 0

        async with httpx.AsyncClient() as client:
            get_response = await client.get(url)
            del_response = await client.delete(url)

        assert foobar1.called is True
        assert foobar2.called is True
        assert foobar1.call_count == 1
        assert foobar2.call_count == 1

        _request, _response = foobar1.calls[-1]
        assert isinstance(_request, httpx.Request)
        assert isinstance(_response, httpx.Response)
        assert _request.method == "GET"
        assert _request.url == url
        assert _response.status_code == 202
github lundberg / respx / tests / test_api.py View on Github external
assert response.status_code == 204
        response = await client.delete(url)
        assert response.status_code == 204

        response = httpx.head(url)
        assert response.status_code == 405
        response = await client.head(url)
        assert response.status_code == 405

        response = httpx.options(url)
        assert response.status_code == 501
        response = await client.options(url)
        assert response.status_code == 501

        assert m.called is True
        assert respx.stats.call_count == 7 * 2
github lundberg / respx / tests / test_mock.py View on Github external
async def test_global_contextmanager(client):
    with respx.mock:
        assert respx.stats.call_count == 0
        request = respx.get("https://foo/bar/", status_code=202)
        response = await client.get("https://foo/bar/")
        assert request.called is True
        assert response.status_code == 202
        assert respx.stats.call_count == 1

    async with respx.mock:
        assert respx.stats.call_count == 0
        request = respx.get("https://foo/bar/", status_code=202)
        response = await client.get("https://foo/bar/")
        assert request.called is True
        assert response.status_code == 202
        assert respx.stats.call_count == 1

    assert respx.stats.call_count == 0