32 lines
865 B
Python
32 lines
865 B
Python
|
|
"""Test configuration - set env before importing app."""
|
||
|
|
import os
|
||
|
|
|
||
|
|
os.environ.setdefault("POSTGRES_USER", "test_user")
|
||
|
|
os.environ.setdefault("POSTGRES_PASSWORD", "test_pass")
|
||
|
|
os.environ.setdefault("POSTGRES_DB", "test_db")
|
||
|
|
os.environ.setdefault("AUTH_SECRET_KEY", "test-secret-key")
|
||
|
|
os.environ.setdefault("AUTH_DEFAULT_USER", "admin")
|
||
|
|
os.environ.setdefault("AUTH_DEFAULT_PASSWORD", "admin123")
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
from fastapi.testclient import TestClient
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def client():
|
||
|
|
from main import app
|
||
|
|
with TestClient(app) as c:
|
||
|
|
yield c
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def auth_token(client):
|
||
|
|
resp = client.post("/api/auth/login", json={"username": "admin", "password": "admin123"})
|
||
|
|
return resp.json()["access_token"]
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def auth_client(client, auth_token):
|
||
|
|
client.headers["Authorization"] = f"Bearer {auth_token}"
|
||
|
|
return client
|