-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_search_fix.py
More file actions
executable file
·100 lines (86 loc) · 3.31 KB
/
Copy pathtest_search_fix.py
File metadata and controls
executable file
·100 lines (86 loc) · 3.31 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
import os
import sys
from app import app
from database import db, File, search_files
from datetime import datetime
def setup_test_data():
# Clear existing files for clean test
File.query.delete()
# Add a folder marker
folder1 = File(
filename='.folder_marker',
file_id='folder_1',
folder='root/my_vacation',
mime_type='folder',
size=0,
upload_date=datetime.utcnow(),
is_deleted=False
)
# Add another folder marker
folder2 = File(
filename='.folder_marker',
file_id='folder_2',
folder='root/work',
mime_type='folder',
size=0,
upload_date=datetime.utcnow(),
is_deleted=False
)
# Add a file in the first folder
file1 = File(
filename='beach.jpg',
file_id='file_1',
folder='root/my_vacation',
mime_type='image/jpeg',
size=1024,
upload_date=datetime.utcnow(),
is_deleted=False
)
# Add a file in the second folder
file2 = File(
filename='report.pdf',
file_id='file_2',
folder='root/work',
mime_type='application/pdf',
size=2048,
upload_date=datetime.utcnow(),
is_deleted=False
)
db.session.add(folder1)
db.session.add(folder2)
db.session.add(file1)
db.session.add(file2)
db.session.commit()
def test_search():
with app.app_context():
setup_test_data()
print("--- Test 1: Search for 'vacation' with type 'folder' ---")
results = search_files(query='vacation', path='root', file_type='folder')
print(f"Results: {[f.folder for f in results]}")
assert len(results) == 1
assert results[0].folder == 'root/my_vacation'
print("--- Test 2: Search for 'work' with type 'folder' ---")
results = search_files(query='work', path='root', file_type='folder')
print(f"Results: {[f.folder for f in results]}")
assert len(results) == 1
assert results[0].folder == 'root/work'
print("--- Test 3: Search for 'beach' with type 'image' ---")
results = search_files(query='beach', path='root', file_type='image')
print(f"Results: {[f.filename for f in results]}")
assert len(results) == 1
assert results[0].filename == 'beach.jpg'
print("--- Test 4: Search for 'vacation' with type '' (All) ---")
results = search_files(query='vacation', path='root', file_type='')
# Should find 'root/my_vacation' folder marker
print(f"Results: {[(f.filename, f.folder) for f in results]}")
# Depending on implementation, it might also find 'beach.jpg' if we search folder path for all files.
# But my implementation only searches folder path for folder markers.
# So only the folder marker should be found if filename doesn't contain 'vacation'.
assert any(f.filename == '.folder_marker' and 'vacation' in f.folder for f in results)
print("--- Test 5: Search with empty query and type 'folder' ---")
results = search_files(query='', path='root', file_type='folder')
print(f"Results: {[f.folder for f in results]}")
assert len(results) == 2
print("\nAll tests passed!")
if __name__ == "__main__":
test_search()