Exemplo n.º 1
0
async def test_httpx_debug_enabled_stderr_logging(server, capsys, httpx_debug):
    os.environ["HTTPX_DEBUG"] = httpx_debug

    # Force a reload on the logging handlers
    utils._LOGGER_INITIALIZED = False
    utils.get_logger("httpx")

    async with httpx.AsyncClient() as client:
        await client.get(server.url)

    if httpx_debug in ("1", "True"):
        assert "httpx.dispatch.connection_pool" in capsys.readouterr().err
    else:
        assert "httpx.dispatch.connection_pool" not in capsys.readouterr().err

    # Reset the logger so we don't have verbose output in all unit tests
    logging.getLogger("httpx").handlers = []
Exemplo n.º 2
0
import typing

from httpx import AsyncClient
from httpx.concurrency.asyncio import AsyncioBackend
from httpx.concurrency.base import ConcurrencyBackend
from httpx.config import CertTypes, TimeoutTypes, VerifyTypes
from httpx.models import AsyncRequest, AsyncResponse
from httpx.utils import MessageLoggerASGIMiddleware, get_logger
from httpx.dispatch.base import AsyncDispatcher
from base64 import b64encode
import json
import itsdangerous

logger = get_logger(__name__)


class TestClient(AsyncClient):
    __test__ = False

    def __init__(self, app, raise_server_exceptions=True):
        from source.settings import SECRET

        dispatch = ASGIDispatch(app=app,
                                raise_app_exceptions=raise_server_exceptions)
        self.signer = itsdangerous.TimestampSigner(SECRET)
        super().__init__(
            base_url="https://testserver",
            dispatch=dispatch,
            headers={"accept": "text/html; */*"},
        )