Beispiel #1
0
def test_sync_transport():
    url = "https://foo.bar/"

    router = Router(assert_all_called=False)
    router.get(url) % 404
    router.post(url).pass_through()
    router.put(url)
    transport = MockTransport(handler=router.handler)

    with httpx.Client(transport=transport) as client:
        response = client.get(url)
        assert response.status_code == 404
        with pytest.raises(PassThrough):
            client.post(url)
Beispiel #2
0
async def test_async_transport_handler():
    url = "https://foo.bar/"

    router = Router(assert_all_called=False)
    router.get(url) % 404
    router.post(url).pass_through()
    router.put(url)

    with warnings.catch_warnings(record=True) as w:
        transport = MockTransport(async_handler=router.async_handler)
        assert len(w) == 1

    async with httpx.AsyncClient(transport=transport) as client:
        response = await client.get(url)
        assert response.status_code == 404
        with pytest.raises(PassThrough):
            await client.post(url)