test: tighten regression guard and hoist httpx import

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) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-04-22 20:26:41 +02:00
co-authored by Claude Opus 4.7
parent 06d871ce22
commit b3bd14f183
2 changed files with 4 additions and 10 deletions
@@ -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",
@@ -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