test: pytest (auth, RBAC, endpoints) + étape CI build->test->push
Build & Deploy / build (push) Successful in 11s
Build & Deploy / build (push) Successful in 11s
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""Fixtures de test : client FastAPI + curseur SQL simulé (aucune vraie BDD)."""
|
||||
import os
|
||||
from contextlib import contextmanager
|
||||
|
||||
os.environ.setdefault("JWT_SECRET", "test-secret")
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
import main
|
||||
from auth import create_access_token
|
||||
|
||||
|
||||
class FakeCursor:
|
||||
"""Curseur pyodbc simulé : on règle description / rows / one par test."""
|
||||
def __init__(self):
|
||||
self.description = []
|
||||
self._rows = []
|
||||
self._one = None
|
||||
self.executed = []
|
||||
|
||||
def execute(self, query, *args):
|
||||
self.executed.append((query, args))
|
||||
return self
|
||||
|
||||
def fetchall(self):
|
||||
return self._rows
|
||||
|
||||
def fetchone(self):
|
||||
return self._one
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cur(monkeypatch):
|
||||
c = FakeCursor()
|
||||
|
||||
@contextmanager
|
||||
def fake_get_cursor():
|
||||
yield c
|
||||
|
||||
monkeypatch.setattr(main, "get_cursor", fake_get_cursor)
|
||||
return c
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
return TestClient(main.app)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def auth_headers():
|
||||
token = create_access_token({"sub": "admin", "role": "Admin", "uid": 1})
|
||||
return {"Authorization": f"Bearer {token}"}
|
||||
Reference in New Issue
Block a user