"""Complete API test with user creation flow.""" import requests import json import sys BASE_URL = "http://localhost:8000" print("="*60) print("PROJECT MEMORY - COMPLETE API TEST") print("="*60) def test_api(): # Check if server is running try: response = requests.get(f"{BASE_URL}/") print(f"✓ Server is running: {response.json()['message']}") except: print("❌ Server is not running!") print("Start it with: uvicorn app.main:app --reload") return print("\n" + "="*60) print("1. CREATE USER") print("="*60) # Create a new user user_data = { "firstName": "John", "lastName": "Doe", "avatar_url": "https://example.com/avatar.jpg" } print(f"POST /api/users") print(f"Body: {json.dumps(user_data, indent=2)}") response = requests.post(f"{BASE_URL}/api/users", json=user_data) print(f"Status: {response.status_code}") if response.status_code != 200: print(f"Error: {response.text}") return user = response.json() user_id = user["id"] print(f"✓ Created user: {user_id}") print(f"Response: {json.dumps(user, indent=2)}") print("\n" + "="*60) print("2. GET USER") print("="*60) print(f"GET /api/users/{user_id}") response = requests.get(f"{BASE_URL}/api/users/{user_id}") print(f"Status: {response.status_code}") print(f"Response: {json.dumps(response.json(), indent=2)}") print("\n" + "="*60) print("3. LIST ALL USERS") print("="*60) print(f"GET /api/users") response = requests.get(f"{BASE_URL}/api/users") print(f"Status: {response.status_code}") users = response.json() print(f"Total users: {len(users)}") for u in users[:3]: # Show first 3 users print(f" - {u['firstName']} {u['lastName']} ({u['id']})") print("\n" + "="*60) print("4. CREATE PROJECT") print("="*60) project_data = { "name": "Test Project", "description": "API Testing Project", "userId": user_id } print(f"POST /api/projects") print(f"Body: {json.dumps(project_data, indent=2)}") response = requests.post(f"{BASE_URL}/api/projects", json=project_data) print(f"Status: {response.status_code}") if response.status_code != 200: print(f"Error: {response.text}") return project = response.json() project_id = project["id"] print(f"✓ Created project: {project_id}") print("\n" + "="*60) print("5. LIST USER'S PROJECTS") print("="*60) print(f"GET /api/projects?userId={user_id}") response = requests.get(f"{BASE_URL}/api/projects?userId={user_id}") print(f"Status: {response.status_code}") projects = response.json() print(f"User has {len(projects)} project(s)") print("\n" + "="*60) print("6. CREATE TASK") print("="*60) task_data = { "title": "Implement user authentication", "description": "Add login and registration features", "assignedTo": user_id } print(f"POST /api/projects/{project_id}/tasks") print(f"Body: {json.dumps(task_data, indent=2)}") response = requests.post(f"{BASE_URL}/api/projects/{project_id}/tasks", json=task_data) print(f"Status: {response.status_code}") if response.status_code != 200: print(f"Error: {response.text}") return task = response.json() task_id = task["id"] print(f"✓ Created task: {task_id}") print("\n" + "="*60) print("7. LIST TASKS") print("="*60) print(f"GET /api/projects/{project_id}/tasks") response = requests.get(f"{BASE_URL}/api/projects/{project_id}/tasks") print(f"Status: {response.status_code}") tasks = response.json() print(f"Project has {len(tasks)} task(s)") print("\n" + "="*60) print("8. COMPLETE TASK (with AI documentation)") print("="*60) complete_data = { "userId": user_id, "whatIDid": "Implemented OAuth2 authentication with JWT tokens", "codeSnippet": "def authenticate(token): return jwt.decode(token, SECRET_KEY)" } print(f"POST /api/tasks/{task_id}/complete") print(f"Body: {json.dumps(complete_data, indent=2)}") print("⏳ This will call Gemini AI to generate documentation...") response = requests.post(f"{BASE_URL}/api/tasks/{task_id}/complete", json=complete_data) print(f"Status: {response.status_code}") if response.status_code == 200: print(f"✓ Task completed with AI documentation") print(f"Response: {json.dumps(response.json(), indent=2)}") else: print(f"Note: Task completion requires GEMINI_API_KEY in .env") print(f"Response: {response.text}") print("\n" + "="*60) print("9. GET ACTIVITY FEED") print("="*60) print(f"GET /api/projects/{project_id}/activity") response = requests.get(f"{BASE_URL}/api/projects/{project_id}/activity") print(f"Status: {response.status_code}") if response.status_code == 200: activity = response.json() print(f"Activity entries: {len(activity)}") print("\n" + "="*60) print("TEST COMPLETE - ALL ENDPOINTS WORKING!") print("="*60) print(f""" SUMMARY OF CREATED DATA: - User ID: {user_id} - Project ID: {project_id} - Task ID: {task_id} You can now use these IDs to test other endpoints! """) print("="*60) print("CURL EXAMPLES WITH YOUR DATA") print("="*60) print(f""" # Create another user curl -X POST {BASE_URL}/api/users \\ -H "Content-Type: application/json" \\ -d '{{"firstName": "Jane", "lastName": "Smith"}}' # Get your user curl {BASE_URL}/api/users/{user_id} # List all users curl {BASE_URL}/api/users # Create another project curl -X POST {BASE_URL}/api/projects \\ -H "Content-Type: application/json" \\ -d '{{"name": "Another Project", "description": "Description", "userId": "{user_id}"}}' # Join a project (create a second user first) curl -X POST {BASE_URL}/api/projects/{project_id}/join \\ -H "Content-Type: application/json" \\ -d '{{"userId": "ANOTHER_USER_ID"}}' # Search project memory (after completing tasks) curl -X POST {BASE_URL}/api/projects/{project_id}/search \\ -H "Content-Type: application/json" \\ -d '{{"query": "authentication"}}' """) if __name__ == "__main__": test_api()