49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""Интеграционные тесты HTTP-эндпоинтов (Flask test client)."""
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def client(tmp_path, monkeypatch):
|
|
from db import connection as conn
|
|
monkeypatch.setattr(conn, "DB_PATH", str(tmp_path / "app.db"))
|
|
from app import create_app
|
|
app = create_app()
|
|
app.config["TESTING"] = True
|
|
yield app.test_client()
|
|
c = getattr(conn._local, "conn", None)
|
|
if c is not None:
|
|
try:
|
|
c.close()
|
|
except Exception:
|
|
pass
|
|
conn._local.conn = None
|
|
|
|
|
|
class TestHealth:
|
|
def test_health(self, client):
|
|
from config import VERSION
|
|
r = client.get("/health")
|
|
assert r.status_code == 200
|
|
data = r.get_json()
|
|
assert data["ok"] is True
|
|
assert data["version"] == VERSION
|
|
|
|
|
|
class TestSpecCurrent:
|
|
def test_missing_contract_id(self, client):
|
|
r = client.get("/api/spec-current")
|
|
assert r.status_code == 400
|
|
|
|
def test_empty(self, client):
|
|
r = client.get("/api/spec-current?contract_id=missing")
|
|
assert r.status_code == 200
|
|
data = r.get_json()
|
|
assert data["ok"] is True
|
|
assert data["rows"] == []
|
|
|
|
|
|
class TestGroups:
|
|
def test_missing_batch(self, client):
|
|
r = client.get("/api/groups")
|
|
assert r.status_code == 400
|