first vommit

This commit is contained in:
Till-Immer committed 2026-07-04 14:31:50 +02:00
commit a04e68bc95
4926 files changed
+764440

No files matched your search

@@ -0,0 +1,17 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for the Google GenAI SDK's caches module."""
@@ -0,0 +1,29 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Constants for caches tests."""
CACHED_CONTENT_NAME_MLDEV = 'cachedContents/o239k1gxzz0juy9wqstndhncr85krehehf551hqh'
CACHED_CONTENT_NAME_VERTEX = 'cachedContents/2164089915711684608'
VERTEX_HTTP_OPTIONS = {
'api_version': 'v1beta1',
'base_url': 'https://us-central1-aiplatform.googleapis.com/',
}
MLDEV_HTTP_OPTIONS = {
'api_version': 'v1beta',
'base_url': 'https://generativelanguage.googleapis.com/',
}
@@ -0,0 +1,210 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from copy import deepcopy
import datetime
import pytest
import sys
from ... import types
from .. import pytest_helper
from ... import _transformers as t
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI = types._CreateCachedContentParameters(
model='gemini-2.5-flash',
config={
'contents': [
types.Content(
role='user',
parts=[
types.Part(
fileData=types.FileData(
fileUri='gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf',
mimeType='application/pdf',
)
),
types.Part(
fileData=types.FileData(
fileUri='gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf',
mimeType='application/pdf',
)
),
],
)
],
'system_instruction': t.t_content('What is the sum of the two pdfs?'),
'display_name': 'test cache',
'ttl': '86400s',
},
)
_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE = types._CreateCachedContentParameters(
model='gemini-2.5-flash',
config={
'contents': [
types.Content(
role='user',
parts=[
types.Part(
fileData=types.FileData(
mimeType='application/pdf',
fileUri='https://generativelanguage.googleapis.com/v1beta/files/v200dhvn15h7',
)
)
],
)
],
'system_instruction': t.t_content('What is the sum of the two pdfs?'),
'display_name': 'test cache',
'ttl': '86400s',
},
)
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_PARTIAL_MODEL_1 = deepcopy(
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI
)
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_PARTIAL_MODEL_1.model = (
'models/gemini-2.5-flash'
)
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_PARTIAL_MODEL_2 = deepcopy(
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI
)
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_PARTIAL_MODEL_2.model = (
'publishers/google/models/gemini-2.5-flash'
)
_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE_PARTIAL_MODEL_1 = deepcopy(
_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE
)
_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE_PARTIAL_MODEL_1.model = (
'models/gemini-2.5-flash'
)
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_CMEK = deepcopy(
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI
)
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_CMEK.config.kms_key_name = (
'projects/test-project/locations/us-central1/keyRings/test-keyring/cryptoKeys/test-key'
)
if sys.version_info >= (3, 11):
_EXPIRE_TIME = datetime.datetime.fromisoformat('2025-12-20T00:00:00Z')
else:
_EXPIRE_TIME = datetime.datetime.fromisoformat('2025-12-20T00:00:00+00:00')
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_EXPIRE_TIME = deepcopy(
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI
)
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_EXPIRE_TIME.config.ttl = None
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_EXPIRE_TIME.config.expire_time = (
_EXPIRE_TIME
)
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_EXPIRE_TIME.config.display_name = (
'test cache'
)
_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE_EXPIRE_TIME = deepcopy(
_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE
)
_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE_EXPIRE_TIME.config.ttl = None
_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE_EXPIRE_TIME.config.expire_time = (
_EXPIRE_TIME
)
_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE_EXPIRE_TIME.config.display_name = (
'test cache'
)
# Replay mode is not supported for caches tests due to the error message
# inconsistency in api and replay mode.
# To run api mode tests, use the following steps:
# 1. First create the resource.
# sh run_tests.sh pytest -s tests/caches/test_create.py --mode=api
# 1.1 If mldev test_create fails, update the uploaded file using this colab
# https://colab.sandbox.google.com/drive/1Fv6KGSs0cg6tlpcUHdsclHussXMEGOXk#scrollTo=RSKmFPx00MVL.
# 2. Find the resource name in debugging print and change the resource name constants.py.
# 3. Run and record get and update tests.
# sh run_tests.sh pytest -s tests/caches/test_get.py --mode=api && sh run_tests.sh pytest -s tests/caches/test_update.py --mode=api && sh run_tests.sh pytest -s tests/caches/test_delete.py --mode=api
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_caches_create_with_gcs_uri',
exception_if_mldev='INVALID_ARGUMENT',
parameters=_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI,
),
pytest_helper.TestTableItem(
name='test_caches_create_with_gcs_uri_cmek',
exception_if_mldev='only supported in Gemini Enterprise Agent Platform mode',
exception_if_vertex='INVALID_ARGUMENT', # The key is invalid.
parameters=_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_CMEK,
),
pytest_helper.TestTableItem(
name='test_caches_create_with_gcs_uri_expire_time',
exception_if_mldev='INVALID_ARGUMENT',
parameters=_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_EXPIRE_TIME,
),
pytest_helper.TestTableItem(
name='test_caches_create_model_partial_path_1',
exception_if_mldev='INVALID_ARGUMENT',
parameters=_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_PARTIAL_MODEL_1,
),
pytest_helper.TestTableItem(
name='test_caches_create_model_partial_path_2',
exception_if_mldev='404',
parameters=_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI_PARTIAL_MODEL_2,
),
pytest_helper.TestTableItem(
name='test_caches_create_with_googleai_file',
exception_if_vertex='Internal',
parameters=_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE,
skip_in_api_mode='Create is not reproducible in the API mode.',
),
pytest_helper.TestTableItem(
name='test_caches_create_with_googleai_file_expire_time',
exception_if_vertex='Internal',
parameters=_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE_EXPIRE_TIME,
skip_in_api_mode='Create is not reproducible in the API mode.',
),
pytest_helper.TestTableItem(
name='test_caches_create_with_googleai_file_model_partial_path_1',
exception_if_vertex='Internal',
parameters=_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE_PARTIAL_MODEL_1,
skip_in_api_mode='Create is not reproducible in the API mode.',
),
]
pytestmark = [
pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='caches.create',
test_table=test_table,
),
]
pytest_plugins = ('pytest_asyncio',)
@pytest.mark.asyncio
async def test_async_googleai_file_create(client):
if client._api_client.vertexai:
with pytest.raises(Exception):
await client.aio.caches.create(
model=_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE.model,
config=_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE.config,
)
else:
await client.aio.caches.create(
model=_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE.model,
config=_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE.config,
)
@@ -0,0 +1,105 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import copy
import pytest
from ... import types
from .. import pytest_helper
from . import constants
from ... import _transformers as t
_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI = types._CreateCachedContentParameters(
model='gemini-2.5-flash',
config={
'contents': [
types.Content(
role='user',
parts=[
types.Part(
fileData=types.FileData(
fileUri='gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf',
mimeType='application/pdf',
)
),
types.Part(
fileData=types.FileData(
fileUri='gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf',
mimeType='application/pdf',
)
),
],
)
],
'system_instruction': t.t_content('What is the sum of the two pdfs?'),
'display_name': 'test cache',
'ttl': '86400s',
'http_options': constants.VERTEX_HTTP_OPTIONS,
},
)
_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE = types._CreateCachedContentParameters(
model='gemini-2.5-flash',
config={
'contents': [
types.Content(
role='user',
parts=[
types.Part(
fileData=types.FileData(
mimeType='application/pdf',
fileUri='https://generativelanguage.googleapis.com/v1beta/files/v200dhvn15h7',
)
)
],
)
],
'system_instruction': t.t_content('What is the sum of the two pdfs?'),
'display_name': 'test cache',
'ttl': '86400s',
'http_options': constants.MLDEV_HTTP_OPTIONS,
},
)
# Replay mode is not supported for caches tests due to the error message
# inconsistency in api and replay mode.
# To run api mode tests, use the following steps:
# 1. First create the resource.
# sh run_tests.sh pytest -s tests/caches/test_create.py --mode=api
# 1.1 If mldev test_create fails, update the uploaded file using this colab
# https://colab.sandbox.google.com/drive/1Fv6KGSs0cg6tlpcUHdsclHussXMEGOXk#scrollTo=RSKmFPx00MVL.
# 2. Find the resource name in debugging print and change the resource name constants.py.
# 3. Run and record get and update tests.
# sh run_tests.sh pytest -s tests/caches/test_get.py --mode=api && sh run_tests.sh pytest -s tests/caches/test_update.py --mode=api && sh run_tests.sh pytest -s tests/caches/test_delete.py --mode=api
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
name='test_caches_create_with_gcs_uri',
exception_if_mldev='404',
parameters=_CREATE_CACHED_CONTENT_PARAMETERS_GCS_URI,
),
pytest_helper.TestTableItem(
name='test_caches_create_with_googleai_file',
exception_if_vertex='404',
parameters=_CREATE_CACHED_CONTENT_PARAMETERS_GOOGLEAI_FILE,
skip_in_api_mode='Create is not reproducible in the API mode.',
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='caches.create',
test_table=test_table,
)
pytest_plugins = ('pytest_asyncio',)
@@ -0,0 +1,54 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import pytest
from ... import types
from .. import pytest_helper
from . import constants
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
skip_in_api_mode='Delete is not reproducible in the API mode.',
name='test_caches_delete_with_vertex_cache_name',
exception_if_mldev='PERMISSION_DENIED',
parameters=types._DeleteCachedContentParameters(
name=constants.CACHED_CONTENT_NAME_VERTEX,
),
),
pytest_helper.TestTableItem(
skip_in_api_mode='Delete is not reproducible in the API mode.',
name='test_caches_delete_with_mldev_cache_name',
exception_if_vertex='NOT_FOUND',
parameters=types._DeleteCachedContentParameters(
name=constants.CACHED_CONTENT_NAME_MLDEV,
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='caches.delete',
test_table=test_table,
)
@pytest.mark.asyncio
async def test_async_delete(client):
if client._api_client.vertexai:
await client.aio.caches.delete(name=constants.CACHED_CONTENT_NAME_VERTEX)
else:
await client.aio.caches.delete(name=constants.CACHED_CONTENT_NAME_MLDEV)
@@ -0,0 +1,52 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import pytest
from ... import types
from .. import pytest_helper
from . import constants
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
skip_in_api_mode='Delete is not reproducible in the API mode.',
name='test_caches_delete_with_vertex_cache_name',
exception_if_mldev='404',
parameters=types._DeleteCachedContentParameters(
name=constants.CACHED_CONTENT_NAME_VERTEX,
config={
'http_options': constants.VERTEX_HTTP_OPTIONS,
},
),
),
pytest_helper.TestTableItem(
skip_in_api_mode='Delete is not reproducible in the API mode.',
name='test_caches_delete_with_mldev_cache_name',
exception_if_vertex='404',
parameters=types._DeleteCachedContentParameters(
name=constants.CACHED_CONTENT_NAME_MLDEV,
config={
'http_options': constants.MLDEV_HTTP_OPTIONS,
},
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='caches.delete',
test_table=test_table,
)
@@ -0,0 +1,94 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import pytest
from ... import types
from .. import pytest_helper
from . import constants
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
skip_in_api_mode='Get is not reproducible in the API mode.',
name='test_caches_get_with_vertex_cache_name',
exception_if_mldev='PERMISSION_DENIED',
parameters=types._GetCachedContentParameters(
name=constants.CACHED_CONTENT_NAME_VERTEX,
),
),
pytest_helper.TestTableItem(
skip_in_api_mode='Get is not reproducible in the API mode.',
name='test_caches_get_with_mldev_cache_name',
exception_if_vertex='NOT_FOUND',
parameters=types._GetCachedContentParameters(
name=constants.CACHED_CONTENT_NAME_MLDEV,
),
),
pytest_helper.TestTableItem(
skip_in_api_mode='Get is not reproducible in the API mode.',
name='test_caches_get_with_mldev_cache_name_partial_1',
exception_if_vertex='NOT_FOUND',
parameters=types._GetCachedContentParameters(
name='cachedContents/o239k1gxzz0juy9wqstndhncr85krehehf551hqh'
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='caches.get',
test_table=test_table,
)
@pytest.mark.asyncio
async def test_async_get(client):
if client._api_client.vertexai:
response = await client.aio.caches.get(
name=constants.CACHED_CONTENT_NAME_VERTEX
)
assert response
else:
await client.aio.caches.get(name=constants.CACHED_CONTENT_NAME_MLDEV)
def test_different_cache_name_formats(client):
if client._api_client.vertexai:
response1 = client.caches.get(
name='projects/964831358985/locations/us-central1/cachedContents/2164089915711684608'
)
assert response1
response2 = client.caches.get(
name='locations/us-central1/cachedContents/2164089915711684608'
)
assert response2
response3 = client.caches.get(
name='cachedContents/2164089915711684608'
)
assert response3
response4 = client.caches.get(
name='2164089915711684608'
)
assert response4
else:
response1 = client.caches.get(
name='cachedContents/o239k1gxzz0juy9wqstndhncr85krehehf551hqh'
)
assert response1
response2 = client.caches.get(
name='o239k1gxzz0juy9wqstndhncr85krehehf551hqh'
)
assert response2
@@ -0,0 +1,52 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import pytest
from ... import types
from .. import pytest_helper
from . import constants
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
skip_in_api_mode='Get is not reproducible in the API mode.',
name='test_caches_get_with_vertex_cache_name',
exception_if_mldev='404',
parameters=types._GetCachedContentParameters(
name=constants.CACHED_CONTENT_NAME_VERTEX,
config={
'http_options': constants.VERTEX_HTTP_OPTIONS,
},
),
),
pytest_helper.TestTableItem(
skip_in_api_mode='Get is not reproducible in the API mode.',
name='test_caches_get_with_mldev_cache_name',
exception_if_vertex='404',
parameters=types._GetCachedContentParameters(
name=constants.CACHED_CONTENT_NAME_MLDEV,
config={
'http_options': constants.MLDEV_HTTP_OPTIONS,
},
),
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='caches.get',
test_table=test_table,
)
@@ -0,0 +1,68 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Test caches list method."""
import pytest
from ... import types
from .. import pytest_helper
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
skip_in_api_mode='List is not reproducible in the API mode.',
name='test_caches_list',
parameters=types._ListCachedContentsParameters(config={'page_size': 3}),
),
]
pytestmark = [
pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='caches.list',
test_table=test_table,
)
]
def test_pager(client):
cached_contents = client.caches.list(config={'page_size': 2})
assert 'content-type' in cached_contents.sdk_http_response.headers
assert cached_contents.name == 'cached_contents'
assert cached_contents.page_size == 2
assert len(cached_contents) <= 2
# Iterate through all the pages. Then next_page() should raise an exception.
for _ in cached_contents:
pass
with pytest.raises(IndexError, match='No more pages to fetch.'):
cached_contents.next_page()
@pytest.mark.asyncio
async def test_async_pager(client):
cached_contents = await client.aio.caches.list(config={'page_size': 2})
assert 'Content-Type' in cached_contents.sdk_http_response.headers
assert cached_contents.name == 'cached_contents'
assert cached_contents.page_size == 2
assert len(cached_contents) <= 2
# Iterate through all the pages. Then next_page() should raise an exception.
async for _ in cached_contents:
pass
with pytest.raises(IndexError, match='No more pages to fetch.'):
await cached_contents.next_page()
@@ -0,0 +1,70 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import pytest
from ... import types
from .. import pytest_helper
from . import constants
_VERTEX_UPDATE_PARAMETERS = types._UpdateCachedContentParameters(
name=constants.CACHED_CONTENT_NAME_VERTEX,
config={
'ttl': '7600s',
},
)
_MLDEV_UPDATE_PARAMETERS = types._UpdateCachedContentParameters(
name=constants.CACHED_CONTENT_NAME_MLDEV,
config={
'ttl': '7600s',
},
)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
skip_in_api_mode='Update has permission issues in the API mode.',
name='test_caches_update_with_vertex_cache_name',
exception_if_mldev='PERMISSION_DENIED',
parameters=_VERTEX_UPDATE_PARAMETERS,
),
pytest_helper.TestTableItem(
skip_in_api_mode='Update has permission issues in the API mode.',
name='test_caches_update_with_mldev_cache_name',
exception_if_vertex='NOT_FOUND',
parameters=_MLDEV_UPDATE_PARAMETERS,
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='caches.update',
test_table=test_table,
)
@pytest.mark.asyncio
async def test_async_update(client):
if client._api_client.vertexai:
response = await client.aio.caches.update(
name=_VERTEX_UPDATE_PARAMETERS.name,
config=_VERTEX_UPDATE_PARAMETERS.config,
)
assert response
else:
await client.aio.caches.update(
name=_MLDEV_UPDATE_PARAMETERS.name,
config=_MLDEV_UPDATE_PARAMETERS.config,
)
@@ -0,0 +1,58 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import pytest
from ... import types
from .. import pytest_helper
from . import constants
_VERTEX_UPDATE_PARAMETERS = types._UpdateCachedContentParameters(
name=constants.CACHED_CONTENT_NAME_VERTEX,
config={
'ttl': '7600s',
'http_options': constants.VERTEX_HTTP_OPTIONS,
},
)
_MLDEV_UPDATE_PARAMETERS = types._UpdateCachedContentParameters(
name=constants.CACHED_CONTENT_NAME_MLDEV,
config={
'ttl': '7600s',
'http_options': constants.MLDEV_HTTP_OPTIONS,
},
)
test_table: list[pytest_helper.TestTableItem] = [
pytest_helper.TestTableItem(
skip_in_api_mode='Update has permission issues in the API mode.',
name='test_caches_update_with_vertex_cache_name',
exception_if_mldev='404',
parameters=_VERTEX_UPDATE_PARAMETERS,
),
pytest_helper.TestTableItem(
skip_in_api_mode='Update has permission issues in the API mode.',
name='test_caches_update_with_mldev_cache_name',
exception_if_vertex='404',
parameters=_MLDEV_UPDATE_PARAMETERS,
),
]
pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
test_method='caches.update',
test_table=test_table,
)