77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
"""
|
|
Test script for task status endpoint error cases
|
|
"""
|
|
import requests
|
|
import json
|
|
|
|
BASE_URL = "http://localhost:8000"
|
|
|
|
def test_nonexistent_project():
|
|
"""Test accessing task statuses for a non-existent project"""
|
|
|
|
# Login
|
|
login_response = requests.post(
|
|
f"{BASE_URL}/auth/login",
|
|
json={
|
|
"email": "admin@vfx.com",
|
|
"password": "admin123"
|
|
}
|
|
)
|
|
|
|
if login_response.status_code != 200:
|
|
print(f"❌ Login failed: {login_response.status_code}")
|
|
return
|
|
|
|
token = login_response.json()["access_token"]
|
|
headers = {"Authorization": f"Bearer {token}"}
|
|
|
|
print("✅ Login successful")
|
|
|
|
# Try to access task statuses for non-existent project
|
|
nonexistent_project_id = 99999
|
|
print(f"\n--- Testing with non-existent project ID: {nonexistent_project_id} ---")
|
|
|
|
response = requests.get(
|
|
f"{BASE_URL}/projects/{nonexistent_project_id}/task-statuses",
|
|
headers=headers
|
|
)
|
|
|
|
print(f"Status Code: {response.status_code}")
|
|
|
|
if response.status_code == 404:
|
|
print("✅ Correctly returned 404 Not Found")
|
|
data = response.json()
|
|
print(f"Response: {json.dumps(data, indent=2)}")
|
|
|
|
if "detail" in data and "not found" in data["detail"].lower():
|
|
print("✅ Error message is appropriate")
|
|
else:
|
|
print("❌ Error message is not appropriate")
|
|
else:
|
|
print(f"❌ Expected 404 but got {response.status_code}")
|
|
print(response.text)
|
|
|
|
|
|
def test_unauthorized_access():
|
|
"""Test accessing task statuses without authentication"""
|
|
|
|
print("\n--- Testing without authentication ---")
|
|
|
|
response = requests.get(
|
|
f"{BASE_URL}/projects/1/task-statuses"
|
|
)
|
|
|
|
print(f"Status Code: {response.status_code}")
|
|
|
|
if response.status_code in [401, 403]:
|
|
print(f"✅ Correctly returned {response.status_code} (Unauthorized/Forbidden)")
|
|
print(f"Response: {response.json()}")
|
|
else:
|
|
print(f"❌ Expected 401 or 403 but got {response.status_code}")
|
|
print(response.text)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_nonexistent_project()
|
|
test_unauthorized_access()
|