Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b2cb0a5
Added Cross partition query tests for sync and async APIs
kushagraThapar Dec 1, 2023
a3fcabb
Added license header for new files
kushagraThapar Dec 1, 2023
bc81ab2
Updated database and container creation
kushagraThapar Dec 4, 2023
187b3d2
Updated python tests with setup and tear down
kushagraThapar Dec 8, 2023
f589e48
Fixed some tests cases
kushagraThapar Dec 8, 2023
40cf21e
Fixed spelling
kushagraThapar Dec 8, 2023
998b997
Added emulator CI
kushagraThapar Dec 12, 2023
f7d9ca4
Merged latest main and resolved conflicts
kushagraThapar Jan 12, 2024
cbaf26e
Removed python 3.7 emulator tests config
kushagraThapar Jan 12, 2024
d1434ae
Removed collection crud tests from emulator
kushagraThapar Jan 17, 2024
ade8a78
Merged latest main and resolved conflicts
kushagraThapar Jan 17, 2024
c7ccc22
Updated some collection heavy tests to skip for emulator
kushagraThapar Jan 17, 2024
cafc996
Fixing python 3.10
kushagraThapar Jan 18, 2024
b763f8b
Marking test_computed_properties async test to run only in live tests
kushagraThapar Jan 22, 2024
d95157a
Merge branch 'main' into azure_cosmos_add_cross_partition_query_tests
kushagraThapar Jan 22, 2024
7a34c7e
Fixed emulator tests with pytest fixtures
kushagraThapar Jan 29, 2024
c05e65c
Fixed more emulator tests with pytest fixtures
kushagraThapar Jan 30, 2024
6252619
Fixed more emulator tests with pytest fixtures
kushagraThapar Jan 31, 2024
420d639
Fixed more emulator tests with pytest fixtures and updated azure core…
kushagraThapar Feb 1, 2024
acbb98a
Fixed flaky tests
kushagraThapar Feb 1, 2024
a64f69c
Updated stored procedure create calls
kushagraThapar Feb 1, 2024
06d708c
Fixing sproc test
kushagraThapar Feb 2, 2024
1b85744
Fixing trigger test
kushagraThapar Feb 2, 2024
9b93a8f
Fixing flaky live ci tests
kushagraThapar Feb 5, 2024
499ef27
Fixing max parallel and removed python 3.11 for cosmos emulator windo…
kushagraThapar Feb 5, 2024
8198961
Added MIT license header
kushagraThapar Feb 7, 2024
b51d6f6
Update sdk/cosmos/azure-cosmos/test/test_partition_split_query.py
simorenoh Feb 7, 2024
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
Prev Previous commit
Next Next commit
Fixed more emulator tests with pytest fixtures and updated azure core…
… min version
  • Loading branch information
kushagraThapar committed Feb 1, 2024
commit 420d639f7b1725c2a84c9dc6ff0251d7a3e54591
2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
packages=find_packages(exclude=exclude_packages),
python_requires=">=3.8",
install_requires=[
"azure-core<2.0.0,>=1.25.0",
"azure-core<2.0.0,>=1.25.1",
"typing-extensions>=4.6.0",
],
)
38 changes: 0 additions & 38 deletions sdk/cosmos/azure-cosmos/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,10 @@

# pytest fixture 'teardown' is called at the end of a test run to clean up resources

import pytest

import test_config
from azure.cosmos import CosmosClient as CosmosSyncClient
from azure.cosmos.aio import CosmosClient as CosmosAsyncClient

cosmos_sync_client = CosmosSyncClient(test_config.TestConfig.host, test_config.TestConfig.masterKey)
cosmos_async_client = CosmosAsyncClient(test_config.TestConfig.host, test_config.TestConfig.masterKey)


@pytest.fixture(scope="session", autouse=True)
def get_cosmos_sync_client():
return cosmos_sync_client


@pytest.fixture(scope="session", autouse=True)
def get_cosmos_async_client():
return cosmos_async_client


@pytest.fixture(scope="session")
def create_test_database():
config = test_config.TestConfig
config.create_database_if_not_exist(cosmos_sync_client)


