Files
syops/backend/tests/manual_test_agent.py

72 lines
2.3 KiB
Python

import requests
import json
import sys
BASE_URL = "http://127.0.0.1:5001/api"
HEADERS = {
"X-Username": "admin",
"X-Role": "admin",
"Content-Type": "application/json"
}
def test_create_iframe_agent():
print("\n--- Testing Iframe Agent Creation ---")
payload = {
"name": "Test Iframe Agent",
"type": "iframe",
"description": "Auto-test Iframe Agent",
"extra_config": {
"iframe_url": "http://192.168.100.230:8882/chatbot/imrmbYyasJUHjXQg"
}
}
try:
response = requests.post(f"{BASE_URL}/admin/agents", headers=HEADERS, json=payload)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
if response.status_code == 201:
print("SUCCESS: Iframe Agent created")
return response.json()['id']
else:
print("FAILURE: Could not create Iframe Agent")
sys.exit(1)
except Exception as e:
print(f"ERROR: {e}")
sys.exit(1)
def test_create_api_agent():
print("\n--- Testing API Agent Creation ---")
payload = {
"name": "Test API Agent",
"type": "api",
"description": "Auto-test API Agent",
"dify_app_id": "test-app-id-123", # Dummy ID for testing constraint
"dify_api_key": "app-xdiejQibWQy8ZQWXcdxJjS9I",
"api_base_url": "http://127.0.0.1:5001/v1"
}
try:
response = requests.post(f"{BASE_URL}/admin/agents", headers=HEADERS, json=payload)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
if response.status_code == 201:
print("SUCCESS: API Agent created")
return response.json()['id']
else:
# Handle unique constraint if it already exists from previous run
if "integrity error" in response.text.lower() or "unique" in response.text.lower():
print("WARNING: Agent likely already exists (Integrity Error).")
else:
print("FAILURE: Could not create API Agent")
sys.exit(1)
except Exception as e:
print(f"ERROR: {e}")
sys.exit(1)
if __name__ == "__main__":
iframe_id = test_create_iframe_agent()
api_id = test_create_api_agent()
print("\nAll automated tests passed!")