-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_unit.py
More file actions
169 lines (132 loc) · 6.91 KB
/
Copy pathtest_unit.py
File metadata and controls
169 lines (132 loc) · 6.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"""Tests for UiPathGoogle client initialization and API config."""
from unittest.mock import MagicMock, PropertyMock, patch
import httpx
from uipath.llm_client.settings import UiPathAPIConfig
from uipath.llm_client.settings.constants import ApiFlavor, ApiType, RoutingMode, VendorType
# ============================================================================
# Test Google API Config
# ============================================================================
class TestBuildApiConfig:
"""Tests for the API config built inside UiPathGoogle.__init__."""
def test_default_api_config_fields(self):
"""The api_config created in __init__ has the expected constant values."""
api_config = UiPathAPIConfig(
api_type=ApiType.COMPLETIONS,
routing_mode=RoutingMode.PASSTHROUGH,
vendor_type=VendorType.VERTEXAI,
api_flavor=ApiFlavor.GENERATE_CONTENT,
api_version="v1beta1",
freeze_base_url=True,
)
assert api_config.api_type == "completions"
assert api_config.routing_mode == "passthrough"
assert api_config.vendor_type == "vertexai"
assert api_config.api_flavor == "generate-content"
assert api_config.api_version == "v1beta1"
assert api_config.freeze_base_url is True
# ============================================================================
# Test UiPathGoogle Initialization
# ============================================================================
def _make_mock_sync_client():
"""Create a mock sync httpx client that passes pydantic validation."""
client = MagicMock(spec=httpx.Client)
type(client).base_url = PropertyMock(return_value=httpx.URL("https://example.com/base"))
client.headers = httpx.Headers({"Authorization": "Bearer tok"})
return client
def _make_mock_async_client():
"""Create a mock async httpx client that passes pydantic validation."""
return MagicMock(spec=httpx.AsyncClient)
class TestUiPathGoogleInit:
"""Tests for UiPathGoogle client construction with mocked dependencies."""
@patch("uipath.llm_client.clients.google.client.build_httpx_async_client")
@patch("uipath.llm_client.clients.google.client.build_httpx_client")
@patch("uipath.llm_client.clients.google.client.get_default_client_settings")
def test_placeholder_api_key(
self,
mock_get_settings,
mock_build_sync,
mock_build_async,
):
"""UiPathGoogle passes api_key='PLACEHOLDER' to the parent Client."""
from google.genai.client import Client
mock_settings = MagicMock()
mock_get_settings.return_value = mock_settings
mock_build_sync.return_value = _make_mock_sync_client()
mock_build_async.return_value = _make_mock_async_client()
with patch.object(Client, "__init__", return_value=None) as mock_init:
from uipath.llm_client.clients.google.client import UiPathGoogle
UiPathGoogle(model_name="gemini-2.5-flash")
mock_init.assert_called_once()
call_kwargs = mock_init.call_args[1]
assert call_kwargs["api_key"] == "PLACEHOLDER"
@patch("uipath.llm_client.clients.google.client.build_httpx_async_client")
@patch("uipath.llm_client.clients.google.client.build_httpx_client")
@patch("uipath.llm_client.clients.google.client.get_default_client_settings")
def test_httpx_clients_passed_via_http_options(
self,
mock_get_settings,
mock_build_sync,
mock_build_async,
):
"""UiPathGoogle passes both httpx clients into HttpOptions."""
from google.genai.client import Client
mock_settings = MagicMock()
mock_get_settings.return_value = mock_settings
sync_client = _make_mock_sync_client()
async_client = _make_mock_async_client()
mock_build_sync.return_value = sync_client
mock_build_async.return_value = async_client
with patch.object(Client, "__init__", return_value=None) as mock_init:
from uipath.llm_client.clients.google.client import UiPathGoogle
UiPathGoogle(model_name="gemini-2.5-flash")
call_kwargs = mock_init.call_args[1]
http_options = call_kwargs["http_options"]
assert http_options.httpx_client is sync_client
assert http_options.httpx_async_client is async_client
assert str(http_options.base_url) == "https://example.com/base"
assert http_options.retry_options is None
@patch("uipath.llm_client.clients.google.client.build_httpx_async_client")
@patch("uipath.llm_client.clients.google.client.build_httpx_client")
@patch("uipath.llm_client.clients.google.client.get_default_client_settings")
def test_uses_provided_client_settings(
self,
mock_get_settings,
mock_build_sync,
mock_build_async,
):
"""When client_settings is provided, get_default_client_settings is not called."""
from google.genai.client import Client
custom_settings = MagicMock()
mock_build_sync.return_value = _make_mock_sync_client()
mock_build_async.return_value = _make_mock_async_client()
with patch.object(Client, "__init__", return_value=None):
from uipath.llm_client.clients.google.client import UiPathGoogle
UiPathGoogle(model_name="gemini-2.5-flash", client_settings=custom_settings)
mock_get_settings.assert_not_called()
assert mock_build_sync.call_args[1]["client_settings"] is custom_settings
assert mock_build_async.call_args[1]["client_settings"] is custom_settings
@patch("uipath.llm_client.clients.google.client.build_httpx_async_client")
@patch("uipath.llm_client.clients.google.client.build_httpx_client")
@patch("uipath.llm_client.clients.google.client.get_default_client_settings")
def test_api_config_forwarded_to_builders(
self,
mock_get_settings,
mock_build_sync,
mock_build_async,
):
"""The internally-built api_config is forwarded to both httpx client builders."""
from google.genai.client import Client
mock_get_settings.return_value = MagicMock()
mock_build_sync.return_value = _make_mock_sync_client()
mock_build_async.return_value = _make_mock_async_client()
with patch.object(Client, "__init__", return_value=None):
from uipath.llm_client.clients.google.client import UiPathGoogle
UiPathGoogle(model_name="gemini-2.5-flash")
sync_config = mock_build_sync.call_args[1]["api_config"]
async_config = mock_build_async.call_args[1]["api_config"]
for cfg in (sync_config, async_config):
assert cfg.api_type == "completions"
assert cfg.routing_mode == "passthrough"
assert cfg.vendor_type == "vertexai"
assert cfg.api_flavor == "generate-content"
assert cfg.freeze_base_url is True