1
1
import json
2
2
import os
3
3
import sys
4
- from unittest .mock import AsyncMock , MagicMock , patch
4
+ from unittest .mock import MagicMock , patch
5
5
6
6
import httpx
7
7
import pytest
@@ -51,9 +51,12 @@ async def test_vertex_ai_gpt_oss_simple_request():
51
51
with the correct request body.
52
52
"""
53
53
from litellm .llms .custom_httpx .http_handler import AsyncHTTPHandler
54
+ from litellm .llms .vertex_ai .gemini .vertex_and_google_ai_studio_gemini import (
55
+ VertexLLM ,
56
+ )
54
57
55
58
# Mock response
56
- mock_response = AsyncMock ()
59
+ mock_response = MagicMock ()
57
60
mock_response .status_code = 200
58
61
mock_response .headers = {}
59
62
mock_response .json .return_value = {
@@ -80,7 +83,11 @@ async def test_vertex_ai_gpt_oss_simple_request():
80
83
81
84
client = AsyncHTTPHandler ()
82
85
83
- with patch .object (client , "post" , return_value = mock_response ) as mock_post :
86
+ async def mock_post_func (* args , ** kwargs ):
87
+ return mock_response
88
+
89
+ with patch .object (client , "post" , side_effect = mock_post_func ) as mock_post , \
90
+ patch .object (VertexLLM , "_ensure_access_token" , return_value = ("fake-token" , "pathrise-convert-1606954137718" )):
84
91
response = await litellm .acompletion (
85
92
model = "vertex_ai/openai/gpt-oss-20b-maas" ,
86
93
messages = [
@@ -103,7 +110,8 @@ async def test_vertex_ai_gpt_oss_simple_request():
103
110
104
111
# Get the call arguments
105
112
call_args = mock_post .call_args
106
- called_url = call_args [0 ][0 ] # First positional argument is the URL
113
+ # For side_effect, the URL is passed as kwargs['url']
114
+ called_url = call_args .kwargs ["url" ]
107
115
request_body = json .loads (call_args .kwargs ["data" ])
108
116
109
117
# Verify the URL
@@ -128,7 +136,7 @@ async def test_vertex_ai_gpt_oss_simple_request():
128
136
assert request_body == expected_request_body
129
137
130
138
# Verify response structure
131
- assert response .model == "vertex_ai/ openai/gpt-oss-20b-maas"
139
+ assert response .model == "openai/gpt-oss-20b-maas"
132
140
assert len (response .choices ) == 1
133
141
assert response .choices [0 ].message .role == "assistant"
134
142
@@ -140,9 +148,12 @@ async def test_vertex_ai_gpt_oss_reasoning_effort():
140
148
for GPT-OSS models.
141
149
"""
142
150
from litellm .llms .custom_httpx .http_handler import AsyncHTTPHandler
151
+ from litellm .llms .vertex_ai .gemini .vertex_and_google_ai_studio_gemini import (
152
+ VertexLLM ,
153
+ )
143
154
144
155
# Mock response
145
- mock_response = AsyncMock ()
156
+ mock_response = MagicMock ()
146
157
mock_response .status_code = 200
147
158
mock_response .headers = {}
148
159
mock_response .json .return_value = {
@@ -169,7 +180,11 @@ async def test_vertex_ai_gpt_oss_reasoning_effort():
169
180
170
181
client = AsyncHTTPHandler ()
171
182
172
- with patch .object (client , "post" , return_value = mock_response ) as mock_post :
183
+ async def mock_post_func (* args , ** kwargs ):
184
+ return mock_response
185
+
186
+ with patch .object (client , "post" , side_effect = mock_post_func ) as mock_post , \
187
+ patch .object (VertexLLM , "_ensure_access_token" , return_value = ("fake-token" , "pathrise-convert-1606954137718" )):
173
188
response = await litellm .acompletion (
174
189
model = "vertex_ai/openai/gpt-oss-20b-maas" ,
175
190
messages = [
@@ -218,6 +233,6 @@ async def test_vertex_ai_gpt_oss_reasoning_effort():
218
233
assert request_body == expected_request_body
219
234
220
235
# Verify response structure
221
- assert response .model == "vertex_ai/ openai/gpt-oss-20b-maas"
236
+ assert response .model == "openai/gpt-oss-20b-maas"
222
237
assert len (response .choices ) == 1
223
238
assert response .choices [0 ].message .role == "assistant"
0 commit comments