@@ -326,6 +326,76 @@ async def test_create_bulk_items(
326
326
assert resp .status_code == 200
327
327
328
328
329
+ async def test_create_bulk_items_already_exist_insert (
330
+ app_client , load_test_data : Callable , load_test_collection
331
+ ):
332
+ coll = load_test_collection
333
+ item = load_test_data ("test_item.json" )
334
+
335
+ items = {}
336
+ for _ in range (2 ):
337
+ _item = deepcopy (item )
338
+ _item ["id" ] = str (uuid .uuid4 ())
339
+ items [_item ["id" ]] = _item
340
+
341
+ payload = {"items" : items , "method" : "insert" }
342
+
343
+ resp = await app_client .post (
344
+ f"/collections/{ coll .id } /bulk_items" ,
345
+ json = payload ,
346
+ )
347
+ assert resp .status_code == 200
348
+ assert resp .text == '"Successfully added 2 items."'
349
+
350
+ for item_id in items .keys ():
351
+ resp = await app_client .get (f"/collections/{ coll .id } /items/{ item_id } " )
352
+ assert resp .status_code == 200
353
+
354
+ # Try creating the same items again.
355
+ # This should fail with the default insert behavior.
356
+ resp = await app_client .post (
357
+ f"/collections/{ coll .id } /bulk_items" ,
358
+ json = payload ,
359
+ )
360
+ assert resp .status_code == 409
361
+
362
+
363
+ async def test_create_bulk_items_already_exist_upsert (
364
+ app_client , load_test_data : Callable , load_test_collection
365
+ ):
366
+ coll = load_test_collection
367
+ item = load_test_data ("test_item.json" )
368
+
369
+ items = {}
370
+ for _ in range (2 ):
371
+ _item = deepcopy (item )
372
+ _item ["id" ] = str (uuid .uuid4 ())
373
+ items [_item ["id" ]] = _item
374
+
375
+ payload = {"items" : items , "method" : "insert" }
376
+
377
+ resp = await app_client .post (
378
+ f"/collections/{ coll .id } /bulk_items" ,
379
+ json = payload ,
380
+ )
381
+ assert resp .status_code == 200
382
+ assert resp .text == '"Successfully added 2 items."'
383
+
384
+ for item_id in items .keys ():
385
+ resp = await app_client .get (f"/collections/{ coll .id } /items/{ item_id } " )
386
+ assert resp .status_code == 200
387
+
388
+ # Try creating the same items again, but using upsert.
389
+ # This should succeed.
390
+ payload ["method" ] = "upsert"
391
+ resp = await app_client .post (
392
+ f"/collections/{ coll .id } /bulk_items" ,
393
+ json = payload ,
394
+ )
395
+ assert resp .status_code == 200
396
+ assert resp .text == '"Successfully upserted 2 items."'
397
+
398
+
329
399
# TODO since right now puts implement upsert
330
400
# test_create_collection_already_exists
331
401
# test create_item_already_exists
0 commit comments