-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_remove_ui.py
More file actions
122 lines (93 loc) · 3.77 KB
/
test_remove_ui.py
File metadata and controls
122 lines (93 loc) · 3.77 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
#!/usr/bin/env python3
"""
Test script to verify the remove UI functionality
"""
import sys
sys.path.append('.')
# Mock the missing gradio module to avoid import errors
class MockGradio:
def __getattr__(self, name):
return lambda *args, **kwargs: None
sys.modules['gradio'] = MockGradio()
from note_graph import NoteGraph
class TestRemoveUI:
def __init__(self):
self.ng = NoteGraph()
self.ng.init_embedding_model(use_openai=False)
def test_remove_note_ui(self, note_id: str) -> str:
"""Test remove note UI functionality."""
if not note_id:
return "❌ Please enter a note ID"
try:
note_id = int(note_id.strip())
# Check if note exists first
note = self.ng.get_note_with_connections(note_id)
if not note:
return f"❌ Note with ID {note_id} not found"
# Show confirmation details
title = note['title']
# Remove note
success = self.ng.remove_note(note_id)
if success:
return f"✅ Successfully removed note: '{title}' (ID: {note_id})"
else:
return f"❌ Failed to remove note with ID {note_id}"
except ValueError:
return "❌ Invalid note ID. Please enter a number."
except Exception as e:
return f"❌ Error removing note: {str(e)}"
def test_remove_all_notes_ui(self, confirm: str) -> str:
"""Test remove all notes UI functionality."""
if confirm.lower() != "delete all":
return "❌ Please type 'delete all' exactly to confirm removal of all notes"
try:
# Get current note count
note_ids = self.ng.get_all_note_ids()
count = len(note_ids)
if count == 0:
return "ℹ️ No notes to remove"
# Remove all notes
removed_count = self.ng.remove_all_notes()
return f"✅ Successfully removed {removed_count} notes and all their relationships, embeddings, and connections"
except Exception as e:
return f"❌ Error removing all notes: {str(e)}"
def main():
print("🧪 Testing Remove UI Functionality...")
tester = TestRemoveUI()
# Test 1: Remove single note
print("\n📝 Test 1: Remove single note")
note_ids = tester.ng.get_all_note_ids()
print(f"Current notes: {note_ids}")
if note_ids:
test_id = note_ids[0]
print(f"Testing removal of note {test_id}...")
result = tester.test_remove_note_ui(str(test_id))
print(f"Result: {result}")
# Check remaining notes
remaining_ids = tester.ng.get_all_note_ids()
print(f"Remaining notes: {remaining_ids}")
else:
print("No notes to test single removal")
# Test 2: Invalid note ID
print("\n📝 Test 2: Invalid note ID")
result = tester.test_remove_note_ui("999")
print(f"Result: {result}")
# Test 3: Invalid input format
print("\n📝 Test 3: Invalid input format")
result = tester.test_remove_note_ui("abc")
print(f"Result: {result}")
# Test 4: Remove all notes (with incorrect confirmation)
print("\n📝 Test 4: Remove all - incorrect confirmation")
result = tester.test_remove_all_notes_ui("wrong")
print(f"Result: {result}")
# Test 5: Remove all notes (with correct confirmation)
print("\n📝 Test 5: Remove all - correct confirmation")
result = tester.test_remove_all_notes_ui("delete all")
print(f"Result: {result}")
# Test 6: Try to remove all when empty
print("\n📝 Test 6: Remove all when empty")
result = tester.test_remove_all_notes_ui("delete all")
print(f"Result: {result}")
print("\n✅ All remove UI tests completed!")
if __name__ == "__main__":
main()