import asyncio
import json
import sys
import os
# Add current directory to sys.path to ensure tools can be imported
sys.path.append(os.getcwd())
from tools.instagram_engine import execute
async def test_instagram_engine():
print("Starting test for instagram_engine...")
# Test case 1: Scrape a known public profile (e.g., 'natgeo')
params_success = {
"action": "scrape",
"username": "natgeo",
"limit": 1
}
print(f"Testing with params: {params_success}")
try:
result_str = await execute(params_success)
result = json.loads(result_str)
print("Result received successfully.")
print(json.dumps(result, indent=2))
if result.get("status") == "success":
print("Test Case 1 (Success Path): PASSED")
elif result.get("status") == "error":
print(f"Test Case 1 (Success Path): FAILED with error: {result.get('message')}")
else:
print(f"Test Case 1 (Success Path): FAILED (Unknown status)")
except Exception as e:
print(f"Test Case 1 (Success Path): FAILED with exception: {e}")
# Test case 2: Invalid action
params_invalid_action = {
"action": "delete",
"username": "natgeo"
}
print(f"\nTesting with invalid action: {params_invalid_action}")
try:
result_str = await execute(params_invalid_action)
result = json.loads(result_str)
if "error" in result:
print("Test Case 2 (Invalid Action): PASSED")
else:
print(f"Test Case 2 (Invalid Action): FAILED (Expected error, got: {result})")
except Exception as e:
print(f"Test Case 2 (Invalid/Invalid Action): FAILED with exception: {e}")
# Test case 3: Missing username
params_missing_username = {
"action": "scrape"
}
print(f"\nTesting with missing username: {params_missing_username}")
try:
result_str = await execute(params_missing_username)
result = json.loads(result_str)
if "error" in result:
print("Test Case 3 (Missing Username): PASSED")
else:
print(f"Test Case 3 (Missing Username): FAILED (Expected error, got: {result})")
except Exception as e:
print(f"Test Case 3 (Missing Username): FAILED with exception: {e}")
if __name__ == "__main__":
asyncio.run(test_instagram_engine())