Skip to content

Commit 74a037f

Browse files
jfrancoaclaude
andcommitted
test: pin namespace create wire format and tighten type annotations
- Capture and assert the create() request body is empty JSON, locking the contract that the namespace name lives in the URL path only - Annotate method_call parametrize argument as Callable - Use Dict[str, Any] instead of bare dict for captured request bodies Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 5629aee commit 74a037f

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

mock_tests/test_namespaces.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""
1616

1717
import json
18-
from typing import Generator, Tuple
18+
from typing import Any, Callable, Dict, Generator, Tuple
1919

2020
import grpc
2121
import pytest
@@ -82,15 +82,25 @@ def ns_client_old(
8282
def test_namespaces_create_sends_post_and_parses_response(
8383
ns_client: Tuple[weaviate.WeaviateClient, HTTPServer],
8484
) -> None:
85+
"""``create`` must POST an empty JSON body — the name lives in the URL path.
86+
87+
Sending anything else (e.g. ``{"name": ...}``) would diverge from the server
88+
contract and is the kind of refactor that's tempting but breaks on the wire.
89+
"""
8590
client, server = ns_client
86-
server.expect_request("/v1/namespaces/myns", method="POST").respond_with_json(
87-
{"name": "myns"}, status=201
88-
)
91+
captured: Dict[str, Any] = {}
92+
93+
def handler(request: Request) -> Response:
94+
captured["body"] = json.loads(request.get_data(as_text=True) or "{}")
95+
return Response(json.dumps({"name": "myns"}), status=201)
96+
97+
server.expect_request("/v1/namespaces/myns", method="POST").respond_with_handler(handler)
8998

9099
ns = client.namespaces.create(name="myns")
91100

92101
assert isinstance(ns, Namespace)
93102
assert ns.name == "myns"
103+
assert captured["body"] == {}
94104
server.check_assertions()
95105

96106

@@ -213,7 +223,8 @@ def test_namespaces_delete_accepts_204(
213223
ids=["create", "get", "list_all", "delete"],
214224
)
215225
def test_namespaces_methods_require_1_38(
216-
ns_client_old: weaviate.WeaviateClient, method_call
226+
ns_client_old: weaviate.WeaviateClient,
227+
method_call: Callable[[weaviate.WeaviateClient], object],
217228
) -> None:
218229
"""Every public namespace method must guard with ``check_is_at_least_1_38_0``.
219230
@@ -240,7 +251,7 @@ def test_users_db_create_includes_namespace_in_body(
240251
namespace-binding on multi-tenant clusters.
241252
"""
242253
client, server = ns_client
243-
captured: dict = {}
254+
captured: Dict[str, Any] = {}
244255

245256
def handler(request: Request) -> Response:
246257
captured["body"] = json.loads(request.get_data(as_text=True) or "{}")
@@ -264,7 +275,7 @@ def test_users_db_create_omits_namespace_when_not_provided(
264275
don't recognize the field.
265276
"""
266277
client, server = ns_client
267-
captured: dict = {}
278+
captured: Dict[str, Any] = {}
268279

269280
def handler(request: Request) -> Response:
270281
captured["body"] = json.loads(request.get_data(as_text=True) or "{}")

0 commit comments

Comments
 (0)