jobsearch-mcp-server / tests /test_job_search.py
daniielyan's picture
πŸ” Add debug logging to JobSearchService for Remotive API responses, including URL, parameters, job count, and error handling.
9e0d988
from dotenv import load_dotenv
from src.services.job_search_service import JobSearchService
from src.services.profile_service import ProfileService
from src.config import get_settings
import json
import os
# Load environment variables from .env file
load_dotenv()
# Debug: Check if Adzuna credentials are loaded
settings = get_settings()
print(
f"πŸ” Debug - Adzuna App ID: {'βœ… Set' if settings.adzuna_app_id else '❌ Not set'}"
)
print(
f"πŸ” Debug - Adzuna App Key: {'βœ… Set' if settings.adzuna_app_key else '❌ Not set'}"
)
print(f"πŸ” Debug - Adzuna Country: {settings.adzuna_country}")
# Environment variables check
print(
f"πŸ” Debug - ADZUNA_APP_ID env: {'βœ… Set' if os.getenv('ADZUNA_APP_ID') else '❌ Not set'}"
)
print(
f"πŸ” Debug - ADZUNA_APP_KEY env: {'βœ… Set' if os.getenv('ADZUNA_APP_KEY') else '❌ Not set'}"
)
# Initialize services
jb = JobSearchService()
profile_service = ProfileService()
# Create a sample user profile first (required for job search)
user_id = "test_user_001"
profile_data = {
"skills": ["Python", "JavaScript", "React", "Node.js", "AWS"],
"career_goals": "Software Engineer seeking remote opportunities in full-stack development",
"location": "Remote",
"resume": "Experienced software developer with 5+ years in web development, API design, and cloud platforms",
"salary_wish": "$80,000 - $120,000",
}
# Create user profile
print("Creating user profile...")
profile_result = profile_service.upsert_profile(user_id, json.dumps(profile_data))
print(f"Profile created: {profile_result}")
# Search parameters
search_query = "software engineer"
location = "london"
job_type = "full-time"
print(f"\nπŸ” Searching for '{search_query}' jobs in '{location}' ({job_type})...")
print("=" * 60)
# Run job search (this will fetch from both Remotive and Adzuna)
search_results = jb.search_jobs(
user_id=user_id, query=search_query, location=location, job_type=job_type
)
# Display results
if search_results.get("success"):
jobs = search_results.get("jobs", [])
total_found = search_results.get("total_found", 0)
print(f"βœ… Found {total_found} jobs")
print(f"πŸ“Š Search parameters: {search_results.get('search_params', {})}")
# Group jobs by source
remotive_jobs = [job for job in jobs if job.get("source") == "remotive"]
adzuna_jobs = [job for job in jobs if job.get("source") == "adzuna"]
sample_jobs = [job for job in jobs if job.get("source") == "sample"]
print(f"\nπŸ“ˆ Results breakdown:")
print(f" β€’ Remotive jobs: {len(remotive_jobs)}")
print(f" β€’ Adzuna jobs: {len(adzuna_jobs)}")
print(f" β€’ Sample jobs: {len(sample_jobs)}")
# Display top jobs from each source
print(f"\nπŸ† TOP REMOTIVE JOBS:")
print("-" * 40)
for i, job in enumerate(remotive_jobs[:3], 1):
print(f"{i}. {job['title']} at {job['company']}")
print(f" πŸ“ {job['location']}")
print(f" 🎯 Fit Score: {job['fit_score']}%")
print(f" πŸ”— {job['url']}")
print()
print(f"\nπŸ† TOP ADZUNA JOBS:")
print("-" * 40)
for i, job in enumerate(adzuna_jobs[:3], 1):
print(f"{i}. {job['title']} at {job['company']}")
print(f" πŸ“ {job['location']}")
print(f" 🎯 Fit Score: {job['fit_score']}%")
print(f" πŸ”— {job['url']}")
print()
# Save detailed results to file
with open("job_search_results.json", "w", encoding="utf-8") as f:
json.dump(search_results, f, indent=2, default=str)
print(f"πŸ’Ύ Detailed results saved to 'job_search_results.json'")
else:
print(f"❌ Search failed: {search_results.get('message', 'Unknown error')}")