|
| 1 | +# The MIT License (MIT) |
| 2 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + |
| 4 | +import unittest |
| 5 | +import pytest |
| 6 | +import test_config |
| 7 | +from azure.cosmos.aio import CosmosClient |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.cosmosEmulator |
| 11 | +class TestUserAgentSuffixAsync(unittest.IsolatedAsyncioTestCase): |
| 12 | + """Python User Agent Suffix Tests. |
| 13 | + """ |
| 14 | + |
| 15 | + configs = test_config.TestConfig |
| 16 | + host = configs.host |
| 17 | + masterKey = configs.masterKey |
| 18 | + TEST_DATABASE_ID = configs.TEST_DATABASE_ID |
| 19 | + |
| 20 | + @classmethod |
| 21 | + def setUpClass(cls): |
| 22 | + if (cls.masterKey == '[YOUR_KEY_HERE]' or |
| 23 | + cls.host == '[YOUR_ENDPOINT_HERE]'): |
| 24 | + raise Exception( |
| 25 | + "You must specify your Azure Cosmos account values for " |
| 26 | + "'masterKey' and 'host' at the top of this class to run the " |
| 27 | + "tests.") |
| 28 | + |
| 29 | + async def test_user_agent_suffix_no_special_character_async(self): |
| 30 | + user_agent_suffix = "TestUserAgent" |
| 31 | + self.client = CosmosClient(self.host, self.masterKey, user_agent=user_agent_suffix) |
| 32 | + self.created_database = self.client.get_database_client(test_config.TestConfig.TEST_DATABASE_ID) |
| 33 | + |
| 34 | + read_result = await self.created_database.read() |
| 35 | + assert read_result['id'] == self.created_database.id |
| 36 | + await self.client.close() |
| 37 | + |
| 38 | + async def test_user_agent_suffix_special_character_async(self): |
| 39 | + user_agent_suffix = "TéstUserAgent's" # cspell:disable-line |
| 40 | + self.client = CosmosClient(self.host, self.masterKey, user_agent=user_agent_suffix) |
| 41 | + self.created_database = self.client.get_database_client(test_config.TestConfig.TEST_DATABASE_ID) |
| 42 | + |
| 43 | + read_result = await self.created_database.read() |
| 44 | + assert read_result['id'] == self.created_database.id |
| 45 | + await self.client.close() |
| 46 | + |
| 47 | + async def test_user_agent_suffix_unicode_character_async(self): |
| 48 | + user_agent_suffix = "UnicodeChar鱀InUserAgent" |
| 49 | + self.client = CosmosClient(self.host, self.masterKey, user_agent=user_agent_suffix) |
| 50 | + self.created_database = self.client.get_database_client(test_config.TestConfig.TEST_DATABASE_ID) |
| 51 | + |
| 52 | + read_result = await self.created_database.read() |
| 53 | + assert read_result['id'] == self.created_database.id |
| 54 | + await self.client.close() |
| 55 | + |
| 56 | + async def test_user_agent_suffix_space_character_async(self): |
| 57 | + user_agent_suffix = "UserAgent with space$%_^()*&" |
| 58 | + self.client = CosmosClient(self.host, self.masterKey, user_agent=user_agent_suffix) |
| 59 | + self.created_database = self.client.get_database_client(test_config.TestConfig.TEST_DATABASE_ID) |
| 60 | + |
| 61 | + read_result = await self.created_database.read() |
| 62 | + assert read_result['id'] == self.created_database.id |
| 63 | + await self.client.close() |
| 64 | + |
| 65 | + |
| 66 | +if __name__ == "__main__": |
| 67 | + unittest.main() |
0 commit comments