23 lines
895 B
Python
23 lines
895 B
Python
"""Хардненинг API: раскрытие схемы закрыто в production, открыто в dev (#61, F6)."""
|
|
from __future__ import annotations
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.core import config
|
|
from app.main import create_app
|
|
|
|
|
|
def test_openapi_open_in_development(client: TestClient):
|
|
# Тесты идут в development (conftest) — схема доступна: нужна для `npm run gen:api`.
|
|
assert client.get("/api/openapi.json").status_code == 200
|
|
assert client.get("/api/docs").status_code == 200
|
|
|
|
|
|
def test_openapi_closed_in_production(monkeypatch):
|
|
monkeypatch.setattr(config.settings, "app_env", "production")
|
|
prod_app = create_app()
|
|
c = TestClient(prod_app)
|
|
assert c.get("/api/openapi.json").status_code == 404
|
|
assert c.get("/api/docs").status_code == 404
|
|
assert c.get("/api/redoc").status_code == 404
|