-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument_bulk_delete_fix_v4.py
More file actions
162 lines (139 loc) · 5.64 KB
/
document_bulk_delete_fix_v4.py
File metadata and controls
162 lines (139 loc) · 5.64 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/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}",
"Content-Type": "application/json"
}
print("\nTesting document bulk delete with empty array:")
try:
# Use the new request format with document_ids field
request_body = {"document_ids": []}
print(f"Request URL: {url}")
print(f"Request Headers: {headers}")
print(f"Request Body: {json.dumps(request_body)}")
# Send the request
response = requests.delete(url, json=request_body, headers=headers)
# Print the response details
print(f"Response Status Code: {response.status_code}")
try:
response_json = response.json()
print(f"Response JSON: {json.dumps(response_json, indent=2)}")
except:
print(f"Response Text: {response.text}")
if response.status_code == 200:
data = response.json()
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 test_conversation_bulk_delete_with_empty_array(auth_token):
"""Test conversation bulk delete with empty array"""
url = f"{API_URL}/conversation-history/bulk"
headers = {
"Authorization": f"Bearer {auth_token}",
"Content-Type": "application/json"
}
print("\nTesting conversation bulk delete with empty array:")
try:
# Use the new request format with conversation_ids field
request_body = {"conversation_ids": []}
print(f"Request URL: {url}")
print(f"Request Headers: {headers}")
print(f"Request Body: {json.dumps(request_body)}")
# Send the request
response = requests.delete(url, json=request_body, headers=headers)
# Print the response details
print(f"Response Status Code: {response.status_code}")
try:
response_json = response.json()
print(f"Response JSON: {json.dumps(response_json, indent=2)}")
except:
print(f"Response Text: {response.text}")
if response.status_code == 200:
data = response.json()
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 conversation bulk delete with empty array: {e}")
return False
def main():
"""Main function"""
print("="*80)
print("TESTING BULK DELETE WITH EMPTY ARRAYS 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
doc_success = test_document_bulk_delete_with_empty_array(auth_token)
# Test conversation bulk delete with empty array
conv_success = test_conversation_bulk_delete_with_empty_array(auth_token)
print("\n" + "="*80)
if doc_success and conv_success:
print("✅ BULK DELETE WITH EMPTY ARRAYS IS NOW WORKING CORRECTLY")
else:
print("❌ BULK DELETE WITH EMPTY ARRAYS IS STILL NOT WORKING CORRECTLY")
if not doc_success:
print("❌ Document bulk delete with empty array is not working")
if not conv_success:
print("❌ Conversation bulk delete with empty array is not working")
print("="*80)
if __name__ == "__main__":
main()