How to use the respx.stats 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_mock.py View on Github external
def test(respx_mock):
        assert respx.stats.call_count == 0
        request = respx_mock.get("https://foo.bar/", status_code=202)
        response = httpx.get("https://foo.bar/")
        assert request.called is True
        assert response.status_code == 202
        assert respx.stats.call_count == 0
        assert respx_mock.stats.call_count == 1
github lundberg / respx / tests / test_mock.py View on Github external
async def test_decorating_test(client):
    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
github lundberg / respx / tests / test_api.py View on Github external
async def test_parallel_requests(client):
    async def content(request, page):
        await asyncio.sleep(0.2 if page == "one" else 0.1)
        return page

    url_pattern = re.compile(r"https://foo/(?P\w+)/$")
    respx.get(url_pattern, content=content)

    responses = await asyncio.gather(
        client.get("https://foo/one/"), client.get("https://foo/two/")
    )
    response_one, response_two = responses

    assert response_one.text == "one"
    assert response_two.text == "two"
    assert respx.stats.call_count == 2
github lundberg / respx / tests / test_stats.py View on Github external
assert _response.status_code == 202
        assert _response.status_code == get_response.status_code
        assert _response.content == get_response.content
        assert id(_response) == id(get_response)

        _request, _response = foobar2.calls[-1]
        assert isinstance(_request, httpx.Request)
        assert isinstance(_response, httpx.Response)
        assert _request.method == "DELETE"
        assert _request.url == url
        assert _response.status_code == 200
        assert _response.status_code == del_response.status_code
        assert _response.content == del_response.content
        assert id(_response) == id(del_response)

        assert respx.stats.call_count == 2
        assert respx.calls[0] == foobar1.calls[-1]
        assert respx.calls[1] == foobar2.calls[-1]

        alias = respx.aliases["get_foobar"]
        assert alias == foobar1
        assert alias.alias == foobar1.alias

        alias = respx.aliases["del_foobar"]
        assert alias == foobar2
        assert alias.alias == foobar2.alias