From b3bd14f183b40ba6ab8594a3e3e8c43118fbb1ac Mon Sep 17 00:00:00 2001 From: Chris Coutinho Date: Wed, 22 Apr 2026 20:26:41 +0200 Subject: [PATCH] test: tighten regression guard and hoist httpx import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per review: - Hoist `import httpx` out of the two test function bodies and into the module imports at the top of test_astrolabe_chunk_context.py. - Simplify the regression guard in test_management_chunk_context_endpoint.py to use `mock.assert_awaited_once_with(...)` instead of manually unpacking call_args. This is stricter — it fails loudly on signature change — and matches the canonical pattern for asserting mock calls. Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/integration/test_astrolabe_chunk_context.py | 5 +---- tests/unit/test_management_chunk_context_endpoint.py | 9 +++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/integration/test_astrolabe_chunk_context.py b/tests/integration/test_astrolabe_chunk_context.py index 847df157..c8ef1eee 100644 --- a/tests/integration/test_astrolabe_chunk_context.py +++ b/tests/integration/test_astrolabe_chunk_context.py @@ -25,6 +25,7 @@ import logging import re import uuid +import httpx import pytest from tests.conftest import create_mcp_client_session @@ -208,8 +209,6 @@ async def test_chunk_context_endpoint_uses_app_password( @pytest.mark.timeout(60) async def test_chunk_context_endpoint_requires_authentication(): """Direct HTTP hit at /api/v1/chunk-context without a bearer must 401.""" - import httpx - async with httpx.AsyncClient() as client: response = await client.get( "http://localhost:8003/api/v1/chunk-context", @@ -235,8 +234,6 @@ async def test_chunk_context_endpoint_rejects_invalid_bearer(): `validate_token_and_get_user`, which must turn into a clean 401/404 from the HTTP layer, not an opaque 500. """ - import httpx - async with httpx.AsyncClient() as client: response = await client.get( "http://localhost:8003/api/v1/chunk-context", diff --git a/tests/unit/test_management_chunk_context_endpoint.py b/tests/unit/test_management_chunk_context_endpoint.py index 04d3b0fc..e387a91a 100644 --- a/tests/unit/test_management_chunk_context_endpoint.py +++ b/tests/unit/test_management_chunk_context_endpoint.py @@ -193,12 +193,9 @@ class TestChunkContextCredentialPath: # Regression guard: credential resolution must go through the # app-password helper, not NextcloudClient.from_token. - mock_basic_auth.assert_awaited_once() - args, kwargs = mock_basic_auth.call_args - positional = list(args) - if "user_id" in kwargs: - positional.insert(0, kwargs["user_id"]) - assert positional[0] == "testuser" + mock_basic_auth.assert_awaited_once_with( + "testuser", "http://localhost:8080" + ) def test_not_provisioned_returns_401(self): """If the user has no stored app password, the handler must surface