feat: add backend CI/CD deployment

This commit is contained in:
hailt 2026-11-12 21:32:31 +07:00
parent 8d40cff227
commit 7c2e6ed571
21 changed files with 269 additions and 41 deletions

View file

@ -1,11 +1,13 @@
"""Auth: hashing, tokens, and route protection (no dev-DB writes)."""
import pytest
import pytest_asyncio
from httpx import ASGITransport, AsyncClient
from fastapi.security import HTTPAuthorizationCredentials
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
from models import User
from src.core.db import Base
from src.core.db import get_session
from src.core.security import (
create_token,
decode_token,
@ -69,8 +71,23 @@ def test_protected_routes_reject_missing_token():
assert c.get("/api/v1/projects/x/images").status_code == 401
def test_login_rejects_unknown_user():
with TestClient(app) as c:
r = c.post("/api/v1/auth/login",
json={"email": "no-such-user@example.com", "password": "x"})
@pytest.mark.asyncio
async def test_login_rejects_unknown_user():
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
session_factory = async_sessionmaker(engine, expire_on_commit=False)
async def override_get_session():
async with session_factory() as session:
yield session
app.dependency_overrides[get_session] = override_get_session
try:
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as c:
r = await c.post("/api/v1/auth/login",
json={"email": "no-such-user@example.com", "password": "x"})
assert r.status_code == 401
finally:
app.dependency_overrides.clear()
await engine.dispose()