jobsearch-mcp-server / tests /test_remotive_debug.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.config import get_settings
import requests
import json
import time
# Load environment variables from .env file
load_dotenv()
def test_remotive_api_directly():
"""Test Remotive API directly to debug timeout issues."""
settings = get_settings()
print(f"πŸ” Testing Remotive API directly...")
print(f"🌐 API URL: {settings.remotive_api_url}")
# Test different search parameters and timeouts
test_cases = [
{"search": "software engineer", "location": "london", "timeout": 30},
{"search": "python", "location": "remote", "timeout": 30},
{"search": "software", "location": "", "timeout": 30}, # No location filter
{"search": "", "location": "", "timeout": 30}, # No filters - get all jobs
]
for i, test_case in enumerate(test_cases, 1):
print(
f"\nπŸ“‹ Test {i}: search='{test_case['search']}', location='{test_case['location']}', timeout={test_case['timeout']}s"
)
try:
params = {}
if test_case["search"]:
params["search"] = test_case["search"]
if test_case["location"]:
params["location"] = test_case["location"]
print(f" πŸ“‹ Parameters: {params}")
start_time = time.time()
response = requests.get(
settings.remotive_api_url, params=params, timeout=test_case["timeout"]
)
end_time = time.time()
response_time = end_time - start_time
print(f" ⏱️ Response time: {response_time:.2f}s")
if response.status_code == 200:
data = response.json()
jobs = data.get("jobs", [])
print(f" βœ… Status: {response.status_code} | Found: {len(jobs)} jobs")
if jobs:
sample_job = jobs[0]
print(
f" πŸ“‹ Sample: '{sample_job.get('title', 'N/A')}' at '{sample_job.get('company_name', 'N/A')}' in '{sample_job.get('candidate_required_location', 'N/A')}'"
)
break # Found some results, stop testing
else:
print(f" ⚠️ Response OK but no jobs in results")
print(f" πŸ“„ Response keys: {list(data.keys())}")
else:
print(
f" ❌ Status: {response.status_code} | Error: {response.text[:100]}"
)
except requests.exceptions.Timeout:
print(f" ⏱️ TIMEOUT after {test_case['timeout']}s")
except Exception as e:
print(f" πŸ’₯ Exception: {str(e)}")
def test_remotive_simple():
"""Simple test without any parameters."""
settings = get_settings()
print(f"\nπŸ” Testing Remotive API with no parameters (should be fastest)...")
try:
start_time = time.time()
response = requests.get(settings.remotive_api_url, timeout=30)
end_time = time.time()
response_time = end_time - start_time
print(f"⏱️ Response time: {response_time:.2f}s")
if response.status_code == 200:
data = response.json()
jobs = data.get("jobs", [])
print(f"βœ… Success! Found {len(jobs)} total jobs available")
if jobs:
print(
f"πŸ“‹ First job: '{jobs[0].get('title', 'N/A')}' at '{jobs[0].get('company_name', 'N/A')}'"
)
else:
print(f"❌ Status: {response.status_code}")
print(f"πŸ“„ Response: {response.text[:200]}")
except Exception as e:
print(f"πŸ’₯ Exception: {str(e)}")
if __name__ == "__main__":
test_remotive_simple()
test_remotive_api_directly()