cardserver / tests /test_config.py
GitHub Actions
πŸš€ Auto-deploy from GitHub
63b8c2c
#!/usr/bin/env python3
"""
Test script to verify configuration paths and directory structure.
Run this before deployment to catch path issues early.
"""
import sys
from pathlib import Path
# Add the cardserver directory to the path so we can import our modules
sys.path.insert(0, str(Path(__file__).parent.parent))
try:
from app.core.config import settings
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def test_paths():
"""Test all configured paths and create directories if needed."""
logger.info("Testing configuration paths...")
logger.info(f"Current working directory: {Path.cwd()}")
logger.info(f"Script location: {Path(__file__).resolve()}")
paths_to_test = [
("Model Path", settings.resolved_model_path),
("Generated Images Path", settings.resolved_generated_path),
("Base Images Path", settings.resolved_base_path),
("Symbols Path", settings.resolved_symbols_path),
("QR Codes Path", settings.resolved_qr_code_path),
("Static Files Mount Dir", settings.resolved_static_files_mount_dir),
("Default Font Path", settings.resolved_default_font_path.parent), # Font directory
]
success = True
for name, path in paths_to_test:
logger.info(f"\nTesting {name}: {path}")
if path.exists():
logger.info(f" βœ… EXISTS: {path}")
else:
logger.warning(f" ❌ MISSING: {path}")
try:
# Try to create the directory
if name != "Default Font Path": # Don't create font file, just directory
path.mkdir(parents=True, exist_ok=True)
logger.info(f" βœ… CREATED: {path}")
else:
path.mkdir(parents=True, exist_ok=True)
logger.info(f" βœ… CREATED FONT DIR: {path}")
except Exception as e:
logger.error(f" ❌ FAILED TO CREATE: {path} - {e}")
success = False
# Check if it's readable/writable
try:
if path.exists():
if path.is_dir():
# Test write access
test_file = path / "test_write.tmp"
test_file.write_text("test")
test_file.unlink()
logger.info(f" βœ… WRITABLE: {path}")
elif path.is_file():
logger.info(f" βœ… READABLE: {path}")
except Exception as e:
logger.error(f" ❌ NO WRITE ACCESS: {path} - {e}")
success = False
return success
if __name__ == "__main__":
logger.info("=== PATH CONFIGURATION TEST ===")
success = test_paths()
if success:
logger.info("\nβœ… All paths are configured correctly!")
sys.exit(0)
else:
logger.error("\n❌ Some paths have issues. Check the logs above.")
sys.exit(1)
except ImportError as e:
print(f"❌ Failed to import configuration: {e}")
print("Make sure you're running this from the cardserver directory")
sys.exit(1)
except Exception as e:
print(f"❌ Unexpected error: {e}")
sys.exit(1)