/
tinypot
/
integr
Обзор
Документация
Войти
/
tinypot
/
integr
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
task_management_api/test_simple.py
68 строк
2 KB
Tim Polus
lab1
21 янв 2026, 23:15
21 янв 2026, 23:15
dd1578c
Код
Авторство
О чём код?
""" Simple test to verify FastAPI app can be imported and basic functionality works """ import os # Set environment variables for testing os.environ["DATABASE_URL"] = "sqlite+aiosqlite:///./test.db" def test_app_import(): """Test that the app can be imported""" try: from main import app assert app is not None assert app.title == "Task Management API" print("✅ App import successful") except Exception as e: print(f"❌ App import failed: {e}") raise def test_health_endpoint(): """Test health endpoint without database""" from fastapi.testclient import TestClient from main import app # Override database dependency to avoid connection async def mock_get_db(): # Mock database session - this won't work for real queries but allows app to start pass # Temporarily disable database-dependent routes client = TestClient(app) # Test health endpoint (should work without database) try: response = client.get("/health") assert response.status_code == 200 data = response.json() assert data == {"status": "healthy"} print("✅ Health endpoint test successful") except Exception as e: print(f"❌ Health endpoint test failed: {e}") raise def test_root_endpoint(): """Test root endpoint""" from fastapi.testclient import TestClient from main import app client = TestClient(app) try: response = client.get("/") assert response.status_code == 200 data = response.json() assert "message" in data assert "version" in data print("✅ Root endpoint test successful") except Exception as e: print(f"❌ Root endpoint test failed: {e}") raise if __name__ == "__main__": print("Running simple tests...") test_app_import() test_health_endpoint() test_root_endpoint() print("🎉 All simple tests passed!")