test: realign deps + page_context tests with current source
All checks were successful
CI / ruff (push) Successful in 18s
CI / pytest (push) Successful in 2h27m38s
CI / dependency-scanning (push) Successful in 32s
CI / docs (push) Successful in 50s
CI / validate (push) Successful in 31s
CI / deploy (push) Successful in 3m44s

Two stale unit-test groups left over from earlier intentional changes:

1. tests/unit/api/test_deps.py — TestGetCurrentStoreApi
   get_current_store_api gained a leading `request: Request` param in
   commit 6276e9e3 (terminal-device pairing) so the device-token path
   could record last_seen IP. The three tests still passed `(creds, db)`
   positionally, so `creds` bound to `request` and the function blew up
   with `Session has no attribute 'credentials'`. Pass a mock request
   first using the existing `_make_request` helper.

2. tests/unit/utils/test_page_context.py — TestBaseUrlCalculation
   d591200d switched the storefront base_url builder to use
   `store.subdomain or store.store_code` (lowercase slug) because the
   store-context middleware resolves URLs by the lowercase slug; the
   uppercase `store_code` is for internal use. Tests still asserted the
   old uppercase shape. Update the two URL assertions to the lowercase
   subdomain, invert `test_base_url_uses_store_code_not_subdomain` into
   `test_base_url_uses_subdomain_not_store_code`, and add a fallback
   test that exercises the `or store.store_code` path when subdomain
   is None.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-09 22:58:07 +02:00
parent fc7dc0ccd5
commit b65c51c038
2 changed files with 35 additions and 14 deletions

View File

@@ -518,24 +518,27 @@ class TestGetCurrentStoreApi:
store_role="owner",
)
creds = _make_credentials(token_data["access_token"])
request = _make_request("/api/v1/store/loyalty")
# Mock is_member_of to return True
with patch.object(User, "is_member_of", return_value=True):
result = get_current_store_api(creds, db)
result = get_current_store_api(request, creds, db)
assert result.id == test_store_user.id
def test_rejects_missing_credentials(self, db):
"""Missing credentials raises InvalidTokenException."""
request = _make_request("/api/v1/store/loyalty")
with pytest.raises(InvalidTokenException):
get_current_store_api(None, db)
get_current_store_api(request, None, db)
def test_admin_blocked(self, db, auth_manager, test_admin):
"""Admin user blocked from store API."""
token_data = auth_manager.create_access_token(user=test_admin)
creds = _make_credentials(token_data["access_token"])
request = _make_request("/api/v1/store/loyalty")
with pytest.raises(Exception, match="Store access only"):
get_current_store_api(creds, db)
get_current_store_api(request, creds, db)
# ============================================================================