c56bef871b
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
58 lines
2.1 KiB
Python
58 lines
2.1 KiB
Python
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from haystack.utils.http_client import init_http_client
|
|
|
|
|
|
def test_init_http_client():
|
|
# test without any params
|
|
http_client = init_http_client()
|
|
assert http_client is None
|
|
|
|
# test client is initialized with http_client_kwargs
|
|
client_kwargs = {"base_url": "https://example.com"}
|
|
http_client = init_http_client(http_client_kwargs=client_kwargs)
|
|
assert http_client is not None
|
|
assert isinstance(http_client, httpx.Client)
|
|
assert http_client.base_url == "https://example.com"
|
|
|
|
|
|
def test_init_http_client_async():
|
|
# test without any params
|
|
http_async_client = init_http_client(async_client=True)
|
|
assert http_async_client is None
|
|
|
|
# test async client is initialized with http_client_kwargs
|
|
http_async_client = init_http_client(http_client_kwargs={"base_url": "https://example.com"}, async_client=True)
|
|
assert http_async_client is not None
|
|
assert isinstance(http_async_client, httpx.AsyncClient)
|
|
assert http_async_client.base_url == "https://example.com"
|
|
|
|
|
|
def test_http_client_kwargs_type_validation():
|
|
# test http_client_kwargs is not a dictionary
|
|
with pytest.raises(TypeError, match="The parameter 'http_client_kwargs' must be a dictionary."):
|
|
init_http_client(http_client_kwargs="invalid") # type: ignore[call-overload]
|
|
|
|
|
|
def test_http_client_kwargs_with_invalid_params():
|
|
# test http_client_kwargs with invalid keys
|
|
with pytest.raises(TypeError, match="unexpected keyword argument"):
|
|
init_http_client(http_client_kwargs={"invalid_key": "invalid"})
|
|
|
|
|
|
def test_init_http_client_with_dict_limits():
|
|
"""Test that dict limits are converted to httpx.Limits objects without AttributeError."""
|
|
http_client_kwargs = {"limits": {"max_connections": 100, "max_keepalive_connections": 20}}
|
|
|
|
# This should not raise AttributeError: 'dict' object has no attribute 'max_connections'
|
|
client = init_http_client(http_client_kwargs=http_client_kwargs, async_client=False)
|
|
assert client is not None
|
|
assert isinstance(client, httpx.Client)
|
|
|
|
client.close()
|