Files
Onyva-Postling/scripts/test_linkedin_setup.py
Ruben Fischer f14515e9cf Major updates: LinkedIn auto-posting, timezone fixes, and Docker improvements
Features:
- Add LinkedIn OAuth integration and auto-posting functionality
- Add scheduler service for automated post publishing
- Add metadata field to generated_posts for LinkedIn URLs
- Add privacy policy page for LinkedIn API compliance
- Add company management features and employee accounts
- Add license key system for company registrations

Fixes:
- Fix timezone issues (use UTC consistently across app)
- Fix datetime serialization errors in database operations
- Fix scheduling timezone conversion (local time to UTC)
- Fix import errors (get_database -> db)

Infrastructure:
- Update Docker setup to use port 8001 (avoid conflicts)
- Add SSL support with nginx-proxy and Let's Encrypt
- Add LinkedIn setup documentation
- Add migration scripts for schema updates

Services:
- Add linkedin_service.py for LinkedIn API integration
- Add scheduler_service.py for background job processing
- Add storage_service.py for Supabase Storage
- Add email_service.py improvements
- Add encryption utilities for token storage

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-11 11:30:20 +01:00

132 lines
3.6 KiB
Python

#!/usr/bin/env python3
"""
Test script to verify LinkedIn auto-posting setup.
Usage:
python scripts/test_linkedin_setup.py
"""
import asyncio
import sys
from pathlib import Path
# Add project root to path
sys.path.insert(0, str(Path(__file__).parent.parent))
from src.config import settings
from src.database.client import db
async def main():
"""Run setup checks."""
print("=" * 70)
print("LinkedIn Auto-Posting Setup Verification")
print("=" * 70)
print()
checks_passed = 0
checks_total = 0
# Check 1: Environment variables
print("📋 Checking environment variables...")
checks_total += 4
if settings.linkedin_client_id:
print(" ✅ LINKEDIN_CLIENT_ID is set")
checks_passed += 1
else:
print(" ❌ LINKEDIN_CLIENT_ID is missing")
if settings.linkedin_client_secret:
print(" ✅ LINKEDIN_CLIENT_SECRET is set")
checks_passed += 1
else:
print(" ❌ LINKEDIN_CLIENT_SECRET is missing")
if settings.linkedin_redirect_uri:
print(" ✅ LINKEDIN_REDIRECT_URI is set")
checks_passed += 1
print(f" URI: {settings.linkedin_redirect_uri}")
else:
print(" ❌ LINKEDIN_REDIRECT_URI is missing")
if settings.encryption_key:
print(" ✅ ENCRYPTION_KEY is set")
checks_passed += 1
else:
print(" ❌ ENCRYPTION_KEY is missing")
print()
# Check 2: Encryption
print("🔐 Testing encryption...")
checks_total += 1
try:
from src.utils.encryption import encrypt_token, decrypt_token
test_token = "test_access_token_12345"
encrypted = encrypt_token(test_token)
decrypted = decrypt_token(encrypted)
if decrypted == test_token:
print(" ✅ Encryption/decryption working")
checks_passed += 1
else:
print(" ❌ Encryption/decryption mismatch")
except Exception as e:
print(f" ❌ Encryption error: {e}")
print()
# Check 3: Database table
print("💾 Checking database schema...")
checks_total += 1
try:
# Try to query the table (will fail if it doesn't exist)
result = await asyncio.to_thread(
lambda: db.client.table("linkedin_accounts").select("id").limit(0).execute()
)
print(" ✅ linkedin_accounts table exists")
checks_passed += 1
except Exception as e:
print(f" ❌ linkedin_accounts table not found: {e}")
print(" Run: psql $DATABASE_URL -f config/migrate_add_linkedin_accounts.sql")
print()
# Check 4: LinkedIn service
print("🔧 Checking LinkedIn service...")
checks_total += 1
try:
from src.services.linkedin_service import linkedin_service
print(" ✅ LinkedIn service initialized")
checks_passed += 1
except Exception as e:
print(f" ❌ LinkedIn service error: {e}")
print()
# Summary
print("=" * 70)
print(f"Summary: {checks_passed}/{checks_total} checks passed")
print("=" * 70)
if checks_passed == checks_total:
print("✅ All checks passed! LinkedIn auto-posting is ready.")
print("\nNext steps:")
print("1. Restart your application")
print("2. Log in as an employee")
print("3. Go to Settings and connect your LinkedIn account")
print("4. Schedule a test post")
return 0
else:
print("❌ Some checks failed. Please fix the issues above.")
print("\nSetup guide: See LINKEDIN_SETUP.md for detailed instructions")
return 1
if __name__ == "__main__":
exit_code = asyncio.run(main())
sys.exit(exit_code)