Esempio n. 1
0
async def test_timeout():
    api = MockApi(
        iter([
            httpx.ConnectTimeout(),
            [{
                "update_id": 0,
                "message": "A"
            }],
            httpx.ReadTimeout(),
            httpx.WriteTimeout(),
            [{
                "update_id": 1,
                "message": "B"
            }],
        ]))
    updater = make_updater(api)

    updates = await updater.get_updates()
    assert len(updates) == 1
    assert updates[0]["message"] == "A"
    assert updater.offset == 1

    updates = await updater.get_updates()
    assert len(updates) == 1
    assert updates[0]["message"] == "B"
    assert updater.offset == 2
Esempio n. 2
0
async def test_raising_content(client):
    async with respx.HTTPXMock() as httpx_mock:
        url = "https://foo.bar/"
        request = httpx_mock.get(url, content=httpx.ConnectTimeout())
        with pytest.raises(httpx.ConnectTimeout):
            await client.get(url)

        assert request.called is True
        _request, _response = request.calls[-1]
        assert _request is not None
        assert _response is None
async def open_uds_socket_stream(
    path: str, hostname: str, timeout: httpx.Timeout, ssl_context: ssl.SSLContext = None
) -> BaseSocketStream:
    async_library = sniffio.current_async_library()
    assert async_library == "asyncio"

    server_hostname = hostname if ssl_context else None

    try:
        stream_reader, stream_writer = await asyncio.wait_for(
            asyncio.open_unix_connection(
                path, ssl=ssl_context, server_hostname=server_hostname
            ),
            timeout.connect_timeout,
        )
    except asyncio.TimeoutError:
        raise httpx.ConnectTimeout()

    return SocketStream(stream_reader=stream_reader, stream_writer=stream_writer)
Esempio n. 4
0
async def test_raising_content(client):
    async with MockRouter() as respx_mock:
        url = "https://foo.bar/"
        request = respx_mock.get(url)
        request.side_effect = httpx.ConnectTimeout("X-P", request=None)
        with pytest.raises(httpx.ConnectTimeout):
            await client.get(url)

        assert request.called is True
        _request, _response = request.calls[-1]
        assert _request is not None
        assert _response is None

        # Test httpx exception class get instantiated
        route = respx_mock.get(url).mock(side_effect=httpx.ConnectError)
        with pytest.raises(httpx.ConnectError):
            await client.get(url)

        assert route.call_count == 2
        assert route.calls.last.request is not None
        assert route.calls.last.response is None
Esempio n. 5
0
 async def effect(request):
     raise httpx.ConnectTimeout("X-P", request=request)
Esempio n. 6
0
 async def test_should_return_false_when_host_does_not_exist(
         self, httpx_mock, trio_analyzer):
     httpx_mock.get('/robots.txt', content=httpx.ConnectTimeout())
     assert await trio_analyzer.can_fetch('http://example.com/path'
                                          ) is False