Skip to content

Commit 2d9f22f

Browse files
committed
Use new build_nat_client helper method
Signed-off-by: David Gardner <[email protected]>
1 parent 7456a3a commit 2d9f22f

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

tests/nat/front_ends/fastapi/test_openai_compatibility.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
from contextlib import asynccontextmanager
17-
1816
import pytest
19-
from asgi_lifespan import LifespanManager
20-
from httpx import ASGITransport
21-
from httpx import AsyncClient
2217
from httpx_sse import aconnect_sse
2318

2419
from nat.data_models.api_server import ChatRequest
@@ -31,20 +26,9 @@
3126
from nat.data_models.config import Config
3227
from nat.data_models.config import GeneralConfig
3328
from nat.front_ends.fastapi.fastapi_front_end_config import FastApiFrontEndConfig
34-
from nat.front_ends.fastapi.fastapi_front_end_plugin_worker import FastApiFrontEndPluginWorker
3529
from nat.test.functions import EchoFunctionConfig
3630
from nat.test.functions import StreamingEchoFunctionConfig
37-
38-
39-
@asynccontextmanager
40-
async def _build_client(config: Config, worker_class: type[FastApiFrontEndPluginWorker] = FastApiFrontEndPluginWorker):
41-
"""Helper to build test client with proper lifecycle management"""
42-
worker = worker_class(config)
43-
app = worker.build_app()
44-
45-
async with LifespanManager(app):
46-
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
47-
yield client
31+
from nat.test.utils import build_nat_client
4832

4933

5034
def test_fastapi_config_openai_api_v1_path_field():
@@ -198,7 +182,7 @@ async def test_legacy_vs_openai_v1_mode_endpoints(openai_api_v1_path: str | None
198182
workflow=EchoFunctionConfig(use_openai_api=True),
199183
)
200184

201-
async with _build_client(config) as client:
185+
async with build_nat_client(config) as client:
202186
base_path = "/v1/chat/completions"
203187

204188
if openai_api_v1_path:
@@ -273,7 +257,7 @@ async def test_openai_compatible_mode_stream_parameter():
273257
workflow=StreamingEchoFunctionConfig(use_openai_api=True),
274258
)
275259

276-
async with _build_client(config) as client:
260+
async with build_nat_client(config) as client:
277261
base_path = "/v1/chat/completions"
278262

279263
# Test stream=true (should return streaming response)
@@ -311,7 +295,7 @@ async def test_legacy_non_streaming_response_format():
311295
workflow=EchoFunctionConfig(use_openai_api=True),
312296
)
313297

314-
async with _build_client(config) as client:
298+
async with build_nat_client(config) as client:
315299
# Send request to legacy OpenAI endpoint
316300
response = await client.post("/chat",
317301
json={
@@ -386,7 +370,7 @@ async def test_legacy_streaming_response_format():
386370
workflow=StreamingEchoFunctionConfig(use_openai_api=True),
387371
)
388372

389-
async with _build_client(config) as client:
373+
async with build_nat_client(config) as client:
390374
async with aconnect_sse(client,
391375
"POST",
392376
"/chat/stream",
@@ -454,7 +438,7 @@ async def test_openai_compatible_non_streaming_response_format():
454438
workflow=EchoFunctionConfig(use_openai_api=True),
455439
)
456440

457-
async with _build_client(config) as client:
441+
async with build_nat_client(config) as client:
458442
# Send request to actual OpenAI endpoint - this will trigger generate_single_response
459443
response = await client.post("/v1/chat/completions",
460444
json={
@@ -530,7 +514,7 @@ async def test_openai_compatible_streaming_response_format():
530514
workflow=StreamingEchoFunctionConfig(use_openai_api=True),
531515
)
532516

533-
async with _build_client(config) as client:
517+
async with build_nat_client(config) as client:
534518
async with aconnect_sse(client,
535519
"POST",
536520
"/v1/chat/completions",

0 commit comments

Comments
 (0)