@@ -2404,50 +2404,52 @@ def test_get_resource_with_dictionary_and_object(self):
2404
2404
read_permission = created_user .get_permission (created_permission .properties )
2405
2405
self .assertEqual (read_permission .id , created_permission .id )
2406
2406
2407
- # Commenting out delete items by pk until test pipelines support it
2408
- # def test_delete_all_items_by_partition_key(self):
2409
- # # create database
2410
- # created_db = self.databaseForTest
2411
- #
2412
- # # create container
2413
- # created_collection = created_db.create_container(
2414
- # id='test_delete_all_items_by_partition_key ' + str(uuid.uuid4()),
2415
- # partition_key=PartitionKey(path='/pk', kind='Hash')
2416
- # )
2417
- # # Create two partition keys
2418
- # partition_key1 = "{}-{}".format("Partition Key 1", str(uuid.uuid4()))
2419
- # partition_key2 = "{}-{}".format("Partition Key 2", str(uuid.uuid4()))
2420
- #
2421
- # # add items for partition key 1
2422
- # for i in range(1, 3):
2423
- # created_collection.upsert_item(
2424
- # dict(id="item{}".format(i), pk=partition_key1)
2425
- # )
2426
- #
2427
- # # add items for partition key 2
2428
- #
2429
- # pk2_item = created_collection.upsert_item(dict(id="item{}".format(3), pk=partition_key2))
2430
- #
2431
- # # delete all items for partition key 1
2432
- # created_collection.delete_all_items_by_partition_key(partition_key1)
2433
- #
2434
- # # check that only items from partition key 1 have been deleted
2435
- # items = list(created_collection.read_all_items())
2436
- #
2437
- # # items should only have 1 item and it should equal pk2_item
2438
- # self.assertDictEqual(pk2_item, items[0])
2439
- #
2440
- # # attempting to delete a non-existent partition key or passing none should not delete
2441
- # # anything and leave things unchanged
2442
- # created_collection.delete_all_items_by_partition_key(None)
2443
- #
2444
- # # check that no changes were made by checking if the only item is still there
2445
- # items = list(created_collection.read_all_items())
2446
- #
2447
- # # items should only have 1 item and it should equal pk2_item
2448
- # self.assertDictEqual(pk2_item, items[0])
2449
- #
2450
- # created_db.delete_container(created_collection)
2407
+ def test_delete_all_items_by_partition_key (self ):
2408
+ # enable the test only for the emulator
2409
+ if "localhost" not in self .host and "127.0.0.1" not in self .host :
2410
+ return
2411
+ # create database
2412
+ created_db = self .databaseForTest
2413
+
2414
+ # create container
2415
+ created_collection = created_db .create_container (
2416
+ id = 'test_delete_all_items_by_partition_key ' + str (uuid .uuid4 ()),
2417
+ partition_key = PartitionKey (path = '/pk' , kind = 'Hash' )
2418
+ )
2419
+ # Create two partition keys
2420
+ partition_key1 = "{}-{}" .format ("Partition Key 1" , str (uuid .uuid4 ()))
2421
+ partition_key2 = "{}-{}" .format ("Partition Key 2" , str (uuid .uuid4 ()))
2422
+
2423
+ # add items for partition key 1
2424
+ for i in range (1 , 3 ):
2425
+ created_collection .upsert_item (
2426
+ dict (id = "item{}" .format (i ), pk = partition_key1 )
2427
+ )
2428
+
2429
+ # add items for partition key 2
2430
+
2431
+ pk2_item = created_collection .upsert_item (dict (id = "item{}" .format (3 ), pk = partition_key2 ))
2432
+
2433
+ # delete all items for partition key 1
2434
+ created_collection .delete_all_items_by_partition_key (partition_key1 )
2435
+
2436
+ # check that only items from partition key 1 have been deleted
2437
+ items = list (created_collection .read_all_items ())
2438
+
2439
+ # items should only have 1 item, and it should equal pk2_item
2440
+ self .assertDictEqual (pk2_item , items [0 ])
2441
+
2442
+ # attempting to delete a non-existent partition key or passing none should not delete
2443
+ # anything and leave things unchanged
2444
+ created_collection .delete_all_items_by_partition_key (None )
2445
+
2446
+ # check that no changes were made by checking if the only item is still there
2447
+ items = list (created_collection .read_all_items ())
2448
+
2449
+ # items should only have 1 item, and it should equal pk2_item
2450
+ self .assertDictEqual (pk2_item , items [0 ])
2451
+
2452
+ created_db .delete_container (created_collection )
2451
2453
2452
2454
def test_patch_operations (self ):
2453
2455
created_container = self .databaseForTest .get_container_client (self .configs .TEST_MULTI_PARTITION_CONTAINER_ID )
0 commit comments