LinkDesk/backend/test_notifications.py

96 lines
2.9 KiB
Python

"""
Test script for notification system.
"""
import requests
import json
BASE_URL = "http://localhost:8000"
def test_notifications():
"""Test notification endpoints."""
# Login first
print("1. Logging in...")
login_response = requests.post(
f"{BASE_URL}/auth/login",
data={
"username": "admin@example.com",
"password": "admin123"
}
)
if login_response.status_code != 200:
print(f"❌ Login failed: {login_response.status_code}")
print(login_response.text)
return
token = login_response.json()["access_token"]
headers = {"Authorization": f"Bearer {token}"}
print("✅ Login successful")
# Get notifications
print("\n2. Getting notifications...")
notifications_response = requests.get(
f"{BASE_URL}/notifications",
headers=headers
)
if notifications_response.status_code == 200:
notifications = notifications_response.json()
print(f"✅ Got {len(notifications)} notifications")
if notifications:
print(f" First notification: {notifications[0]['title']}")
else:
print(f"❌ Failed to get notifications: {notifications_response.status_code}")
print(notifications_response.text)
# Get notification stats
print("\n3. Getting notification stats...")
stats_response = requests.get(
f"{BASE_URL}/notifications/stats",
headers=headers
)
if stats_response.status_code == 200:
stats = stats_response.json()
print(f"✅ Stats: {stats['total']} total, {stats['unread']} unread")
else:
print(f"❌ Failed to get stats: {stats_response.status_code}")
# Get notification preferences
print("\n4. Getting notification preferences...")
prefs_response = requests.get(
f"{BASE_URL}/notifications/preferences",
headers=headers
)
if prefs_response.status_code == 200:
prefs = prefs_response.json()
print(f"✅ Preferences loaded")
print(f" Email enabled: {prefs['email_enabled']}")
print(f" In-app enabled: {prefs['inapp_enabled']}")
else:
print(f"❌ Failed to get preferences: {prefs_response.status_code}")
# Get recent activities
print("\n5. Getting recent activities...")
activities_response = requests.get(
f"{BASE_URL}/activities/recent",
headers=headers
)
if activities_response.status_code == 200:
activities = activities_response.json()
print(f"✅ Got {len(activities)} recent activities")
if activities:
print(f" First activity: {activities[0]['description']}")
else:
print(f"❌ Failed to get activities: {activities_response.status_code}")
print(activities_response.text)
print("\n✅ All tests completed!")
if __name__ == "__main__":
test_notifications()