2525from azure .cosmos .aio import CosmosClient , _retry_utility_async , DatabaseProxy
2626from azure .cosmos .http_constants import HttpHeaders , StatusCodes
2727from azure .cosmos .partition_key import PartitionKey
28+ from azure .cosmos import ThroughputProperties
2829
2930
3031class TimeoutTransport (AsyncioRequestsTransport ):
@@ -956,7 +957,6 @@ def __validate_offer_response_body(self, offer, expected_coll_link, expected_off
956957 assert expected_offer_type == offer .properties .get ('offerType' )
957958
958959 async def test_offer_read_and_query_async (self ):
959-
960960 # Create database.
961961 db = self .database_for_test
962962
@@ -968,7 +968,6 @@ async def test_offer_read_and_query_async(self):
968968 self .__validate_offer_response_body (expected_offer , collection_properties .get ('_self' ), None )
969969
970970 async def test_offer_replace_async (self ):
971-
972971 collection = self .database_for_test .get_container_client (self .configs .TEST_MULTI_PARTITION_CONTAINER_ID )
973972 # Read Offer
974973 expected_offer = await collection .get_throughput ()
@@ -984,7 +983,6 @@ async def test_offer_replace_async(self):
984983 assert expected_offer .offer_throughput + 100 == replaced_offer .offer_throughput
985984
986985 async def test_index_progress_headers_async (self ):
987-
988986 created_db = self .database_for_test
989987 consistent_coll = created_db .get_container_client (self .configs .TEST_MULTI_PARTITION_CONTAINER_ID )
990988 created_container = created_db .get_container_client (container = consistent_coll )
@@ -1007,6 +1005,35 @@ async def test_index_progress_headers_async(self):
10071005
10081006 await created_db .delete_container (none_coll )
10091007
1008+ async def test_replace_throughput_offer_with_int (self ):
1009+ created_db = self .database_for_test
1010+ collection = created_db .get_container_client (self .configs .TEST_MULTI_PARTITION_CONTAINER_ID )
1011+
1012+ new_throughput = ThroughputProperties (offer_throughput = 2500 )
1013+ await collection .replace_throughput (new_throughput .offer_throughput )
1014+
1015+ retrieve_throughput = await collection .get_throughput ()
1016+ assert getattr (retrieve_throughput , "offer_throughput" ) == getattr (new_throughput , "offer_throughput" )
1017+
1018+ async def test_replace_throughput_offer_with_object (self ):
1019+ created_db = self .database_for_test
1020+ collection = created_db .get_container_client (self .configs .TEST_MULTI_PARTITION_CONTAINER_ID )
1021+
1022+ new_throughput = ThroughputProperties (offer_throughput = 2500 )
1023+ await collection .replace_throughput (new_throughput )
1024+
1025+ retrieve_throughput = await collection .get_throughput ()
1026+ assert getattr (retrieve_throughput , "offer_throughput" ) == getattr (new_throughput , "offer_throughput" )
1027+
1028+ async def test_negative_replace_throughput_with_all_configs_set (self ):
1029+ created_db = self .database_for_test
1030+ collection = created_db .get_container_client (self .configs .TEST_MULTI_PARTITION_CONTAINER_ID )
1031+
1032+ new_throughput = ThroughputProperties (offer_throughput = 2500 , auto_scale_max_throughput = 4000 , auto_scale_increment_percent = 5 )
1033+
1034+ with pytest .raises (KeyError ):
1035+ await collection .replace_throughput (new_throughput )
1036+
10101037 async def _mock_execute_function (self , function , * args , ** kwargs ):
10111038 if HttpHeaders .PartitionKey in args [4 ].headers :
10121039 self .last_headers .append (args [4 ].headers [HttpHeaders .PartitionKey ])
0 commit comments