haystack/test/utils/test_http_client.py
Sebastian Husch Lee 85258f0654
fix: Fix types and formatting pipeline test_run.py (#9575)
* Fix types in test_run.py

* Get test_run.py to pass fmt-check

* Add test_run to mypy checks

* Update test folder to pass ruff linting

* Fix merge

* Fix HF tests

* Fix hf test

* Try to fix tests

* Another attempt

* minor fix

* fix SentenceTransformersDiversityRanker

* skip integrations tests due to model unavailable on HF inference

---------

Co-authored-by: anakin87 <stefanofiorucci@gmail.com>
2025-07-03 09:49:09 +02:00

45 lines
1.6 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
http_client = init_http_client(http_client_kwargs={"base_url": "https://example.com"})
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")
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"})