@pytest.fixture(scope="session")
def create_multi_partition_container():
config = test_config.TestConfig
config.create_multi_partition_container_if_not_exist(cosmos_sync_client)


@pytest.fixture(scope="session")
def create_single_partition_container():
config = test_config.TestConfig
config.create_single_partition_container_if_not_exist(cosmos_sync_client)


@pytest.fixture(scope="session")
def delete_test_database():
config = test_config.TestConfig
config.try_delete_database(cosmos_sync_client)


def pytest_configure(config):
Expand Down
3 changes: 3 additions & 0 deletions sdk/cosmos/azure-cosmos/test/test_base_unit.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import unittest

import pytest

import azure.cosmos._base as base


@pytest.mark.cosmosEmulator
class TestIdAndNameBased(unittest.TestCase):
def test_is_name_based(self):
self.assertFalse(base.IsNameBased("dbs/xjwmAA==/"))
Expand Down
24 changes: 12 additions & 12 deletions sdk/cosmos/azure-cosmos/test/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def send(self, *args, **kwargs):


@pytest.mark.cosmosEmulator
class CRUDTests(unittest.TestCase):
class TestCRUDOperations(unittest.TestCase):
"""Python CRUD Tests.
"""

Expand Down Expand Up @@ -533,7 +533,7 @@ def test_partitioned_collection_permissions(self):
read_permission.properties['_token'])

restricted_client = cosmos_client.CosmosClient(
CRUDTests.host, resource_tokens, "Session", connection_policy=CRUDTests.connectionPolicy)
TestCRUDOperations.host, resource_tokens, "Session", connection_policy=TestCRUDOperations.connectionPolicy)

document_definition = {'id': 'document1',
'key': 1
Expand Down Expand Up @@ -1322,22 +1322,22 @@ def __SetupEntities(client):

# Client without any authorization will fail.
try:
cosmos_client.CosmosClient(CRUDTests.host, {}, "Session", connection_policy=CRUDTests.connectionPolicy)
cosmos_client.CosmosClient(TestCRUDOperations.host, {}, "Session", connection_policy=TestCRUDOperations.connectionPolicy)
raise Exception("Test did not fail as expected.")
except exceptions.CosmosHttpResponseError as error:
self.assertEqual(error.status_code, StatusCodes.UNAUTHORIZED)

# Client with master key.
client = cosmos_client.CosmosClient(CRUDTests.host,
CRUDTests.masterKey,
client = cosmos_client.CosmosClient(TestCRUDOperations.host,
TestCRUDOperations.masterKey,
"Session",
connection_policy=CRUDTests.connectionPolicy)
connection_policy=TestCRUDOperations.connectionPolicy)
# setup entities
entities = __SetupEntities(client)
resource_tokens = {"dbs/" + entities['db'].id + "/colls/" + entities['coll'].id:
entities['permissionOnColl'].properties['_token']}
col_client = cosmos_client.CosmosClient(
CRUDTests.host, resource_tokens, "Session", connection_policy=CRUDTests.connectionPolicy)
TestCRUDOperations.host, resource_tokens, "Session", connection_policy=TestCRUDOperations.connectionPolicy)
db = entities['db']

old_client_connection = db.client_connection
Expand Down Expand Up @@ -1377,7 +1377,7 @@ def __SetupEntities(client):
entities['permissionOnDoc'].properties['_token']}

doc_client = cosmos_client.CosmosClient(
CRUDTests.host, resource_tokens, "Session", connection_policy=CRUDTests.connectionPolicy)
TestCRUDOperations.host, resource_tokens, "Session", connection_policy=TestCRUDOperations.connectionPolicy)

# 6. Success-- Use Doc permission to read doc
read_doc = doc_client.get_database_client(db.id).get_container_client(success_coll.id).read_item(docId, docId)
Expand Down Expand Up @@ -1843,7 +1843,7 @@ def test_client_request_timeout(self):

