Complete backend verification: fix syntax errors, create __init__.py files, add setup_db.py, update docker-compose for two PostgreSQL containers
This commit is contained in:
+26
-16
@@ -3,7 +3,7 @@
|
||||
Backend System Test Script
|
||||
|
||||
Tests all backend components:
|
||||
- Database connections (Cockatrice + MTG)
|
||||
- Database connections (MTG Online + MTG)
|
||||
- Redis connection and caching
|
||||
- Card database queries
|
||||
- API endpoints
|
||||
@@ -21,10 +21,20 @@ from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
||||
from sqlalchemy import text
|
||||
|
||||
# Database URLs
|
||||
COCKATRICE_DB = "postgresql+asyncpg://cockatrice:cockatrice_pass@localhost:5432/cockatrice"
|
||||
MTG_DB = "postgresql+asyncpg://cockatrice:cockatrice_pass@localhost:5432/mtgdata"
|
||||
COCKATRICE_DB = "postgresql+asyncpg://mtgonline:mtgonline_pass@localhost:5432/mtgonline"
|
||||
MTG_DB = "postgresql+asyncpg://mtgonline:mtgonline_pass@localhost:5432/mtgdata"
|
||||
REDIS_URL = "redis://localhost:6379/0"
|
||||
|
||||
# Test URLs - detect environment
|
||||
import socket
|
||||
try:
|
||||
# Try Docker network first
|
||||
socket.getaddrinfo('mtg_backend', 8000)
|
||||
API_BASE = 'http://mtg_backend:8000'
|
||||
except:
|
||||
# Fall back to host port
|
||||
API_BASE = 'http://localhost:8001'
|
||||
print(f"Using API base: {API_BASE}")
|
||||
results = {
|
||||
"tests_run": 0,
|
||||
"tests_passed": 0,
|
||||
@@ -97,29 +107,29 @@ async def test_cache_operations() -> bool:
|
||||
print(f"✗ Redis cache operations: FAILED - {str(e)}")
|
||||
return False
|
||||
|
||||
async def test_cockatrice_tables() -> bool:
|
||||
"""Test Cockatrice database tables."""
|
||||
async def test_mtgonline_tables() -> bool:
|
||||
"""Test MTG Online database tables."""
|
||||
results["tests_run"] += 1
|
||||
try:
|
||||
engine = create_async_engine(COCKATRICE_DB, echo=False)
|
||||
async with engine.connect() as conn:
|
||||
# Test users table
|
||||
result = await conn.execute(text("SELECT COUNT(*) FROM cockatrice_users"))
|
||||
result = await conn.execute(text("SELECT COUNT(*) FROM mtgonline_users"))
|
||||
user_count = result.scalar()
|
||||
|
||||
# Test decks table
|
||||
result = await conn.execute(text("SELECT COUNT(*) FROM cockatrice_decklist_files"))
|
||||
result = await conn.execute(text("SELECT COUNT(*) FROM mtgonline_decklist_files"))
|
||||
deck_count = result.scalar()
|
||||
|
||||
await engine.dispose()
|
||||
|
||||
results["tests_passed"] += 1
|
||||
print(f"✓ Cockatrice tables: OK (users: {user_count}, decks: {deck_count})")
|
||||
print(f"✓ MTG Online tables: OK (users: {user_count}, decks: {deck_count})")
|
||||
return True
|
||||
except Exception as e:
|
||||
results["tests_failed"] += 1
|
||||
results["failures"].append(f"Cockatrice tables: {str(e)}")
|
||||
print(f"✗ Cockatrice tables: FAILED - {str(e)}")
|
||||
results["failures"].append(f"MTG Online tables: {str(e)}")
|
||||
print(f"✗ MTG Online tables: FAILED - {str(e)}")
|
||||
return False
|
||||
|
||||
async def test_mtg_tables() -> bool:
|
||||
@@ -181,7 +191,7 @@ async def test_health_endpoint() -> bool:
|
||||
results["tests_run"] += 1
|
||||
try:
|
||||
import requests
|
||||
response = requests.get("http://localhost:8000/health", timeout=5)
|
||||
response = requests.get("http://localhost:8001/health", timeout=5)
|
||||
|
||||
if response.status_code == 200:
|
||||
results["tests_passed"] += 1
|
||||
@@ -204,7 +214,7 @@ async def test_card_search_endpoint() -> bool:
|
||||
try:
|
||||
import requests
|
||||
response = requests.get(
|
||||
"http://localhost:8000/mtg/cards/search",
|
||||
"http://localhost:8001/api/v1/mtg/cards/search",
|
||||
params={"q": "Lightning Bolt", "limit": 5},
|
||||
timeout=10
|
||||
)
|
||||
@@ -231,7 +241,7 @@ async def test_statistics_endpoint() -> bool:
|
||||
try:
|
||||
import requests
|
||||
response = requests.get(
|
||||
"http://localhost:8000/mtg/cards/statistics",
|
||||
"http://localhost:8001/api/v1/mtg/cards/statistics",
|
||||
timeout=10
|
||||
)
|
||||
|
||||
@@ -258,7 +268,7 @@ async def test_auth_endpoint() -> bool:
|
||||
try:
|
||||
import requests
|
||||
response = requests.post(
|
||||
"http://localhost:8000/auth/register",
|
||||
"http://localhost:8001/api/v1/auth/register",
|
||||
json={
|
||||
"username": "test_user",
|
||||
"email": "test@example.com",
|
||||
@@ -295,7 +305,7 @@ async def run_all_tests():
|
||||
# Database connections
|
||||
print("Testing Database Connections:")
|
||||
print("-" * 60)
|
||||
await test_connection(COCKATRICE_DB, "Cockatrice PostgreSQL")
|
||||
await test_connection(COCKATRICE_DB, "MTG Online PostgreSQL")
|
||||
await test_connection(MTG_DB, "MTG PostgreSQL")
|
||||
await test_redis()
|
||||
print()
|
||||
@@ -309,7 +319,7 @@ async def run_all_tests():
|
||||
# Database tables
|
||||
print("Testing Database Tables:")
|
||||
print("-" * 60)
|
||||
await test_cockatrice_tables()
|
||||
await test_mtgonline_tables()
|
||||
await test_mtg_tables()
|
||||
await test_mtg_card_query()
|
||||
print()
|
||||
|
||||
Reference in New Issue
Block a user