#!/usr/bin/env python3 """ Quick test script to verify R2 connection and list templates Run this to test if R2 credentials are working before Docker build """ import os import sys from dotenv import load_dotenv # Load environment variables load_dotenv() # Add backend to path sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend')) try: from app.services.r2_service import r2_service print("🔍 Testing Cloudflare R2 Connection...\n") # Test 1: List templates print("📝 Test 1: Listing templates from R2...") templates = r2_service.list_templates() if templates: print(f"✅ SUCCESS! Found {len(templates)} template(s):") for template in templates: print(f" - {template}") else: print("⚠️ No templates found (this might be expected if bucket is empty)") print("\n" + "="*50 + "\n") # Test 2: List converted resumes print("📄 Test 2: Listing converted resumes from R2...") resumes = r2_service.list_converted_resumes(limit=5) if resumes: print(f"✅ SUCCESS! Found {len(resumes)} resume(s):") for resume in resumes[:5]: # Show first 5 print(f" - {resume['name']} ({resume['size']} bytes)") else: print("⚠️ No converted resumes found (this might be expected)") print("\n" + "="*50 + "\n") print("✅ R2 Connection Test Complete!") print("\nYou can now run: docker-compose up --build") except ImportError as e: print(f"❌ Import Error: {e}") print("\nThis is expected if you haven't installed backend dependencies yet.") print("Docker will handle this automatically during build.") except Exception as e: print(f"❌ Error: {e}") print("\nCheck your R2 credentials in .env file") sys.exit(1)