- Define SQLModel schemas for Session, Note, and Link entities - Add API request/response models for RPC endpoints - Create LLM structured output models for Zettel extraction - Set up async database initialization with SQLModel and aiosqlite - Implement repository pattern for CRUD operations - Add complete test suite with pytest configuration - Create validation test runner for development workflow - Add .gitignore for Python/FastAPI project security
132 lines
3.7 KiB
Python
132 lines
3.7 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test runner script for SkyTalk API.
|
|
|
|
This script can be run without pytest to validate basic functionality.
|
|
"""
|
|
import asyncio
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add the app directory to Python path
|
|
app_dir = Path(__file__).parent
|
|
sys.path.insert(0, str(app_dir))
|
|
|
|
|
|
async def test_basic_setup():
|
|
"""Test basic setup and imports."""
|
|
print("🧪 Testing basic setup...")
|
|
|
|
try:
|
|
from app.core.config import settings
|
|
print(f"✅ Config loaded: API key {'set' if settings.GOOGLE_API_KEY and settings.GOOGLE_API_KEY != 'your_google_api_key_here' else 'NOT set'}")
|
|
|
|
from app.data.models import Session, Note, Link, StartSessionRequest
|
|
print("✅ All models imported successfully")
|
|
|
|
from app.data.database import init_db, get_session
|
|
print("✅ Database modules imported successfully")
|
|
|
|
from app.data.repositories import SessionRepository, NoteRepository, LinkRepository
|
|
print("✅ Repository modules imported successfully")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Import error: {e}")
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
async def test_model_validation():
|
|
"""Test model creation and validation."""
|
|
print("\n🧪 Testing model validation...")
|
|
|
|
try:
|
|
from app.data.models import StartSessionRequest, Session, Note
|
|
import uuid
|
|
|
|
# Test API models
|
|
req = StartSessionRequest(topic="AI Ethics")
|
|
print(f"✅ StartSessionRequest: {req.topic}")
|
|
|
|
# Test database models
|
|
session = Session()
|
|
print(f"✅ Session created with ID: {session.id}")
|
|
|
|
note = Note(
|
|
title="Test Note",
|
|
content="Test content",
|
|
tags=["test"],
|
|
session_id=session.id
|
|
)
|
|
print(f"✅ Note created with ID: {note.id}")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Model validation error: {e}")
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
async def test_database_operations():
|
|
"""Test database initialization and basic operations."""
|
|
print("\n🧪 Testing database operations...")
|
|
|
|
try:
|
|
from app.data.database import init_db, get_session
|
|
from app.data.repositories import SessionRepository
|
|
from app.data.models import Session
|
|
|
|
# Initialize database
|
|
await init_db()
|
|
print("✅ Database tables created")
|
|
|
|
# Test repository operations
|
|
async with get_session() as db:
|
|
repo = SessionRepository(db)
|
|
session = await repo.create(status="test")
|
|
print(f"✅ Session created via repository: {session.id}")
|
|
|
|
retrieved = await repo.get(session.id)
|
|
print(f"✅ Session retrieved: {retrieved.status}")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Database operation error: {e}")
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
async def main():
|
|
"""Run all tests."""
|
|
print("🚀 Running SkyTalk API validation tests...\n")
|
|
|
|
tests = [
|
|
test_basic_setup,
|
|
test_model_validation,
|
|
test_database_operations
|
|
]
|
|
|
|
passed = 0
|
|
total = len(tests)
|
|
|
|
for test in tests:
|
|
if await test():
|
|
passed += 1
|
|
else:
|
|
break # Stop on first failure
|
|
|
|
print(f"\n📊 Test Results: {passed}/{total} passed")
|
|
|
|
if passed == total:
|
|
print("🎉 All basic validation tests passed!")
|
|
print("\nNext steps:")
|
|
print("1. Run full test suite: pytest")
|
|
print("2. Continue with Phase 3 implementation")
|
|
else:
|
|
print("❌ Some tests failed. Please fix issues before continuing.")
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main()) |