200 lines
5.8 KiB
Python
200 lines
5.8 KiB
Python
"""
|
|
Main test suite for PunimTag
|
|
|
|
Consolidated tests covering core functionality.
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add src to path for imports
|
|
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
|
|
|
|
def test_imports():
|
|
"""Test that all modules can be imported."""
|
|
try:
|
|
from backend import app
|
|
print("✅ Flask app imported successfully")
|
|
|
|
# Test if we can access the app instance
|
|
if hasattr(app, 'app'):
|
|
print("✅ Flask app instance found")
|
|
else:
|
|
print("⚠️ Flask app instance not found, but module imported")
|
|
|
|
return True
|
|
except ImportError as e:
|
|
print(f"❌ Import error: {e}")
|
|
return False
|
|
|
|
def test_database_connection():
|
|
"""Test database connection and basic operations."""
|
|
try:
|
|
# Test if we can connect to the database
|
|
import sqlite3
|
|
db_path = Path(__file__).parent.parent / "data" / "punimtag_simple.db"
|
|
|
|
if db_path.exists():
|
|
conn = sqlite3.connect(str(db_path))
|
|
cursor = conn.cursor()
|
|
cursor.execute("SELECT 1")
|
|
result = cursor.fetchone()
|
|
conn.close()
|
|
|
|
if result and result[0] == 1:
|
|
print("✅ Database connection successful")
|
|
return True
|
|
else:
|
|
print("❌ Database query failed")
|
|
return False
|
|
else:
|
|
print("⚠️ Database file not found, but this is normal for fresh installs")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Database error: {e}")
|
|
return False
|
|
|
|
def test_face_recognition_import():
|
|
"""Test face recognition module import."""
|
|
try:
|
|
from backend import visual_identifier
|
|
print("✅ Face recognition module imported successfully")
|
|
return True
|
|
except ImportError as e:
|
|
print(f"❌ Face recognition import error: {e}")
|
|
return False
|
|
|
|
def test_config_loading():
|
|
"""Test configuration loading."""
|
|
try:
|
|
# Test if config directory exists and has files
|
|
config_dir = Path(__file__).parent.parent / "config"
|
|
if config_dir.exists():
|
|
config_files = list(config_dir.glob("*.py"))
|
|
if config_files:
|
|
print(f"✅ Configuration directory found with {len(config_files)} files")
|
|
return True
|
|
else:
|
|
print("⚠️ Configuration directory exists but no Python files found")
|
|
return True
|
|
else:
|
|
print("❌ Configuration directory not found")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Configuration error: {e}")
|
|
return False
|
|
|
|
def test_directory_structure():
|
|
"""Test that all required directories exist."""
|
|
required_dirs = [
|
|
"src/backend",
|
|
"src/frontend",
|
|
"src/utils",
|
|
"tests",
|
|
"data",
|
|
"config",
|
|
"docs",
|
|
"photos",
|
|
"scripts",
|
|
"assets"
|
|
]
|
|
|
|
missing_dirs = []
|
|
for dir_path in required_dirs:
|
|
if not os.path.exists(dir_path):
|
|
missing_dirs.append(dir_path)
|
|
|
|
if missing_dirs:
|
|
print(f"❌ Missing directories: {missing_dirs}")
|
|
return False
|
|
else:
|
|
print("✅ All required directories exist")
|
|
return True
|
|
|
|
def test_steering_documents():
|
|
"""Test that steering documents exist."""
|
|
required_docs = [
|
|
"docs/product.md",
|
|
"docs/structure.md",
|
|
"docs/tech.md",
|
|
"docs/api-standards.md",
|
|
"docs/testing-standards.md",
|
|
"docs/code-conventions.md"
|
|
]
|
|
|
|
missing_docs = []
|
|
for doc_path in required_docs:
|
|
if not os.path.exists(doc_path):
|
|
missing_docs.append(doc_path)
|
|
|
|
if missing_docs:
|
|
print(f"❌ Missing steering documents: {missing_docs}")
|
|
return False
|
|
else:
|
|
print("✅ All steering documents exist")
|
|
return True
|
|
|
|
def test_main_app_file():
|
|
"""Test that the main application file exists and is accessible."""
|
|
try:
|
|
main_app_path = Path(__file__).parent.parent / "src" / "backend" / "app.py"
|
|
if main_app_path.exists():
|
|
print(f"✅ Main app file found: {main_app_path}")
|
|
|
|
# Test if we can read the file
|
|
with open(main_app_path, 'r') as f:
|
|
content = f.read()
|
|
if 'Flask' in content and 'app' in content:
|
|
print("✅ Main app file contains Flask app")
|
|
return True
|
|
else:
|
|
print("⚠️ Main app file exists but doesn't contain expected Flask content")
|
|
return True
|
|
else:
|
|
print("❌ Main app file not found")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Main app file error: {e}")
|
|
return False
|
|
|
|
def run_all_tests():
|
|
"""Run all tests and report results."""
|
|
print("🧪 Running PunimTag Test Suite")
|
|
print("=" * 50)
|
|
|
|
tests = [
|
|
test_imports,
|
|
test_database_connection,
|
|
test_face_recognition_import,
|
|
test_config_loading,
|
|
test_directory_structure,
|
|
test_steering_documents,
|
|
test_main_app_file
|
|
]
|
|
|
|
passed = 0
|
|
total = len(tests)
|
|
|
|
for test in tests:
|
|
try:
|
|
if test():
|
|
passed += 1
|
|
except Exception as e:
|
|
print(f"❌ Test {test.__name__} failed with exception: {e}")
|
|
|
|
print("=" * 50)
|
|
print(f"📊 Test Results: {passed}/{total} tests passed")
|
|
|
|
if passed == total:
|
|
print("🎉 All tests passed!")
|
|
return True
|
|
else:
|
|
print("⚠️ Some tests failed")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = run_all_tests()
|
|
sys.exit(0 if success else 1) |