How to use respx - 10 common examples

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
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_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
github lundberg / respx / tests / test_mock.py View on Github external
def test():
        assert respx.stats.call_count == 0
        request = respx.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 == 1
github lundberg / respx / tests / test_mock.py View on Github external
    @respx.mock(assert_all_called=False, assert_all_mocked=False)
    async def test(respx_mock):
        assert respx_mock.stats.call_count == 0
        request = respx_mock.get("https://foo.bar/")
        response = await client.get("https://some.thing/")

        assert response.status_code == 200
        assert response.headers == httpx.Headers({"Content-Type": "text/plain"})
        assert response.text == ""

        assert request.called is False
        assert respx.stats.call_count == 0
        assert respx_mock.stats.call_count == 1

        _request, _response = respx_mock.calls[-1]
        assert _request is not None
        assert _response is not None
github lundberg / respx / tests / test_mock.py View on Github external
    @respx.mock
    def test():
        assert respx.stats.call_count == 0
        request = respx.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 == 1
github lundberg / respx / tests / test_stats.py View on Github external
    @respx.mock
    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)
github lundberg / respx / tests / test_mock.py View on Github external
    @respx.mock()
    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
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_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
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