-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_document_upload.py
More file actions
104 lines (83 loc) · 2.92 KB
/
test_document_upload.py
File metadata and controls
104 lines (83 loc) · 2.92 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
#!/usr/bin/env python3
"""
Test script to verify document upload functionality
"""
import requests
import json
from pathlib import Path
# Test server URL
BASE_URL = "http://localhost:8000"
def test_create_event_with_documents():
"""Test creating an event with document attachments"""
# Test data
event_data = {
'title': 'Test Event with Documents',
'description': 'Testing document upload functionality',
'date': '2025-10-21T12:00:00',
'timeline': 'Testing',
'actor': 'Brody',
'tags': 'testing, documents'
}
# Test documents
test_md_content = """# Test Legal Document
## Case Information
This is a test document to verify the document parsing functionality.
Key points: evidence, timeline, legal workflow.
"""
test_txt_content = """Test document content
Legal case notes
Document parsing test
Search functionality validation"""
# Prepare files for upload
files = [
('files', ('test_document.md', test_md_content, 'text/markdown')),
('files', ('test_notes.txt', test_txt_content, 'text/plain'))
]
# Prepare form data
form_data = {}
for key, value in event_data.items():
form_data[key] = (None, value)
try:
print("Testing document upload endpoint...")
response = requests.post(
f"{BASE_URL}/events/with-attachments",
data=form_data,
files=files
)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
if response.status_code == 200:
event = response.json()
print(f"✅ Event created successfully: {event['title']}")
print(f"Event ID: {event['id']}")
return event['id']
else:
print(f"❌ Error creating event: {response.status_code}")
return None
except Exception as e:
print(f"❌ Exception: {e}")
return None
def test_search_documents():
"""Test searching across document content"""
try:
print("\nTesting document search...")
response = requests.get(f"{BASE_URL}/search?q=legal")
print(f"Status Code: {response.status_code}")
if response.status_code == 200:
results = response.json()
print(f"✅ Search successful, found {len(results)} results")
for result in results:
print(f" - {result['title']}")
else:
print(f"❌ Search error: {response.status_code}")
except Exception as e:
print(f"❌ Search exception: {e}")
if __name__ == "__main__":
print("🧪 Testing Chronicle Document Upload Functionality")
print("=" * 50)
# Test document upload
event_id = test_create_event_with_documents()
# Test search
if event_id:
test_search_documents()
print("\n✅ Test completed!")