Linted and formatted all files
This commit is contained in:
@@ -1,19 +1,24 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.main import app, lifespan
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
"""Test client for FastAPI app"""
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
def test_root_endpoint(client):
|
||||
"""Test root endpoint returns expected message"""
|
||||
response = client.get("/")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"message": "IPTV Updater API"}
|
||||
|
||||
|
||||
def test_openapi_schema_generation(client):
|
||||
"""Test OpenAPI schema is properly generated"""
|
||||
# First call - generate schema
|
||||
@@ -23,7 +28,7 @@ def test_openapi_schema_generation(client):
|
||||
assert schema["openapi"] == "3.1.0"
|
||||
assert "securitySchemes" in schema["components"]
|
||||
assert "Bearer" in schema["components"]["securitySchemes"]
|
||||
|
||||
|
||||
# Test empty components initialization
|
||||
with patch("app.main.get_openapi", return_value={"info": {}}):
|
||||
# Clear cached schema
|
||||
@@ -35,26 +40,28 @@ def test_openapi_schema_generation(client):
|
||||
assert "components" in schema
|
||||
assert "schemas" in schema["components"]
|
||||
|
||||
|
||||
def test_openapi_schema_caching(mocker):
|
||||
"""Test OpenAPI schema caching behavior"""
|
||||
# Clear any existing schema
|
||||
app.openapi_schema = None
|
||||
|
||||
|
||||
# Mock get_openapi to return test schema
|
||||
mock_schema = {"test": "schema"}
|
||||
mocker.patch("app.main.get_openapi", return_value=mock_schema)
|
||||
|
||||
|
||||
# First call - should call get_openapi
|
||||
schema = app.openapi()
|
||||
assert schema == mock_schema
|
||||
assert app.openapi_schema == mock_schema
|
||||
|
||||
|
||||
# Second call - should return cached schema
|
||||
with patch("app.main.get_openapi") as mock_get_openapi:
|
||||
schema = app.openapi()
|
||||
assert schema == mock_schema
|
||||
mock_get_openapi.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_lifespan_init_db(mocker):
|
||||
"""Test lifespan manager initializes database"""
|
||||
@@ -63,6 +70,7 @@ async def test_lifespan_init_db(mocker):
|
||||
pass # Just enter/exit context
|
||||
mock_init_db.assert_called_once()
|
||||
|
||||
|
||||
def test_router_inclusion():
|
||||
"""Test all routers are properly included"""
|
||||
route_paths = {route.path for route in app.routes}
|
||||
@@ -70,4 +78,4 @@ def test_router_inclusion():
|
||||
assert any(path.startswith("/auth") for path in route_paths)
|
||||
assert any(path.startswith("/channels") for path in route_paths)
|
||||
assert any(path.startswith("/playlist") for path in route_paths)
|
||||
assert any(path.startswith("/priorities") for path in route_paths)
|
||||
assert any(path.startswith("/priorities") for path in route_paths)
|
||||
|
||||
Reference in New Issue
Block a user