@@ -129,3 +129,114 @@ def test_upload_duplicate_then_delete_and_reupload(client, collection):
129129 assert "items" in data3
130130 assert len (data3 ["items" ]) == 1
131131 assert data3 ["items" ][0 ]["name" ] == filename
132+
133+
134+ # Document index rebuild tests
135+ def test_rebuild_single_index_type (client , document , collection ):
136+ """Test rebuilding a single index type (vector)"""
137+ doc_id = document ["id" ]
138+ collection_id = collection ["id" ]
139+
140+ # Test rebuilding vector index
141+ rebuild_request = {"index_types" : ["vector" ]}
142+ response = client .post (
143+ f"/api/v1/collections/{ collection_id } /documents/{ doc_id } /rebuild_indexes" ,
144+ json = rebuild_request
145+ )
146+ assert response .status_code == HTTPStatus .OK , response .text
147+ data = response .json ()
148+ assert data ["code" ] == "200"
149+ assert "vector" in data ["message" ]
150+
151+
152+ def test_rebuild_all_index_types (client , document , collection ):
153+ """Test rebuilding all supported index types"""
154+ doc_id = document ["id" ]
155+ collection_id = collection ["id" ]
156+
157+ # Test rebuilding all index types
158+ rebuild_request = {"index_types" : ["vector" , "fulltext" , "graph" ]}
159+ response = client .post (
160+ f"/api/v1/collections/{ collection_id } /documents/{ doc_id } /rebuild_indexes" ,
161+ json = rebuild_request
162+ )
163+ assert response .status_code == HTTPStatus .OK , response .text
164+ data = response .json ()
165+ assert data ["code" ] == "200"
166+ assert "vector" in data ["message" ]
167+ assert "fulltext" in data ["message" ]
168+ assert "graph" in data ["message" ]
169+
170+
171+ def test_rebuild_index_invalid_index_type (client , document , collection ):
172+ """Test rebuilding with invalid index type"""
173+ doc_id = document ["id" ]
174+ collection_id = collection ["id" ]
175+
176+ # Test with invalid index type
177+ rebuild_request = {"index_types" : ["invalid_type" ]}
178+ response = client .post (
179+ f"/api/v1/collections/{ collection_id } /documents/{ doc_id } /rebuild_indexes" ,
180+ json = rebuild_request
181+ )
182+ assert response .status_code == HTTPStatus .BAD_REQUEST , response .text
183+
184+
185+ def test_rebuild_index_empty_index_types (client , document , collection ):
186+ """Test rebuilding with empty index types array"""
187+ doc_id = document ["id" ]
188+ collection_id = collection ["id" ]
189+
190+ # Test with empty index types
191+ rebuild_request = {"index_types" : []}
192+ response = client .post (
193+ f"/api/v1/collections/{ collection_id } /documents/{ doc_id } /rebuild_indexes" ,
194+ json = rebuild_request
195+ )
196+ assert response .status_code == HTTPStatus .UNPROCESSABLE_ENTITY , response .text
197+
198+
199+ @pytest .mark .parametrize ("index_type" , ["vector" , "fulltext" , "graph" ])
200+ def test_rebuild_individual_index_types (client , document , collection , index_type ):
201+ """Test rebuilding each individual index type"""
202+ doc_id = document ["id" ]
203+ collection_id = collection ["id" ]
204+
205+ rebuild_request = {"index_types" : [index_type ]}
206+ response = client .post (
207+ f"/api/v1/collections/{ collection_id } /documents/{ doc_id } /rebuild_indexes" ,
208+ json = rebuild_request
209+ )
210+ assert response .status_code == HTTPStatus .OK , response .text
211+ data = response .json ()
212+ assert data ["code" ] == "200"
213+ assert index_type in data ["message" ]
214+
215+
216+ def test_rebuild_index_duplicate_types (client , document , collection ):
217+ """Test rebuilding with duplicate index types in request"""
218+ doc_id = document ["id" ]
219+ collection_id = collection ["id" ]
220+
221+ # Test with duplicate index types
222+ rebuild_request = {"index_types" : ["vector" , "vector" , "fulltext" ]}
223+ response = client .post (
224+ f"/api/v1/collections/{ collection_id } /documents/{ doc_id } /rebuild_indexes" ,
225+ json = rebuild_request
226+ )
227+ # Should fail
228+ assert response .status_code == HTTPStatus .BAD_REQUEST , response .text
229+
230+
231+ def test_rebuild_index_case_sensitivity (client , document , collection ):
232+ """Test rebuilding with different case index types"""
233+ doc_id = document ["id" ]
234+ collection_id = collection ["id" ]
235+
236+ # Test with uppercase index type (should fail)
237+ rebuild_request = {"index_types" : ["VECTOR" ]}
238+ response = client .post (
239+ f"/api/v1/collections/{ collection_id } /documents/{ doc_id } /rebuild_indexes" ,
240+ json = rebuild_request
241+ )
242+ assert response .status_code == HTTPStatus .UNPROCESSABLE_ENTITY , response .text
0 commit comments