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:
co-authored by
Claude Opus 4.7
parent
06d871ce22
commit
b3bd14f183
@@ -25,6 +25,7 @@ import logging
|
|||||||
import re
|
import re
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from tests.conftest import create_mcp_client_session
|
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)
|
@pytest.mark.timeout(60)
|
||||||
async def test_chunk_context_endpoint_requires_authentication():
|
async def test_chunk_context_endpoint_requires_authentication():
|
||||||
"""Direct HTTP hit at /api/v1/chunk-context without a bearer must 401."""
|
"""Direct HTTP hit at /api/v1/chunk-context without a bearer must 401."""
|
||||||
import httpx
|
|
||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
response = await client.get(
|
response = await client.get(
|
||||||
"http://localhost:8003/api/v1/chunk-context",
|
"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
|
`validate_token_and_get_user`, which must turn into a clean 401/404 from
|
||||||
the HTTP layer, not an opaque 500.
|
the HTTP layer, not an opaque 500.
|
||||||
"""
|
"""
|
||||||
import httpx
|
|
||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
response = await client.get(
|
response = await client.get(
|
||||||
"http://localhost:8003/api/v1/chunk-context",
|
"http://localhost:8003/api/v1/chunk-context",
|
||||||
|
|||||||
@@ -193,12 +193,9 @@ class TestChunkContextCredentialPath:
|
|||||||
|
|
||||||
# Regression guard: credential resolution must go through the
|
# Regression guard: credential resolution must go through the
|
||||||
# app-password helper, not NextcloudClient.from_token.
|
# app-password helper, not NextcloudClient.from_token.
|
||||||
mock_basic_auth.assert_awaited_once()
|
mock_basic_auth.assert_awaited_once_with(
|
||||||
args, kwargs = mock_basic_auth.call_args
|
"testuser", "http://localhost:8080"
|
||||||
positional = list(args)
|
)
|
||||||
if "user_id" in kwargs:
|
|
||||||
positional.insert(0, kwargs["user_id"])
|
|
||||||
assert positional[0] == "testuser"
|
|
||||||
|
|
||||||
def test_not_provisioned_returns_401(self):
|
def test_not_provisioned_returns_401(self):
|
||||||
"""If the user has no stored app password, the handler must surface
|
"""If the user has no stored app password, the handler must surface
|
||||||
|
|||||||
Reference in New Issue
Block a user