173 lines
5.5 KiB
Python
173 lines
5.5 KiB
Python
#!/usr/bin/env python
|
||
"""
|
||
Configuration Test Script for GPTEdit
|
||
Tests that all configuration options are working correctly
|
||
"""
|
||
|
||
import sys
|
||
import os
|
||
from pathlib import Path
|
||
from datetime import datetime
|
||
|
||
# Add project root to path
|
||
project_root = Path(__file__).parent
|
||
sys.path.insert(0, str(project_root))
|
||
|
||
|
||
def test_configuration():
|
||
"""Test configuration loading and validation"""
|
||
print("=" * 60)
|
||
print("GPTEdit Configuration Test")
|
||
print("=" * 60)
|
||
|
||
try:
|
||
from src.connector.config import Config
|
||
|
||
# Load configuration
|
||
print("\n1. Loading configuration...")
|
||
config = Config()
|
||
print("✓ Configuration loaded")
|
||
|
||
# Display configuration
|
||
print("\n2. Current Configuration:")
|
||
print("-" * 40)
|
||
print(config)
|
||
print("-" * 40)
|
||
|
||
# Validate configuration
|
||
print("\n3. Validating configuration...")
|
||
if config.validate():
|
||
print("✓ Configuration is valid")
|
||
else:
|
||
print("✗ Configuration validation failed")
|
||
return False
|
||
|
||
# Test directories
|
||
print("\n4. Testing directories:")
|
||
|
||
# Output directory
|
||
if config.edited_images_path.exists():
|
||
print(f"✓ Output directory exists: {config.edited_images_path}")
|
||
|
||
# Test write permission
|
||
test_file = config.edited_images_path / "test_write.tmp"
|
||
try:
|
||
test_file.write_text("test")
|
||
test_file.unlink()
|
||
print(" ✓ Write permission confirmed")
|
||
except Exception as e:
|
||
print(f" ✗ Cannot write to output directory: {e}")
|
||
else:
|
||
print(f"✗ Output directory not found: {config.edited_images_path}")
|
||
|
||
# Temp directory
|
||
if config.temp_path.exists():
|
||
print(f"✓ Temp directory exists: {config.temp_path}")
|
||
else:
|
||
print(f"✗ Temp directory not found: {config.temp_path}")
|
||
|
||
# Test file naming
|
||
print("\n5. Testing file naming:")
|
||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||
test_filename = config.output_filename_format.format(
|
||
prefix=config.output_filename_prefix,
|
||
timestamp=timestamp
|
||
)
|
||
print(f" Sample filename: {test_filename}")
|
||
|
||
# Test API key
|
||
print("\n6. API Key Status:")
|
||
if config.api_key:
|
||
if config.api_key.startswith('sk-'):
|
||
print(f" ✓ API key configured (ends with ...{config.api_key[-4:]})")
|
||
else:
|
||
print(" ⚠ API key doesn't start with 'sk-' - might be invalid")
|
||
else:
|
||
print(" ✗ API key not set")
|
||
print(" Please set OPENAI_API_KEY in .env file or environment")
|
||
|
||
# Test feature flags
|
||
print("\n7. Feature Flags:")
|
||
print(f" Auto-optimize: {config.enable_auto_optimize}")
|
||
print(f" Auto-mask: {config.enable_auto_mask}")
|
||
print(f" Save originals: {config.save_originals}")
|
||
|
||
# Test image size limits
|
||
print("\n8. Image Processing Settings:")
|
||
print(f" Max image size: {config.max_image_size_mb} MB")
|
||
print(f" Max bytes: {config.get_max_image_size_bytes():,}")
|
||
|
||
print("\n" + "=" * 60)
|
||
print("✅ Configuration test completed successfully!")
|
||
print("=" * 60)
|
||
|
||
return True
|
||
|
||
except ImportError as e:
|
||
print(f"\n✗ Import error: {e}")
|
||
print(" Make sure you're in the gptedit directory")
|
||
return False
|
||
except Exception as e:
|
||
print(f"\n✗ Unexpected error: {e}")
|
||
import traceback
|
||
traceback.print_exc()
|
||
return False
|
||
|
||
|
||
def test_env_file():
|
||
"""Check .env file status"""
|
||
print("\n" + "=" * 60)
|
||
print("Environment File Check")
|
||
print("=" * 60)
|
||
|
||
env_path = Path(".env")
|
||
env_example_path = Path(".env.example")
|
||
|
||
if env_path.exists():
|
||
print("✓ .env file exists")
|
||
|
||
# Check if it has API key
|
||
with open(env_path, 'r') as f:
|
||
content = f.read()
|
||
if 'OPENAI_API_KEY=' in content:
|
||
if 'your-api-key-here' in content:
|
||
print("⚠ .env contains placeholder API key")
|
||
print(" Please update with your actual OpenAI API key")
|
||
else:
|
||
print("✓ .env contains API key configuration")
|
||
else:
|
||
print("✗ .env file not found")
|
||
if env_example_path.exists():
|
||
print(" ℹ .env.example exists - copy it to .env:")
|
||
print(" cp .env.example .env")
|
||
print(" Then edit .env with your API key")
|
||
else:
|
||
print(" ✗ .env.example also missing")
|
||
|
||
|
||
def main():
|
||
"""Run all configuration tests"""
|
||
print("\n🔧 GPTEdit Configuration Tester\n")
|
||
|
||
# Test environment file
|
||
test_env_file()
|
||
|
||
# Test configuration
|
||
if test_configuration():
|
||
print("\n✅ All configuration tests passed!")
|
||
print("\nYou can now:")
|
||
print("1. Start the server: python main.py")
|
||
print("2. Or configure Claude Desktop with the settings shown above")
|
||
return 0
|
||
else:
|
||
print("\n❌ Configuration tests failed")
|
||
print("\nPlease:")
|
||
print("1. Create a .env file from .env.example")
|
||
print("2. Add your OpenAI API key")
|
||
print("3. Check directory permissions")
|
||
return 1
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|