Skip to content

Commit cf135a2

Browse files
[Cosmos] Fixing replace throughput method (Azure#26363)
* Update _base.py * Update test_auto_scale.py * fixing tests * Update test_auto_scale.py * Update test_auto_scale.py * create db if not exists * Update test_auto_scale.py Co-authored-by: simorenoh <[email protected]>
1 parent f926125 commit cf135a2

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

sdk/cosmos/azure-cosmos/azure/cosmos/_base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,9 @@ def _deserialize_throughput(throughput: list) -> Any:
731731

732732

733733
def _replace_throughput(throughput: Union[int, ThroughputProperties], new_throughput_properties: list):
734-
max_throughput = throughput.auto_scale_max_throughput
735-
increment_percent = throughput.auto_scale_increment_percent
736-
737734
try:
735+
max_throughput = throughput.auto_scale_max_throughput
736+
increment_percent = throughput.auto_scale_increment_percent
738737
if max_throughput is not None:
739738
new_throughput_properties['content']['offerAutopilotSettings'][
740739
'maxThroughput'] = max_throughput

sdk/cosmos/azure-cosmos/test/test_auto_scale.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ def setUpClass(cls):
4545

4646
cls.client = cosmos_client.CosmosClient(cls.host, cls.masterKey, consistency_level="Session",
4747
connection_policy=cls.connectionPolicy)
48-
cls.created_database = cls.client.create_database(test_config._test_config.TEST_DATABASE_ID)
48+
cls.created_database = cls.client.create_database_if_not_exists(test_config._test_config.TEST_DATABASE_ID)
4949

5050
def test_auto_scale(self):
5151
created_container = self.created_database.create_container(
52-
id='container_with_auto_scale_settings',
52+
id='auto_scale',
5353
partition_key=PartitionKey(path="/id"),
5454
offer_throughput=ThroughputProperties(auto_scale_max_throughput=7000, auto_scale_increment_percent=0)
5555

@@ -74,7 +74,7 @@ def test_auto_scale(self):
7474
def test_create_container_if_not_exist(self):
7575
# Testing auto_scale_settings for the create_container_if_not_exists method
7676
created_container = self.created_database.create_container_if_not_exists(
77-
id='container_with_auto_scale_settings',
77+
id='auto_scale_2',
7878
partition_key=PartitionKey(path="/id"),
7979
offer_throughput=ThroughputProperties(auto_scale_max_throughput=1000, auto_scale_increment_percent=3)
8080
)
@@ -86,9 +86,11 @@ def test_create_container_if_not_exist(self):
8686
self.assertEqual(
8787
created_container_properties.auto_scale_increment_percent, 3)
8888

89+
self.created_database.delete_container(created_container.id)
90+
8991
def test_create_database(self):
9092
# Testing auto_scale_settings for the create_database method
91-
created_database = self.client.create_database("db1", offer_throughput=ThroughputProperties(
93+
created_database = self.client.create_database("db_auto_scale", offer_throughput=ThroughputProperties(
9294
auto_scale_max_throughput=5000,
9395
auto_scale_increment_percent=0))
9496
created_db_properties = created_database.get_throughput()
@@ -99,13 +101,14 @@ def test_create_database(self):
99101
self.assertEqual(
100102
created_db_properties.auto_scale_increment_percent, 0)
101103

102-
self.client.delete_database("db1")
104+
self.client.delete_database("db_auto_scale")
103105

104106
def test_create_database_if_not_exists(self):
105107
# Testing auto_scale_settings for the create_database_if_not_exists method
106-
created_database = self.client.create_database_if_not_exists("db2", offer_throughput=ThroughputProperties(
107-
auto_scale_max_throughput=9000,
108-
auto_scale_increment_percent=11))
108+
created_database = self.client.create_database_if_not_exists("db_auto_scale_2",
109+
offer_throughput=ThroughputProperties(
110+
auto_scale_max_throughput=9000,
111+
auto_scale_increment_percent=11))
109112
created_db_properties = created_database.get_throughput()
110113
# Testing the input value of the max_throughput
111114
self.assertNotEqual(
@@ -114,7 +117,7 @@ def test_create_database_if_not_exists(self):
114117
self.assertEqual(
115118
created_db_properties.auto_scale_increment_percent, 11)
116119

117-
self.client.delete_database("db2")
120+
self.client.delete_database("db_auto_scale_2")
118121

119122
def test_replace_throughput(self):
120123
created_container = self.created_database.create_container(
@@ -132,4 +135,4 @@ def test_replace_throughput(self):
132135
self.assertEqual(
133136
created_container_properties.auto_scale_increment_percent, 20)
134137

135-
self.client.delete_database(test_config._test_config.TEST_DATABASE_ID)
138+
self.created_database.delete_container(created_container.id)

sdk/cosmos/azure-cosmos/test/test_auto_scale_async.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def setUpClass(cls):
4545

4646
cls.client = CosmosClient(cls.host, cls.masterKey, consistency_level="Session",
4747
connection_policy=cls.connectionPolicy)
48-
cls.created_database = await cls.client.create_database(test_config._test_config.TEST_DATABASE_ID)
48+
cls.created_database = await cls.client.create_database_if_not_exists(test_config._test_config.TEST_DATABASE_ID)
4949

5050
async def test_auto_scale(self):
5151
created_container = await self.created_database.create_container(
@@ -97,7 +97,6 @@ async def test_create_container_if_not_exist(self):
9797
created_container_properties.auto_scale_increment_percent, 3)
9898

9999
await self.created_database.delete_container(created_container)
100-
await self.client.delete_database(test_config._test_config.TEST_DATABASE_ID)
101100

102101
async def test_create_database(self):
103102
# Testing auto_scale_settings for the create_database method
@@ -144,3 +143,5 @@ async def test_replace_throughput(self):
144143
created_container_properties.auto_scale_max_throughput, 7000)
145144
self.assertEqual(
146145
created_container_properties.auto_scale_increment_percent, 20)
146+
147+
await self.client.delete_database(test_config._test_config.TEST_DATABASE_ID)

0 commit comments

Comments
 (0)