-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument_bulk_delete_fix.py
More file actions
95 lines (80 loc) · 3.05 KB
/
document_bulk_delete_fix.py
File metadata and controls
95 lines (80 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
import requests
import json
import os
from dotenv import load_dotenv
# Load environment variables from frontend/.env
load_dotenv('/app/frontend/.env')
# Get the backend URL from environment variables
BACKEND_URL = os.environ.get('REACT_APP_BACKEND_URL')
if not BACKEND_URL:
print("Error: REACT_APP_BACKEND_URL not found in environment variables")
exit(1)
# Ensure the URL ends with /api
API_URL = f"{BACKEND_URL}/api"
print(f"Using API URL: {API_URL}")
def login():
"""Login with test endpoint to get auth token"""
url = f"{API_URL}/auth/test-login"
try:
response = requests.post(url)
print(f"Status Code: {response.status_code}")
if response.status_code == 200:
data = response.json()
auth_token = data.get("access_token")
user_data = data.get("user", {})
test_user_id = user_data.get("id")
print(f"Login successful. User ID: {test_user_id}")
print(f"JWT Token: {auth_token}")
return auth_token
else:
print(f"Login failed: {response.text}")
return None
except Exception as e:
print(f"Error during login: {e}")
return None
def test_document_bulk_delete_with_empty_array(auth_token):
"""Test document bulk delete with empty array"""
url = f"{API_URL}/documents/bulk"
headers = {"Authorization": f"Bearer {auth_token}"}
print("\nTesting document bulk delete with empty array:")
try:
response = requests.delete(url, json=[], headers=headers)
print(f"Status Code: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"Response: {json.dumps(data, indent=2)}")
deleted_count = data.get("deleted_count", -1)
if deleted_count == 0:
print("✅ Success! Empty array is now handled correctly")
return True
else:
print(f"❌ Expected deleted_count=0, but got {deleted_count}")
return False
else:
print(f"❌ Expected status code 200, but got {response.status_code}")
print(f"Response: {response.text}")
return False
except Exception as e:
print(f"❌ Error testing document bulk delete with empty array: {e}")
return False
def main():
"""Main function"""
print("="*80)
print("TESTING DOCUMENT BULK DELETE WITH EMPTY ARRAY AFTER FIX")
print("="*80)
# Login first
auth_token = login()
if not auth_token:
print("Login failed. Cannot proceed with testing.")
return
# Test document bulk delete with empty array
success = test_document_bulk_delete_with_empty_array(auth_token)
print("\n" + "="*80)
if success:
print("✅ DOCUMENT BULK DELETE WITH EMPTY ARRAY IS NOW WORKING CORRECTLY")
else:
print("❌ DOCUMENT BULK DELETE WITH EMPTY ARRAY IS STILL NOT WORKING CORRECTLY")
print("="*80)
if __name__ == "__main__":
main()