Skip to content
Myr

test_concurrency.py

This file

Path

tests/test_concurrency.py

38 lines · 1.2 KiB · Python

Last changed by

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

History of this file

Take it

1import sys23import pytest45from httpx import AsyncioBackend, HTTPVersionConfig, SSLConfig, TimeoutConfig678@pytest.mark.xfail(9    sys.version_info < (3, 7),10    reason="Requires Python 3.7+ for AbstractEventLoop.start_tls()",11)12@pytest.mark.asyncio13async def test_start_tls_on_socket_stream(https_server):14    """15    See that the backend can make a connection without TLS then16    start TLS on an existing connection.17    """18    backend = AsyncioBackend()19    ctx = SSLConfig().load_ssl_context_no_verify(HTTPVersionConfig())20    timeout = TimeoutConfig(5)2122    stream = await backend.connect(23        https_server.url.host, https_server.url.port, None, timeout24    )2526    try:27        assert stream.is_connection_dropped() is False28        assert stream.stream_writer.get_extra_info("cipher", default=None) is None2930        stream = await backend.start_tls(stream, https_server.url.host, ctx, timeout)31        assert stream.is_connection_dropped() is False32        assert stream.stream_writer.get_extra_info("cipher", default=None) is not None3334        await stream.write(b"GET / HTTP/1.1\r\n\r\n")35        assert (await stream.read(8192, timeout)).startswith(b"HTTP/1.1 200 OK\r\n")3637    finally:38        await stream.close()