File: test_client_user_agent.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (34 lines) | stat: -rw-r--r-- 1,618 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# The MIT License (MIT)
# Copyright (c) Microsoft Corporation. All rights reserved.

import unittest

import pytest

from azure.cosmos import CosmosClient as sync_client
from azure.cosmos.aio import CosmosClient as async_client
from test_config import TestConfig


@pytest.mark.cosmosEmulator
class TestClientUserAgent(unittest.IsolatedAsyncioTestCase):

    async def test_client_user_agent(self):
        async with async_client(url=TestConfig.host, credential=TestConfig.masterKey) as client_async:
            client_sync = sync_client(url=TestConfig.host, credential=TestConfig.masterKey)

            self.assertTrue(client_sync.client_connection._user_agent.startswith("azsdk-python-cosmos/"))
            self.assertTrue(client_async.client_connection._user_agent.startswith("azsdk-python-cosmos-async/"))
            self.assertTrue(client_async.client_connection._user_agent != client_sync.client_connection._user_agent)

    async def test_client_user_agent_suffix(self):
        async with async_client(url=TestConfig.host, credential=TestConfig.masterKey, user_agent_suffix="testAsyncSuffix") as client_async:
            client_sync = sync_client(url=TestConfig.host, credential=TestConfig.masterKey, user_agent_suffix="testSyncSuffix")

            self.assertTrue(client_sync.client_connection._user_agent.endswith(" testSyncSuffix"))
            self.assertTrue(client_async.client_connection._user_agent.endswith(" testAsyncSuffix"))
            self.assertTrue(client_async.client_connection._user_agent != client_sync.client_connection._user_agent)


if __name__ == "__main__":
    unittest.main()