Add API test script and update STATUS
- test_api.py: Automated API testing - STATUS.md: Phase 1 complete summary - Full communications module working - @grimlock AI mentions functional - Ready for WebSocket + frontend Run: python test_api.py to verify all APIs
This commit is contained in:
137
test_api.py
Executable file
137
test_api.py
Executable file
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Quick API test script for Grimlock
|
||||
Tests auth, channels, and messages
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
|
||||
BASE_URL = "http://localhost:8000"
|
||||
|
||||
def test_grimlock():
|
||||
print("=" * 60)
|
||||
print("GRIMLOCK API TEST")
|
||||
print("=" * 60)
|
||||
|
||||
# Health check
|
||||
print("\n1. Health check...")
|
||||
response = requests.get(f"{BASE_URL}/api/health")
|
||||
print(f" Status: {response.json()}")
|
||||
|
||||
# Register user
|
||||
print("\n2. Registering user...")
|
||||
user_data = {
|
||||
"email": "test@vectorzulu.com",
|
||||
"name": "Test User",
|
||||
"password": "testpass123",
|
||||
"role": "engineer"
|
||||
}
|
||||
response = requests.post(f"{BASE_URL}/api/auth/register", json=user_data)
|
||||
if response.status_code == 200:
|
||||
print(f" ✓ User registered: {response.json()['email']}")
|
||||
else:
|
||||
print(f" User may already exist (continuing)")
|
||||
|
||||
# Login
|
||||
print("\n3. Logging in...")
|
||||
login_data = {
|
||||
"email": "test@vectorzulu.com",
|
||||
"password": "testpass123"
|
||||
}
|
||||
response = requests.post(f"{BASE_URL}/api/auth/login", json=login_data)
|
||||
token = response.json()["access_token"]
|
||||
print(f" ✓ Logged in, got token")
|
||||
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
# Get user info
|
||||
print("\n4. Getting user info...")
|
||||
response = requests.get(f"{BASE_URL}/api/auth/me", headers=headers)
|
||||
user = response.json()
|
||||
print(f" ✓ User: {user['name']} ({user['role']})")
|
||||
|
||||
# Create channel
|
||||
print("\n5. Creating channel...")
|
||||
channel_data = {
|
||||
"name": "test-channel",
|
||||
"description": "Test channel for Grimlock",
|
||||
"type": "public"
|
||||
}
|
||||
response = requests.post(f"{BASE_URL}/api/channels/", json=channel_data, headers=headers)
|
||||
if response.status_code == 200:
|
||||
channel = response.json()
|
||||
channel_id = channel["id"]
|
||||
print(f" ✓ Created channel: #{channel['name']}")
|
||||
else:
|
||||
# Channel might exist, get it
|
||||
response = requests.get(f"{BASE_URL}/api/channels/", headers=headers)
|
||||
channels = response.json()
|
||||
channel = [c for c in channels if c["name"] == "test-channel"][0]
|
||||
channel_id = channel["id"]
|
||||
print(f" ✓ Using existing channel: #{channel['name']}")
|
||||
|
||||
# Send message
|
||||
print("\n6. Sending message...")
|
||||
message_data = {
|
||||
"content": "Hello Grimlock! This is a test message."
|
||||
}
|
||||
response = requests.post(
|
||||
f"{BASE_URL}/api/channels/{channel_id}/messages",
|
||||
json=message_data,
|
||||
headers=headers
|
||||
)
|
||||
message = response.json()
|
||||
print(f" ✓ Message sent: {message['content'][:50]}...")
|
||||
|
||||
# Send message with @grimlock mention
|
||||
print("\n7. Mentioning @grimlock...")
|
||||
message_data = {
|
||||
"content": "@grimlock What is Grimlock?"
|
||||
}
|
||||
response = requests.post(
|
||||
f"{BASE_URL}/api/channels/{channel_id}/messages",
|
||||
json=message_data,
|
||||
headers=headers
|
||||
)
|
||||
print(f" ✓ Mentioned @grimlock (AI response processing in background)")
|
||||
|
||||
# Wait a bit for AI response
|
||||
print("\n8. Waiting for AI response (5 seconds)...")
|
||||
time.sleep(5)
|
||||
|
||||
# Get messages
|
||||
print("\n9. Getting channel messages...")
|
||||
response = requests.get(
|
||||
f"{BASE_URL}/api/channels/{channel_id}/messages",
|
||||
headers=headers
|
||||
)
|
||||
messages = response.json()
|
||||
print(f" ✓ Got {len(messages)} messages:")
|
||||
for msg in messages[-3:]: # Show last 3
|
||||
sender = msg['user']['name'] if msg['user'] else "Grimlock"
|
||||
content = msg['content'][:60]
|
||||
print(f" [{sender}]: {content}...")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("✓ ALL TESTS PASSED!")
|
||||
print("=" * 60)
|
||||
print("\nGrimlock is working! Key features:")
|
||||
print(" - User authentication")
|
||||
print(" - Channel creation and membership")
|
||||
print(" - Message sending")
|
||||
print(" - @grimlock AI mentions")
|
||||
print("\nNext: Build the web interface!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
test_grimlock()
|
||||
except requests.exceptions.ConnectionError:
|
||||
print("\n❌ ERROR: Cannot connect to Grimlock backend")
|
||||
print(" Make sure the server is running:")
|
||||
print(" cd backend && uvicorn main:app --reload")
|
||||
except Exception as e:
|
||||
print(f"\n❌ ERROR: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
Reference in New Issue
Block a user