#!/usr/bin/env python3 """ Simple API test to verify basic functionality """ import requests import time import subprocess import signal import os import sys # Test configuration API_BASE_URL = "http://localhost:8080" API_KEY = "mem0_dev_key_123456789" TEST_USER_ID = "simple_test_user" def test_api_basic(): """Simple API test to verify it's working""" print("=" * 50) print("๐Ÿงช SIMPLE MEM0 API TEST") print("=" * 50) # Start API server print("๐Ÿš€ Starting API server...") env = os.environ.copy() env.update({ "API_HOST": "localhost", "API_PORT": "8080", "API_KEYS": API_KEY, "ADMIN_API_KEYS": "mem0_admin_key_111222333" }) server_process = subprocess.Popen([ sys.executable, "start_api.py" ], env=env, cwd="/home/klas/mem0") # Wait for server to start print("โณ Waiting for server...") time.sleep(8) try: # Test health endpoint print("๐Ÿฅ Testing health endpoint...") response = requests.get(f"{API_BASE_URL}/health", timeout=5) if response.status_code == 200: print(" โœ… Health endpoint working") else: print(f" โŒ Health endpoint failed: {response.status_code}") return False # Test authenticated status endpoint print("๐Ÿ” Testing authenticated endpoint...") headers = {"Authorization": f"Bearer {API_KEY}"} response = requests.get(f"{API_BASE_URL}/status", headers=headers, timeout=5) if response.status_code == 200: print(" โœ… Authentication working") else: print(f" โŒ Authentication failed: {response.status_code}") return False # Test adding memory print("๐Ÿง  Testing memory addition...") memory_data = { "messages": [ {"role": "user", "content": "I enjoy Python programming and building APIs"} ], "user_id": TEST_USER_ID, "metadata": {"source": "simple_test"} } response = requests.post( f"{API_BASE_URL}/v1/memories", headers=headers, json=memory_data, timeout=10 ) if response.status_code == 200: data = response.json() if data.get("success"): print(" โœ… Memory addition working") else: print(f" โŒ Memory addition failed: {data}") return False else: print(f" โŒ Memory addition failed: {response.status_code}") try: print(f" Error: {response.json()}") except: print(f" Raw response: {response.text}") return False print("\n๐ŸŽ‰ Basic API tests passed!") return True except Exception as e: print(f"โŒ Test failed: {e}") return False finally: # Stop server print("๐Ÿ›‘ Stopping server...") server_process.terminate() server_process.wait() print("โœ… Server stopped") if __name__ == "__main__": os.chdir("/home/klas/mem0") success = test_api_basic() sys.exit(0 if success else 1)