Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cosmos] migrate from using unittest #32076

Merged
merged 60 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b46b72d
Update test_auto_scale_async.py
simorenoh Sep 13, 2023
2f7de81
parity
simorenoh Sep 13, 2023
9195608
update the way we use setup
simorenoh Sep 13, 2023
c1524d6
add the pytest mark for asyncio
simorenoh Sep 13, 2023
49602ac
remove connection policy
simorenoh Sep 13, 2023
1860a23
include aiohttp in dev_requirements for pipelines
simorenoh Sep 14, 2023
bbc63af
Update test_auto_scale_async.py
simorenoh Sep 14, 2023
cac28bf
facepalm moment
simorenoh Sep 14, 2023
c4366c7
replace database test
simorenoh Sep 14, 2023
651bb03
Update test_auto_scale.py
simorenoh Sep 14, 2023
22442f6
other async tests
simorenoh Sep 15, 2023
be71aec
fixes
simorenoh Sep 15, 2023
2314fef
small changes
simorenoh Sep 15, 2023
81b549c
more small fixes
simorenoh Sep 15, 2023
50a2753
more fixes
simorenoh Sep 15, 2023
62a28fa
changes
simorenoh Sep 15, 2023
153f9aa
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
7459fb1
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
0cc826e
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
fc74e36
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
6a7864e
Update sdk/cosmos/azure-cosmos/test/test_query_async.py
simorenoh Sep 15, 2023
b3a29b5
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
52abf37
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
edd5f1e
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
98f45da
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
c79dc70
Update sdk/cosmos/azure-cosmos/test/test_resource_id_async.py
simorenoh Sep 15, 2023
ec8dda1
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
24177b8
Update sdk/cosmos/azure-cosmos/test/test_query_async.py
simorenoh Sep 15, 2023
7685055
Update sdk/cosmos/azure-cosmos/test/test_query_async.py
simorenoh Sep 15, 2023
4abcfe3
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
144d5c3
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
d849fe4
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
519145b
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
d457f7d
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
19683af
Update sdk/cosmos/azure-cosmos/test/test_crud_async.py
simorenoh Sep 15, 2023
044787a
Update test_crud_async.py
simorenoh Sep 19, 2023
327c0bf
Update test_crud_async.py
simorenoh Sep 19, 2023
6aafb5f
tests changes
simorenoh Sep 19, 2023
6aaa878
Update test_crud_async.py
simorenoh Sep 19, 2023
19b9288
more test changes
simorenoh Sep 19, 2023
f900659
Update test_crud_async.py
simorenoh Sep 19, 2023
136df86
Merge branch 'main' into update-tests
simorenoh Sep 19, 2023
6bbca53
Update test_crud_async.py
simorenoh Sep 20, 2023
afe7bbf
Update test_query_async.py
simorenoh Sep 20, 2023
aee3750
Update test_query_async.py
simorenoh Sep 22, 2023
918becd
Update test_query_async.py
simorenoh Sep 22, 2023
f2d43c4
etag vs Etag difference in test - does this depend on OS?
simorenoh Sep 25, 2023
6668b7e
fixing wrong logic check
simorenoh Sep 25, 2023
e49ab68
Ubuntu2004_pypy39 returns etag as opposed to Etag
simorenoh Sep 26, 2023
7c4e8b4
more parenthesis
simorenoh Sep 26, 2023
d55b98c
Update test_query_async.py
simorenoh Sep 26, 2023
25f57b9
Update test_query_async.py
simorenoh Sep 26, 2023
4afa226
fixing tests dealing with weird/mock functionalities
simorenoh Sep 27, 2023
4c53f53
Update test_query_async.py
simorenoh Sep 27, 2023
bc91ffc
Update test_query_async.py
simorenoh Sep 28, 2023
c105c85
Update test_query_async.py
simorenoh Sep 29, 2023
7bfc165
Update test_query_async.py
simorenoh Sep 29, 2023
6fcd120
last small changes
simorenoh Oct 10, 2023
4d226aa
Update test_resource_id.py
simorenoh Oct 12, 2023
250da82
Update CHANGELOG.md
simorenoh Oct 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async def create_database_if_not_exists( # pylint: disable=redefined-builtin
:returns: A DatabaseProxy instance representing the database.
:rtype: ~azure.cosmos.DatabaseProxy
"""
offer_throughput = kwargs.pop("offerThroughput", None)
offer_throughput = kwargs.pop("offer_throughput", None)
simorenoh marked this conversation as resolved.
Show resolved Hide resolved
try:
database_proxy = self.get_database_client(id)
await database_proxy.read(**kwargs)
Expand Down
1 change: 1 addition & 0 deletions sdk/cosmos/azure-cosmos/dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
aiohttp>=3.0
simorenoh marked this conversation as resolved.
Show resolved Hide resolved
-e ../../core/azure-core
-e ../../identity/azure-identity
-e ../../../tools/azure-sdk-tools
Expand Down
80 changes: 41 additions & 39 deletions sdk/cosmos/azure-cosmos/test/test_auto_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,36 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import unittest
import azure.cosmos.cosmos_client as cosmos_client

from azure.cosmos import CosmosClient
import azure.cosmos.exceptions as exceptions
from azure.cosmos import ThroughputProperties, PartitionKey, http_constants
from azure.cosmos import ThroughputProperties, PartitionKey
import pytest
import test_config

pytestmark = pytest.mark.cosmosEmulator


@pytest.mark.usefixtures("teardown")
class AutoScaleTest(unittest.TestCase):
class TestAutoScale:
host = test_config._test_config.host
masterKey = test_config._test_config.masterKey
connectionPolicy = test_config._test_config.connectionPolicy

@classmethod
def setUpClass(cls):
def _set_up(cls):
if (cls.masterKey == '[YOUR_KEY_HERE]' or
cls.host == '[YOUR_ENDPOINT_HERE]'):
raise Exception(
"You must specify your Azure Cosmos account values for "
"'masterKey' and 'host' at the top of this class to run the "
"tests.")

cls.client = cosmos_client.CosmosClient(cls.host, cls.masterKey, consistency_level="Session",
connection_policy=cls.connectionPolicy)
cls.client = CosmosClient(cls.host, cls.masterKey, consistency_level="Session")
simorenoh marked this conversation as resolved.
Show resolved Hide resolved
cls.created_database = cls.client.create_database_if_not_exists(test_config._test_config.TEST_DATABASE_ID)

def test_auto_scale(self):
def test_autoscale_create_container(self):
self._set_up()
created_container = self.created_database.create_container(
id='auto_scale',
partition_key=PartitionKey(path="/id"),
Expand All @@ -56,83 +56,85 @@ def test_auto_scale(self):
)
created_container_properties = created_container.get_throughput()
# Testing the input value of the max_throughput
self.assertEqual(
created_container_properties.auto_scale_max_throughput, 7000)
self.assertEqual(created_container_properties.auto_scale_increment_percent, 0)
self.assertEqual(created_container_properties.offer_throughput, None)
assert created_container_properties.auto_scale_max_throughput == 7000
assert created_container_properties.auto_scale_increment_percent == 0
assert created_container_properties.offer_throughput is None

self.created_database.delete_container(created_container)

# Testing the incorrect passing of an input value of the max_throughput to verify negative behavior
with pytest.raises(exceptions.CosmosHttpResponseError) as e:
created_container = self.created_database.create_container(
self.created_database.create_container(
id='container_with_wrong_auto_scale_settings',
partition_key=PartitionKey(path="/id"),
offer_throughput=ThroughputProperties(auto_scale_max_throughput=-200, auto_scale_increment_percent=0))
assert "Requested throughput -200 is less than required minimum throughput 1000" in str(e.value)

def test_create_container_if_not_exist(self):
# Testing auto_scale_settings for the create_container_if_not_exists method
created_container = self.created_database.create_container_if_not_exists(
id='auto_scale_2',
partition_key=PartitionKey(path="/id"),
offer_throughput=ThroughputProperties(auto_scale_max_throughput=1000, auto_scale_increment_percent=3)
)
created_container_properties = created_container.get_throughput()
# Testing the incorrect input value of the max_throughput
self.assertNotEqual(
created_container_properties.auto_scale_max_throughput, 2000)
# Testing the input value of the max_throughput
assert created_container_properties.auto_scale_max_throughput == 1000
# Testing the input value of the increment_percentage
self.assertEqual(
created_container_properties.auto_scale_increment_percent, 3)
assert created_container_properties.auto_scale_increment_percent == 3

self.created_database.delete_container(created_container.id)

def test_create_database(self):
def test_autoscale_create_database(self):
self._set_up()
# Testing auto_scale_settings for the create_database method
created_database = self.client.create_database("db_auto_scale", offer_throughput=ThroughputProperties(
auto_scale_max_throughput=5000,
auto_scale_increment_percent=0))
auto_scale_increment_percent=2))
created_db_properties = created_database.get_throughput()
# Testing the input value of the max_throughput
self.assertEqual(
created_db_properties.auto_scale_max_throughput, 5000)
assert created_db_properties.auto_scale_max_throughput == 5000
# Testing the input value of the increment_percentage
self.assertEqual(
created_db_properties.auto_scale_increment_percent, 0)
assert created_db_properties.auto_scale_increment_percent == 2

self.client.delete_database("db_auto_scale")

def test_create_database_if_not_exists(self):
# Testing auto_scale_settings for the create_database_if_not_exists method
created_database = self.client.create_database_if_not_exists("db_auto_scale_2",
offer_throughput=ThroughputProperties(
auto_scale_max_throughput=9000,
auto_scale_increment_percent=11))
created_db_properties = created_database.get_throughput()
# Testing the input value of the max_throughput
self.assertNotEqual(
created_db_properties.auto_scale_max_throughput, 8000)
assert created_db_properties.auto_scale_max_throughput == 9000
# Testing the input value of the increment_percentage
self.assertEqual(
created_db_properties.auto_scale_increment_percent, 11)
assert created_db_properties.auto_scale_increment_percent == 11

self.client.delete_database("db_auto_scale_2")

def test_replace_throughput(self):
def test_autoscale_replace_throughput(self):
self._set_up()

created_database = self.client.create_database("replace_db", offer_throughput=ThroughputProperties(
auto_scale_max_throughput=5000,
auto_scale_increment_percent=2))
created_database.replace_throughput(
throughput=ThroughputProperties(auto_scale_max_throughput=7000, auto_scale_increment_percent=20))
created_db_properties = created_database.get_throughput()
# Testing the input value of the max_throughput
assert created_db_properties.auto_scale_max_throughput == 7000
# Testing the input value of the increment_percentage
assert created_db_properties.auto_scale_increment_percent == 20
self.client.delete_database("replace_db")

created_container = self.created_database.create_container(
id='container_with_replace_functionality',
partition_key=PartitionKey(path="/id"),
offer_throughput=ThroughputProperties(auto_scale_max_throughput=5000, auto_scale_increment_percent=0)

)
new_throughput = created_container.replace_throughput(
offer_throughput=ThroughputProperties(auto_scale_max_throughput=5000, auto_scale_increment_percent=0))
created_container.replace_throughput(
throughput=ThroughputProperties(auto_scale_max_throughput=7000, auto_scale_increment_percent=20))
created_container_properties = created_container.get_throughput()
# Testing the input value of the replaced auto_scale settings
self.assertEqual(
created_container_properties.auto_scale_max_throughput, 7000)
self.assertEqual(
created_container_properties.auto_scale_increment_percent, 20)
assert created_container_properties.auto_scale_max_throughput == 7000
assert created_container_properties.auto_scale_increment_percent == 20

self.created_database.delete_container(created_container.id)
95 changes: 45 additions & 50 deletions sdk/cosmos/azure-cosmos/test/test_auto_scale_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,37 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import unittest

from azure.cosmos.aio import CosmosClient
import azure.cosmos.exceptions as exceptions
from azure.cosmos import ThroughputProperties, PartitionKey, http_constants
from azure.cosmos import ThroughputProperties, PartitionKey
import pytest
import test_config

pytestmark = pytest.mark.cosmosEmulator


@pytest.mark.usefixtures("teardown")
class AutoScaleTest(unittest.TestCase):
class TestAutoScaleAsync:
host = test_config._test_config.host
masterKey = test_config._test_config.masterKey
connectionPolicy = test_config._test_config.connectionPolicy

@classmethod
async def setUpClass(cls):
async def _set_up(cls):
if (cls.masterKey == '[YOUR_KEY_HERE]' or
cls.host == '[YOUR_ENDPOINT_HERE]'):
raise Exception(
"You must specify your Azure Cosmos account values for "
"'masterKey' and 'host' at the top of this class to run the "
"tests.")

cls.client = CosmosClient(cls.host, cls.masterKey, consistency_level="Session",
connection_policy=cls.connectionPolicy)
cls.client = CosmosClient(cls.host, cls.masterKey)
simorenoh marked this conversation as resolved.
Show resolved Hide resolved
cls.created_database = await cls.client.create_database_if_not_exists(test_config._test_config.TEST_DATABASE_ID)

async def test_auto_scale(self):
@pytest.mark.asyncio
async def test_autoscale_create_container_async(self):
await self._set_up()
created_container = await self.created_database.create_container(
id='container_with_auto_scale_settings',
partition_key=PartitionKey(path="/id"),
Expand All @@ -56,92 +57,86 @@ async def test_auto_scale(self):
)
created_container_properties = await created_container.get_throughput()
# Testing the input value of the max_throughput
self.assertEqual(
created_container_properties.auto_scale_max_throughput, 5000)
self.assertEqual(created_container_properties.auto_scale_increment_percent, 0)
self.assertEqual(created_container_properties.offer_throughput, None)
assert created_container_properties.auto_scale_max_throughput == 5000
assert created_container_properties.auto_scale_increment_percent == 0
assert created_container_properties.offer_throughput is None

await self.created_database.delete_container(created_container)

# Testing the incorrect passing of an input value of the max_throughput to verify negative behavior
with pytest.raises(exceptions.CosmosHttpResponseError) as e:
created_container = await self.created_database.create_container(
await self.created_database.create_container(
id='container_with_wrong_auto_scale_settings',
partition_key=PartitionKey(path="/id"),
offer_throughput=ThroughputProperties(auto_scale_max_throughput=-200, auto_scale_increment_percent=0))
assert "Requested throughput -200 is less than required minimum throughput 1000" in str(e.value)

async def test_create_container_if_not_exist(self):
# Testing auto_scale_settings for the create_container_if_not_exists method
created_container = await self.created_database.create_container_if_not_exists(
id='container_with_auto_scale_settings',
partition_key=PartitionKey(path="/id"),
offer_throughput=ThroughputProperties(auto_scale_max_throughput=1000, auto_scale_increment_percent=0)
offer_throughput=ThroughputProperties(auto_scale_max_throughput=1000, auto_scale_increment_percent=3)
)
created_container_properties = await created_container.get_throughput()
# Testing the incorrect input value of the max_throughput
self.assertNotEqual(
created_container_properties.auto_scale_max_throughput, 2000)

await self.created_database.delete_container(created_container)

created_container = await self.created_database.create_container_if_not_exists(
id='container_with_auto_scale_settings',
partition_key=PartitionKey(path="/id"),
offer_throughput=ThroughputProperties(auto_scale_max_throughput=5000, auto_scale_increment_percent=2)

)
created_container_properties = await created_container.get_throughput()
# Testing the incorrect input value of the max_increment_percentage
self.assertNotEqual(
created_container_properties.auto_scale_increment_percent, 3)
# Testing the input value of the max_throughput
assert created_container_properties.auto_scale_max_throughput == 1000
# Testing the input value of the increment_percentage
assert created_container_properties.auto_scale_increment_percent == 3

await self.created_database.delete_container(created_container)
await self.created_database.delete_container(created_container.id)

async def test_create_database(self):
@pytest.mark.asyncio
async def test_autoscale_create_database_async(self):
await self._set_up()
# Testing auto_scale_settings for the create_database method
created_database = await self.client.create_database("db1", offer_throughput=ThroughputProperties(
auto_scale_max_throughput=5000,
auto_scale_increment_percent=0))
created_db_properties = await created_database.get_throughput()
# Testing the input value of the max_throughput
self.assertEqual(
created_db_properties.auto_scale_max_throughput, 5000)
assert created_db_properties.auto_scale_max_throughput == 5000
# Testing the input value of the increment_percentage
self.assertEqual(
created_db_properties.auto_scale_increment_percent, 0)
assert created_db_properties.auto_scale_increment_percent == 0

await self.client.delete_database("db1")

async def test_create_database_if_not_exists(self):
# Testing auto_scale_settings for the create_database_if_not_exists method
created_database = await self.client.create_database_if_not_exists("db2", offer_throughput=ThroughputProperties(
auto_scale_max_throughput=9000,
auto_scale_increment_percent=11))
created_db_properties = await created_database.get_throughput()
# Testing the input value of the max_throughput
self.assertNotEqual(
created_db_properties.auto_scale_max_throughput, 8000)
assert created_db_properties.auto_scale_max_throughput == 9000
# Testing the input value of the increment_percentage
self.assertEqual(
created_db_properties.auto_scale_increment_percent, 11)
assert created_db_properties.auto_scale_increment_percent == 11

await self.client.delete_database("db2")

async def test_replace_throughput(self):
@pytest.mark.asyncio
async def test_replace_throughput_async(self):
await self._set_up()

created_database = await self.client.create_database("replace_db", offer_throughput=ThroughputProperties(
auto_scale_max_throughput=5000,
auto_scale_increment_percent=0))
await created_database.replace_throughput(
throughput=ThroughputProperties(auto_scale_max_throughput=7000, auto_scale_increment_percent=20))
created_db_properties = await created_database.get_throughput()
# Testing the replaced value of the max_throughput
assert created_db_properties.auto_scale_max_throughput == 7000
# Testing the replaced value of the increment_percentage
assert created_db_properties.auto_scale_increment_percent == 20
await self.client.delete_database("replace_db")

created_container = await self.created_database.create_container(
id='container_with_auto_scale_settings',
partition_key=PartitionKey(path="/id"),
offer_throughput=ThroughputProperties(auto_scale_max_throughput=5000, auto_scale_increment_percent=0)

)
new_throughput = await created_container.replace_throughput(
offer_throughput=ThroughputProperties(auto_scale_max_throughput=5000, auto_scale_increment_percent=0) )
await created_container.replace_throughput(
throughput=ThroughputProperties(auto_scale_max_throughput=7000, auto_scale_increment_percent=20))
created_container_properties = await created_container.get_throughput()
# Testing the input value of the replaced auto_scale settings
self.assertEqual(
created_container_properties.auto_scale_max_throughput, 7000)
self.assertEqual(
created_container_properties.auto_scale_increment_percent, 20)
assert created_container_properties.auto_scale_max_throughput == 7000
assert created_container_properties.auto_scale_increment_percent == 20

await self.client.delete_database(test_config._test_config.TEST_DATABASE_ID)
Loading