with self.assertRaises(Exception):
# client does a getDatabaseAccount on initialization, which will time out
cosmos_client.CosmosClient(CRUDTests.host, CRUDTests.masterKey, "Session",
cosmos_client.CosmosClient(TestCRUDOperations.host, TestCRUDOperations.masterKey, "Session",
connection_policy=connection_policy)

@pytest.mark.cosmosLiveTest
Expand All @@ -1860,7 +1860,7 @@ def test_client_request_timeout_when_connection_retry_configuration_specified(se
)
with self.assertRaises(AzureError):
# client does a getDatabaseAccount on initialization, which will time out
cosmos_client.CosmosClient(CRUDTests.host, CRUDTests.masterKey, "Session",
cosmos_client.CosmosClient(TestCRUDOperations.host, TestCRUDOperations.masterKey, "Session",
connection_policy=connection_policy)

def test_client_connection_retry_configuration(self):
Expand All @@ -1873,7 +1873,7 @@ def initialize_client_with_connection_core_retry_config(self, retries):
try:
cosmos_client.CosmosClient(
"https://localhost:9999",
CRUDTests.masterKey,
TestCRUDOperations.masterKey,
"Session",
retry_total=retries,
retry_read=retries,
Expand All @@ -1890,7 +1890,7 @@ def test_absolute_client_timeout(self):
with self.assertRaises(exceptions.CosmosClientTimeoutError):
cosmos_client.CosmosClient(
"https://localhost:9999",
CRUDTests.masterKey,
TestCRUDOperations.masterKey,
"Session",
retry_total=3,
timeout=1)
Expand Down
28 changes: 14 additions & 14 deletions sdk/cosmos/azure-cosmos/test/test_crud_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def send(self, *args, **kwargs):
return response


class TestCRUDAsync(unittest.IsolatedAsyncioTestCase):
class TestCRUDOperationsAsync(unittest.IsolatedAsyncioTestCase):
"""Python CRUD Tests.
"""
client: CosmosClient = None
Expand Down Expand Up @@ -516,7 +516,7 @@ async def test_partitioned_collection_permissions_async(self):
resource_tokens["dbs/" + created_db.id + "/colls/" + read_collection.id] = (
read_permission.properties['_token'])

async with CosmosClient(TestCRUDAsync.host, resource_tokens) as restricted_client:
async with CosmosClient(TestCRUDOperationsAsync.host, resource_tokens) as restricted_client:
print('Async Initialization')

document_definition = {'id': 'document1',
Expand Down Expand Up @@ -1235,21 +1235,21 @@ async def __setup_entities():

# Client without any authorization will fail.
try:
async with CosmosClient(TestCRUDAsync.host, {}) as client:
async with CosmosClient(TestCRUDOperationsAsync.host, {}) as client:
[db async for db in client.list_databases()]
except exceptions.CosmosHttpResponseError as e:
assert e.status_code == StatusCodes.UNAUTHORIZED

# Client with master key.
async with CosmosClient(TestCRUDAsync.host,
TestCRUDAsync.masterKey) as client:
async with CosmosClient(TestCRUDOperationsAsync.host,
TestCRUDOperationsAsync.masterKey) as client:
# setup entities
entities = await __setup_entities()
resource_tokens = {"dbs/" + entities['db'].id + "/colls/" + entities['coll'].id:
entities['permissionOnColl'].properties['_token']}

async with CosmosClient(
TestCRUDAsync.host, resource_tokens) as col_client:
TestCRUDOperationsAsync.host, resource_tokens) as col_client:
db = entities['db']

old_client_connection = db.client_connection
Expand Down Expand Up @@ -1283,7 +1283,7 @@ async def __setup_entities():
entities['permissionOnDoc'].properties['_token']}

async with CosmosClient(
TestCRUDAsync.host, resource_tokens) as doc_client:
TestCRUDOperationsAsync.host, resource_tokens) as doc_client:

# 6. Success-- Use Doc permission to read doc
read_doc = await doc_client.get_database_client(db.id).get_container_client(success_coll.id).read_item(
Expand Down Expand Up @@ -1714,7 +1714,7 @@ async def test_client_request_timeout_async(self):

with self.assertRaises(Exception):
# client does a getDatabaseAccount on initialization, which will time out
async with CosmosClient(TestCRUDAsync.host, TestCRUDAsync.masterKey,
async with CosmosClient(TestCRUDOperationsAsync.host, TestCRUDOperationsAsync.masterKey,
connection_policy=connection_policy) as client:
print('Async initialization')

Expand All @@ -1724,7 +1724,7 @@ async def test_client_request_timeout_when_connection_retry_configuration_specif
connection_policy.RequestTimeout = 0.000000000001
with self.assertRaises(AzureError):
# client does a getDatabaseAccount on initialization, which will time out
async with CosmosClient(TestCRUDAsync.host, TestCRUDAsync.masterKey,
async with CosmosClient(TestCRUDOperationsAsync.host, TestCRUDOperationsAsync.masterKey,
connection_policy=connection_policy,
retry_total=3, retry_connect=3, retry_read=3, retry_backoff_max=0.3,
retry_on_status_codes=[500, 502, 504]) as client:
Expand All @@ -1742,7 +1742,7 @@ async def test_client_connection_retry_configuration_async(self):
async def initialize_client_with_connection_urllib_retry_config(self, retries):
start_time = time.time()
try:
async with CosmosClient("https://localhost:9999", TestCRUDAsync.masterKey,
async with CosmosClient("https://localhost:9999", TestCRUDOperationsAsync.masterKey,
retry_total=retries, retry_connect=retries, retry_read=retries,
retry_backoff_max=0.3, retry_on_status_codes=[500, 502, 504]) as client:
print('Async initialization')
Expand All @@ -1756,7 +1756,7 @@ async def initialize_client_with_connection_core_retry_config(self, retries):
try:
async with CosmosClient(
"https://localhost:9999",
TestCRUDAsync.masterKey,
TestCRUDOperationsAsync.masterKey,
retry_total=retries,
retry_read=retries,
retry_connect=retries,
Expand All @@ -1773,7 +1773,7 @@ async def test_absolute_client_timeout_async(self):
with self.assertRaises(exceptions.CosmosClientTimeoutError):
async with CosmosClient(
"https://localhost:9999",
TestCRUDAsync.masterKey,
TestCRUDOperationsAsync.masterKey,
retry_total=3,
timeout=1) as client:
print('Async initialization')
Expand Down Expand Up @@ -1816,8 +1816,8 @@ async def test_absolute_client_timeout_async(self):

async def test_query_iterable_functionality_async(self):

collection = await self.database_for_test.create_container_if_not_exists("query-iterable-container-async",
PartitionKey(path="/pk"))
collection = await self.database_for_test.create_container("query-iterable-container-async",
PartitionKey(path="/pk"))
doc1 = await collection.upsert_item(body={'id': 'doc1', 'prop1': 'value1'})
doc2 = await collection.upsert_item(body={'id': 'doc2', 'prop1': 'value2'})
doc3 = await collection.upsert_item(body={'id': 'doc3', 'prop1': 'value3'})
Expand Down
14 changes: 4 additions & 10 deletions sdk/cosmos/azure-cosmos/test/test_crud_subpartition.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,14 @@ def test_collection_crud(self):
self.__AssertHTTPFailureWithStatus(StatusCodes.NOT_FOUND,
created_container.read)

container_proxy = created_db.create_container_if_not_exists(id=created_collection.id,
partition_key=PartitionKey(path=
["/id1", "/id2", "/id3"],
kind='MultiHash'))
container_proxy = created_db.create_container(id=created_collection.id,
partition_key=PartitionKey(path=
["/id1", "/id2", "/id3"],
kind='MultiHash'))
self.assertEqual(created_collection.id, container_proxy.id)
self.assertDictEqual(PartitionKey(path=["/id1", "/id2", "/id3"], kind='MultiHash'),
container_proxy._properties['partitionKey'])

container_proxy = created_db.create_container_if_not_exists(id=created_collection.id,
partition_key=created_properties['partitionKey'])
self.assertEqual(created_container.id, container_proxy.id)
self.assertDictEqual(PartitionKey(path=["/id1", "/id2", "/id3"], kind='MultiHash'),
container_proxy._properties['partitionKey'])

created_db.delete_container(created_collection.id)

def test_partitioned_collection(self):
Expand Down
19 changes: 5 additions & 14 deletions sdk/cosmos/azure-cosmos/test/test_crud_subpartition_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,12 @@ async def test_collection_crud_async(self):
await self.__assert_http_failure_with_status(StatusCodes.NOT_FOUND,
created_container.read)

container_proxy = await created_db.create_container_if_not_exists(id=created_collection.id,
partition_key=PartitionKey(path=['/id1',
'/id2',
'/id3'],
kind='MultiHash'))
container_proxy = await created_db.create_container(id=created_collection.id,
partition_key=PartitionKey(path=['/id1',
'/id2',
'/id3'],
kind='MultiHash'))
assert created_collection.id == container_proxy.id
container_proxy_properties = await container_proxy._get_properties()
assert PartitionKey(path=["/id1", "/id2", "/id3"], kind='MultiHash') == container_proxy_properties[
'partitionKey']

container_proxy = await created_db.create_container_if_not_exists(id=created_collection.id,
partition_key=created_properties[
'partitionKey'])
assert created_container.id == container_proxy.id

container_proxy_properties = await container_proxy._get_properties()
assert PartitionKey(path=["/id1", "/id2", "/id3"], kind='MultiHash') == container_proxy_properties[
'partitionKey']
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos/test/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@pytest.mark.cosmosEmulator
class EncodingTest(unittest.TestCase):
class TestEncoding(unittest.TestCase):
"""Test to ensure escaping of non-ascii characters from partition key"""

host = test_config.TestConfig.host
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos/test/test_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


@pytest.mark.cosmosEmulator
class HeadersTest(unittest.TestCase):
class TestHeaders(unittest.TestCase):
database: DatabaseProxy = None
client: cosmos_client.CosmosClient = None
configs = test_config.TestConfig
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos/test/test_location_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run(self):


@pytest.mark.cosmosEmulator
class LocationCacheTest(unittest.TestCase):
class TestLocationCache(unittest.TestCase):
DEFAULT_ENDPOINT = "https://default.documents.azure.com"
LOCATION_1_ENDPOINT = "https://location1.documents.azure.com"
LOCATION_2_ENDPOINT = "https://location2.documents.azure.com"
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos/test/test_multi_orderby.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


@pytest.mark.cosmosEmulator
class MultiOrderbyTests(unittest.TestCase):
class TestMultiOrderBy(unittest.TestCase):
"""Multi Orderby and Composite Indexes Tests.
"""

Expand Down
6 changes: 3 additions & 3 deletions sdk/cosmos/azure-cosmos/test/test_multimaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@pytest.mark.cosmosEmulator
class MultiMasterTests(unittest.TestCase):
class TestMultiMaster(unittest.TestCase):
host = test_config.TestConfig.host
masterKey = test_config.TestConfig.masterKey
connectionPolicy = test_config.TestConfig.connectionPolicy
Expand All @@ -33,9 +33,9 @@ def _validate_tentative_write_headers(self):
self.OriginalExecuteFunction = _retry_utility.ExecuteFunction
_retry_utility.ExecuteFunction = self._MockExecuteFunction

connectionPolicy = MultiMasterTests.connectionPolicy
connectionPolicy = TestMultiMaster.connectionPolicy
connectionPolicy.UseMultipleWriteLocations = True
client = cosmos_client.CosmosClient(MultiMasterTests.host, MultiMasterTests.masterKey,
client = cosmos_client.CosmosClient(TestMultiMaster.host, TestMultiMaster.masterKey,
consistency_level="Session",
connection_policy=connectionPolicy)

Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos/test/test_murmurhash3.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


@pytest.mark.cosmosEmulator
class MurmurHash3Test(unittest.TestCase):
class TestMurmurHash3(unittest.TestCase):
"""Python Murmurhash3 Tests and its compatibility with backend implementation..
"""
string_low_value = 2792699143512860960
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos/test/test_orderby.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@


@pytest.mark.cosmosEmulator
class CrossPartitionTopOrderByTest(unittest.TestCase):
class TestCrossPartitionTopOrderBy(unittest.TestCase):
"""Orderby Tests.
"""

Expand Down
Loading