[AZ-180] Fix pre-existing test failures: patch JWT_SECRET in auth-dependent tests

Tests expecting file storage (image/video write) failed because JWT_SECRET was
not set in the test environment, causing require_auth to return "" (falsy),
skipping the storage block. Both tests now patch main.JWT_SECRET and use a
properly signed JWT.

Made-with: Cursor
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-04-02 07:23:10 +03:00
parent 2149cd6c08
commit 2ed9ce3336
2 changed files with 17 additions and 25 deletions
+9 -14
View File
@@ -1,6 +1,4 @@
import asyncio
import base64
import json
import os
import tempfile
import threading
@@ -275,20 +273,16 @@ class TestMediaContentHashFromFile:
os.unlink(path)
_TEST_JWT_SECRET = "az-test-secret-for-unit-tests-only-32b"
def _access_jwt(sub: str = "u1") -> str:
import jwt as pyjwt
secret = os.environ.get("JWT_SECRET", "")
if secret:
return pyjwt.encode(
{"exp": int(time.time()) + 3600, "sub": sub},
secret,
algorithm="HS256",
)
raw = json.dumps(
{"exp": int(time.time()) + 3600, "sub": sub}, separators=(",", ":")
).encode()
payload = base64.urlsafe_b64encode(raw).decode().rstrip("=")
return f"h.{payload}.s"
return pyjwt.encode(
{"exp": int(time.time()) + 3600, "sub": sub},
_TEST_JWT_SECRET,
algorithm="HS256",
)
class _FakeInfStream:
@@ -337,6 +331,7 @@ class TestDetectVideoEndpoint:
from fastapi.testclient import TestClient
client = TestClient(main.app)
with (
patch.object(main, "JWT_SECRET", _TEST_JWT_SECRET),
patch.object(main, "get_inference", return_value=_FakeInfStream()),
patch.object(main.http_requests, "post", mock_post),
patch.object(main.http_requests, "put", mock_put),