Skip to content

Commit 327e424

Browse files
committed
Add http_client utils test
1 parent dc5acd9 commit 327e424

File tree

4 files changed

+23
-34
lines changed

4 files changed

+23
-34
lines changed

test/components/embedders/test_azure_document_embedder.py

-12
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,6 @@ def test_init_http_client(self, monkeypatch):
231231
client = init_http_client(embedder.http_client_kwargs, async_client=True)
232232
assert isinstance(client, httpx.AsyncClient)
233233

234-
def test_http_client_kwargs_type_validation(self, monkeypatch):
235-
monkeypatch.setenv("AZURE_OPENAI_API_KEY", "fake-api-key")
236-
monkeypatch.setenv("AZURE_OPENAI_ENDPOINT", "https://test.openai.azure.com")
237-
with pytest.raises(TypeError, match="The parameter 'http_client_kwargs' must be a dictionary."):
238-
AzureOpenAIDocumentEmbedder(http_client_kwargs="invalid_argument")
239-
240-
def test_http_client_kwargs_with_invalid_params(self, monkeypatch):
241-
monkeypatch.setenv("AZURE_OPENAI_API_KEY", "fake-api-key")
242-
monkeypatch.setenv("AZURE_OPENAI_ENDPOINT", "https://test.openai.azure.com")
243-
with pytest.raises(TypeError, match="unexpected keyword argument"):
244-
AzureOpenAIDocumentEmbedder(http_client_kwargs={"invalid_key": "invalid_value"})
245-
246234
@pytest.mark.integration
247235
@pytest.mark.skipif(
248236
not os.environ.get("AZURE_OPENAI_API_KEY", None) and not os.environ.get("AZURE_OPENAI_ENDPOINT", None),

test/components/embedders/test_azure_text_embedder.py

-12
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,6 @@ def test_init_http_client(self, monkeypatch):
185185
client = init_http_client(embedder.http_client_kwargs, async_client=True)
186186
assert isinstance(client, httpx.AsyncClient)
187187

188-
def test_http_client_kwargs_type_validation(self, monkeypatch):
189-
monkeypatch.setenv("AZURE_OPENAI_API_KEY", "fake-api-key")
190-
monkeypatch.setenv("AZURE_OPENAI_ENDPOINT", "https://test.openai.azure.com")
191-
with pytest.raises(TypeError, match="The parameter 'http_client_kwargs' must be a dictionary."):
192-
AzureOpenAITextEmbedder(http_client_kwargs="invalid_argument")
193-
194-
def test_http_client_kwargs_with_invalid_params(self, monkeypatch):
195-
monkeypatch.setenv("AZURE_OPENAI_API_KEY", "fake-api-key")
196-
monkeypatch.setenv("AZURE_OPENAI_ENDPOINT", "https://test.openai.azure.com")
197-
with pytest.raises(TypeError, match="unexpected keyword argument"):
198-
AzureOpenAITextEmbedder(http_client_kwargs={"invalid_key": "invalid_value"})
199-
200188
@pytest.mark.integration
201189
@pytest.mark.skipif(
202190
not os.environ.get("AZURE_OPENAI_API_KEY", None) and not os.environ.get("AZURE_OPENAI_ENDPOINT", None),

test/components/generators/chat/test_openai.py

-10
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,6 @@ def test_from_dict_fail_wo_env_var(self, monkeypatch):
288288
with pytest.raises(ValueError):
289289
OpenAIChatGenerator.from_dict(data)
290290

291-
def test_http_client_kwargs_type_validation(self, monkeypatch):
292-
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
293-
with pytest.raises(TypeError, match="The parameter 'http_client_kwargs' must be a dictionary."):
294-
OpenAIChatGenerator(http_client_kwargs="invalid_argument")
295-
296-
def test_http_client_kwargs_with_invalid_params(self, monkeypatch):
297-
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
298-
with pytest.raises(TypeError, match="unexpected keyword argument"):
299-
OpenAIChatGenerator(http_client_kwargs={"invalid_key": "invalid_value"})
300-
301291
def test_run(self, chat_messages, openai_mock_chat_completion):
302292
component = OpenAIChatGenerator(api_key=Secret.from_token("test-api-key"))
303293
response = component.run(chat_messages)

test/utils/test_http_client.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
6+
import pytest
7+
from haystack.utils.http_client import init_http_client
8+
9+
10+
def test_init_http_client():
11+
http_client = init_http_client(http_client_kwargs={"base_url": "https://example.com"})
12+
assert http_client is not None
13+
assert http_client.base_url == "https://example.com"
14+
15+
16+
def test_http_client_kwargs_type_validation():
17+
with pytest.raises(TypeError, match="The parameter 'http_client_kwargs' must be a dictionary."):
18+
init_http_client(http_client_kwargs="invalid")
19+
20+
21+
def test_http_client_kwargs_with_invalid_params():
22+
with pytest.raises(TypeError, match="unexpected keyword argument"):
23+
init_http_client(http_client_kwargs={"invalid_key": "invalid"})

0 commit comments

Comments
 (0)