1313 PropertyIndexTaskStatus ,
1414 Tokenization ,
1515)
16- from weaviate .exceptions import WeaviateUnsupportedFeatureError
16+ from weaviate .exceptions import (
17+ ReindexCanceledError ,
18+ ReindexFailedError ,
19+ WeaviateUnsupportedFeatureError ,
20+ )
1721
1822COLLECTION = "TestCollection"
1923SCHEMA_PATH = f"/v1/schema/{ COLLECTION } "
@@ -128,12 +132,117 @@ def test_update_property_index_wait_for_completion(
128132 weaviate_139_mock .check_assertions ()
129133
130134
135+ def test_update_property_index_bare_str_tenant (
136+ weaviate_139_mock : HTTPServer , client_139 : weaviate .WeaviateClient
137+ ) -> None :
138+ """A bare string tenant is normalized to a single csv value, not exploded into characters."""
139+ weaviate_139_mock .expect_request (
140+ f"{ SCHEMA_PATH } /properties/age/index/rangeFilters" ,
141+ method = "PUT" ,
142+ query_string = {"tenants" : "tenant1" },
143+ json = {},
144+ ).respond_with_json ({"taskId" : TASK_ID , "status" : "STARTED" }, status = 202 )
145+
146+ task = client_139 .collections .use (COLLECTION ).config .update_property_index (
147+ "age" , "rangeFilters" , tenants = "tenant1"
148+ )
149+ assert task .status == PropertyIndexTaskStatus .STARTED
150+ weaviate_139_mock .check_assertions ()
151+
152+
153+ @pytest .mark .parametrize (
154+ "index_status,exception" ,
155+ [("failed" , ReindexFailedError ), ("cancelled" , ReindexCanceledError )],
156+ )
157+ def test_update_property_index_wait_raises (
158+ weaviate_139_mock : HTTPServer ,
159+ client_139 : weaviate .WeaviateClient ,
160+ index_status : str ,
161+ exception : type ,
162+ ) -> None :
163+ weaviate_139_mock .expect_request (
164+ f"{ SCHEMA_PATH } /properties/name/index/searchable" ,
165+ method = "PUT" ,
166+ json = {"tokenization" : "word" },
167+ ).respond_with_json ({"taskId" : TASK_ID , "status" : "STARTED" }, status = 202 )
168+ weaviate_139_mock .expect_request (f"{ SCHEMA_PATH } /indexes" , method = "GET" ).respond_with_json (
169+ {
170+ "collection" : COLLECTION ,
171+ "properties" : [
172+ {
173+ "name" : "name" ,
174+ "dataType" : "text" ,
175+ "indexes" : [
176+ {
177+ "type" : "searchable" ,
178+ "status" : index_status ,
179+ "progress" : 0.42 ,
180+ "taskId" : TASK_ID ,
181+ "tokenization" : "word" ,
182+ }
183+ ],
184+ }
185+ ],
186+ }
187+ )
188+
189+ with pytest .raises (exception ):
190+ client_139 .collections .use (COLLECTION ).config .update_property_index (
191+ "name" , "searchable" , tokenization = Tokenization .WORD , wait_for_completion = True
192+ )
193+ weaviate_139_mock .check_assertions ()
194+
195+
196+ @pytest .mark .parametrize (
197+ "index_status,exception" ,
198+ [("failed" , ReindexFailedError ), ("cancelled" , ReindexCanceledError )],
199+ )
200+ def test_rebuild_property_index_wait_raises (
201+ weaviate_139_mock : HTTPServer ,
202+ client_139 : weaviate .WeaviateClient ,
203+ index_status : str ,
204+ exception : type ,
205+ ) -> None :
206+ weaviate_139_mock .expect_request (
207+ f"{ SCHEMA_PATH } /properties/name/index/searchable/rebuild" ,
208+ method = "POST" ,
209+ json = {},
210+ ).respond_with_json ({"taskId" : TASK_ID , "status" : "STARTED" }, status = 202 )
211+ weaviate_139_mock .expect_request (f"{ SCHEMA_PATH } /indexes" , method = "GET" ).respond_with_json (
212+ {
213+ "collection" : COLLECTION ,
214+ "properties" : [
215+ {
216+ "name" : "name" ,
217+ "dataType" : "text" ,
218+ "indexes" : [
219+ {
220+ "type" : "searchable" ,
221+ "status" : index_status ,
222+ "progress" : 0.42 ,
223+ "taskId" : TASK_ID ,
224+ "tokenization" : "word" ,
225+ }
226+ ],
227+ }
228+ ],
229+ }
230+ )
231+
232+ with pytest .raises (exception ):
233+ client_139 .collections .use (COLLECTION ).config .rebuild_property_index (
234+ "name" , "searchable" , wait_for_completion = True
235+ )
236+ weaviate_139_mock .check_assertions ()
237+
238+
131239def test_rebuild_property_index (
132240 weaviate_139_mock : HTTPServer , client_139 : weaviate .WeaviateClient
133241) -> None :
134242 weaviate_139_mock .expect_request (
135243 f"{ SCHEMA_PATH } /properties/name/index/searchable/rebuild" ,
136244 method = "POST" ,
245+ json = {},
137246 ).respond_with_json ({"taskId" : TASK_ID , "status" : "STARTED" }, status = 202 )
138247
139248 task = client_139 .collections .use (COLLECTION ).config .rebuild_property_index (
@@ -151,6 +260,7 @@ def test_rebuild_property_index_with_tenants(
151260 f"{ SCHEMA_PATH } /properties/age/index/rangeFilters/rebuild" ,
152261 method = "POST" ,
153262 query_string = {"tenants" : "tenant1,tenant2" },
263+ json = {},
154264 ).respond_with_json ({"taskId" : TASK_ID , "status" : "STARTED" }, status = 202 )
155265
156266 task = client_139 .collections .use (COLLECTION ).config .rebuild_property_index (
@@ -167,6 +277,7 @@ def test_cancel_property_index_task_cancelled(
167277 weaviate_139_mock .expect_request (
168278 f"{ SCHEMA_PATH } /properties/name/index/searchable/cancel" ,
169279 method = "POST" ,
280+ json = {},
170281 ).respond_with_json ({"taskId" : TASK_ID , "status" : "CANCELLED" }, status = 202 )
171282
172283 task = client_139 .collections .use (COLLECTION ).config .cancel_property_index_task (
@@ -183,6 +294,7 @@ def test_cancel_property_index_task_no_op(
183294 weaviate_139_mock .expect_request (
184295 f"{ SCHEMA_PATH } /properties/name/index/searchable/cancel" ,
185296 method = "POST" ,
297+ json = {},
186298 ).respond_with_json ({"status" : "NO_OP" }, status = 202 )
187299
188300 task = client_139 .collections .use (COLLECTION ).config .cancel_property_index_task (
@@ -270,6 +382,14 @@ def test_get_property_indexes(
270382 assert age .indexes [0 ].task_id is None
271383 assert age .indexes [0 ].tokenization is None
272384
385+ # the nested dataclasses serialize all the way down to a JSON-compatible dict
386+ out = json .loads (json .dumps (indexes .to_dict ()))
387+ assert out ["collection" ] == COLLECTION
388+ assert out ["properties" ][0 ]["indexes" ][0 ]["taskId" ] == TASK_ID
389+ assert out ["properties" ][0 ]["indexes" ][0 ]["targetTokenization" ] == "field"
390+ assert out ["properties" ][1 ]["dataType" ] == "int"
391+ assert out ["properties" ][1 ]["indexes" ][0 ]["status" ] == "ready"
392+
273393 weaviate_139_mock .check_assertions ()
274394
275395
0 commit comments