25
25
from azure .cosmos .aio import CosmosClient , _retry_utility_async , DatabaseProxy
26
26
from azure .cosmos .http_constants import HttpHeaders , StatusCodes
27
27
from azure .cosmos .partition_key import PartitionKey
28
+ from azure .cosmos import ThroughputProperties
28
29
29
30
30
31
class TimeoutTransport (AsyncioRequestsTransport ):
@@ -956,7 +957,6 @@ def __validate_offer_response_body(self, offer, expected_coll_link, expected_off
956
957
assert expected_offer_type == offer .properties .get ('offerType' )
957
958
958
959
async def test_offer_read_and_query_async (self ):
959
-
960
960
# Create database.
961
961
db = self .database_for_test
962
962
@@ -968,7 +968,6 @@ async def test_offer_read_and_query_async(self):
968
968
self .__validate_offer_response_body (expected_offer , collection_properties .get ('_self' ), None )
969
969
970
970
async def test_offer_replace_async (self ):
971
-
972
971
collection = self .database_for_test .get_container_client (self .configs .TEST_MULTI_PARTITION_CONTAINER_ID )
973
972
# Read Offer
974
973
expected_offer = await collection .get_throughput ()
@@ -984,7 +983,6 @@ async def test_offer_replace_async(self):
984
983
assert expected_offer .offer_throughput + 100 == replaced_offer .offer_throughput
985
984
986
985
async def test_index_progress_headers_async (self ):
987
-
988
986
created_db = self .database_for_test
989
987
consistent_coll = created_db .get_container_client (self .configs .TEST_MULTI_PARTITION_CONTAINER_ID )
990
988
created_container = created_db .get_container_client (container = consistent_coll )
@@ -1007,6 +1005,35 @@ async def test_index_progress_headers_async(self):
1007
1005
1008
1006
await created_db .delete_container (none_coll )
1009
1007
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
+
1010
1037
async def _mock_execute_function (self , function , * args , ** kwargs ):
1011
1038
if HttpHeaders .PartitionKey in args [4 ].headers :
1012
1039
self .last_headers .append (args [4 ].headers [HttpHeaders .PartitionKey ])
0 commit comments