Skip to content

Commit 44387b8

Browse files
speedstorm1copybara-github
authored andcommitted
test: Add replay test for EU multi-regional routing in GenAI SDK
PiperOrigin-RevId: 899117806
1 parent 91506ea commit 44387b8

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import os
17+
18+
import pytest
19+
20+
from ... import _replay_api_client
21+
from ... import Client
22+
from ...models import Models
23+
from .. import pytest_helper
24+
25+
26+
pytestmark = pytest_helper.setup(
27+
file=__file__,
28+
globals_for_file=globals(),
29+
test_method='models.generate_content',
30+
)
31+
32+
33+
def test_eu_location_routing_prediction_replay(client, request, monkeypatch):
34+
"""Tests that the SDK can route to the EU multi-regional endpoint."""
35+
if not client._api_client.vertexai:
36+
pytest.skip('Test requires Vertex AI')
37+
38+
mode = request.config.getoption('--mode')
39+
if mode == 'tap':
40+
mode = 'replay'
41+
42+
# The `client` fixture monkeypatches `Client._get_api_client` to always return
43+
# the fixture's client, which binds to `us-central1` via the environment.
44+
# To test `eu` routing, we bypass the mock by explicitly instantiating a
45+
# ReplayApiClient and injecting it.
46+
with monkeypatch.context() as m:
47+
m.delenv('GOOGLE_CLOUD_LOCATION', raising=False)
48+
49+
replay_api_client = _replay_api_client.ReplayApiClient(
50+
mode=mode,
51+
replay_id='tests/models/generate_content_multi_regional/test_eu_location_routing_prediction_replay.vertex',
52+
replays_directory=os.environ.get('GOOGLE_GENAI_REPLAYS_DIRECTORY'),
53+
vertexai=True,
54+
project=client._api_client.project,
55+
location='eu',
56+
)
57+
58+
eu_client = Client(vertexai=True)
59+
eu_client._api_client = replay_api_client
60+
eu_client._models = Models(replay_api_client)
61+
62+
try:
63+
# 1. Verify that the SDK correctly resolved the EU REP base URL internally
64+
assert (
65+
eu_client._api_client._http_options.base_url
66+
== 'https://aiplatform.eu.rep.googleapis.com/'
67+
)
68+
69+
# 2. Test the dataplane prediction (generate_content) against EU endpoint
70+
response = eu_client.models.generate_content(
71+
model='gemini-3-flash-preview',
72+
contents='Testing EU multi-regional endpoint routing.',
73+
)
74+
assert response is not None
75+
finally:
76+
eu_client.close()

0 commit comments

Comments
 (0)