#!/usr/bin/env python3 """ Test script for LinkedIn service functionality. This script tests that the LinkedIn service can be initialized and basic functionality works without errors. Usage: python test_linkedin_service.py """ import asyncio import sys import os from pathlib import Path # Add the backend directory to the Python path backend_dir = Path(__file__).parent sys.path.insert(0, str(backend_dir)) from loguru import logger from models.linkedin_models import LinkedInPostRequest, GroundingLevel from services.linkedin_service import LinkedInService async def test_linkedin_service(): """Test the LinkedIn service functionality.""" try: logger.info("๐Ÿงช Testing LinkedIn Service Functionality") # Initialize the service logger.info("๐Ÿ“ฆ Initializing LinkedIn Service...") service = LinkedInService() logger.info("โœ… LinkedIn Service initialized successfully") # Create a test request test_request = LinkedInPostRequest( topic="AI in Marketing", industry="Technology", tone="professional", max_length=500, target_audience="Marketing professionals", key_points=["AI automation", "Personalization", "ROI improvement"], research_enabled=True, search_engine="google", grounding_level=GroundingLevel.BASIC, include_citations=True ) logger.info("๐Ÿ“ Testing LinkedIn Post Generation...") # Test post generation response = await service.generate_linkedin_post(test_request) if response.success: logger.info("โœ… LinkedIn post generation successful") logger.info(f"๐Ÿ“Š Content length: {len(response.data.content)} characters") logger.info(f"๐Ÿ”— Sources: {len(response.research_sources)}") logger.info(f"๐Ÿ“š Citations: {len(response.data.citations)}") logger.info(f"๐Ÿ† Quality score: {response.data.quality_metrics.overall_score if response.data.quality_metrics else 'N/A'}") # Display a snippet of the generated content content_preview = response.data.content[:200] + "..." if len(response.data.content) > 200 else response.data.content logger.info(f"๐Ÿ“„ Content preview: {content_preview}") else: logger.error(f"โŒ LinkedIn post generation failed: {response.error}") return False logger.info("๐ŸŽ‰ LinkedIn service test completed successfully!") return True except Exception as e: logger.error(f"โŒ LinkedIn service test failed: {str(e)}") return False async def main(): """Main test function.""" logger.info("๐Ÿš€ Starting LinkedIn Service Test") logger.info("=" * 50) success = await test_linkedin_service() if success: logger.info("\n๐ŸŽ‰ SUCCESS: LinkedIn service is working correctly!") logger.info("โœ… Service initialization successful") logger.info("โœ… Post generation working") logger.info("โœ… Ready for production use") else: logger.error("\nโŒ FAILURE: LinkedIn service test failed") sys.exit(1) if __name__ == "__main__": # Configure logging logger.remove() logger.add( sys.stderr, format="{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {name}:{function}:{line} - {message}", level="INFO" ) # Run the test asyncio.run(main())