Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/storage/src/storage3/_async/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def list_indexes(
prefix: Optional[str] = None,
) -> ListVectorIndexesResponse:
body = self.with_metadata(
next_token=next_token, max_results=max_results, prefix=prefix
nextToken=next_token, maxResults=max_results, prefix=prefix
)
data = await self._request.send(
http_method="POST", path=["ListIndexes"], body=body
Expand Down
2 changes: 1 addition & 1 deletion src/storage/src/storage3/_sync/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def list_indexes(
prefix: Optional[str] = None,
) -> ListVectorIndexesResponse:
body = self.with_metadata(
next_token=next_token, max_results=max_results, prefix=prefix
nextToken=next_token, maxResults=max_results, prefix=prefix
)
data = self._request.send(http_method="POST", path=["ListIndexes"], body=body)
return ListVectorIndexesResponse.model_validate_json(data.content)
Expand Down
67 changes: 67 additions & 0 deletions src/storage/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,70 @@ async def test_async_bucket_proxy_exists_false_on_headless_error() -> None:
proxy._client, "request", new_callable=AsyncMock, return_value=mock_response
):
assert await proxy.exists("missing.txt") is False


def _list_indexes_transport(captured: Dict[str, Any]) -> Any:
"""A transport that records the ListIndexes request body and replies with one page."""
import json as _json

def handler(request: Request) -> Response:
captured["url"] = str(request.url)
captured["body"] = _json.loads(request.content)
return Response(200, json={"indexes": [], "nextToken": None})

return handler


@pytest.mark.asyncio
async def test_async_list_indexes_sends_camel_case_pagination(
valid_url, valid_headers
) -> None:
from httpx import MockTransport

captured: Dict[str, Any] = {}
client = AsyncStorageClient(
url=valid_url + "/",
headers=valid_headers,
http_client=AsyncClient(
transport=MockTransport(_list_indexes_transport(captured))
),
)

await (
client.vectors()
.from_("my-bucket")
.list_indexes(next_token="cursor-1", max_results=10, prefix="idx-")
)

assert captured["url"].endswith("/vector/ListIndexes")
assert captured["body"] == {
"vectorBucketName": "my-bucket",
"nextToken": "cursor-1",
"maxResults": 10,
"prefix": "idx-",
}


def test_sync_list_indexes_sends_camel_case_pagination(
valid_url, valid_headers
) -> None:
from httpx import MockTransport

captured: Dict[str, Any] = {}
client = SyncStorageClient(
url=valid_url + "/",
headers=valid_headers,
http_client=Client(transport=MockTransport(_list_indexes_transport(captured))),
)

client.vectors().from_("my-bucket").list_indexes(
next_token="cursor-1", max_results=10, prefix="idx-"
)

assert captured["url"].endswith("/vector/ListIndexes")
assert captured["body"] == {
"vectorBucketName": "my-bucket",
"nextToken": "cursor-1",
"maxResults": 10,
"prefix": "idx-",
}