|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 | 15 | import json
|
16 |
| -from typing import Any |
| 16 | +from typing import Any, Optional |
17 | 17 |
|
18 | 18 | from aiohttp import web
|
19 | 19 | from mocks import FakeCredentials
|
@@ -102,3 +102,52 @@ async def test_AlloyDBClient_init_(credentials: FakeCredentials) -> None:
|
102 | 102 | assert client._client.headers["x-goog-user-project"] == "my-quota-project"
|
103 | 103 | # close client
|
104 | 104 | await client.close()
|
| 105 | + |
| 106 | + |
| 107 | +@pytest.mark.parametrize( |
| 108 | + "driver", |
| 109 | + [None, "pg8000", "asyncpg"], |
| 110 | +) |
| 111 | +@pytest.mark.asyncio |
| 112 | +async def test_AlloyDBClient_user_agent( |
| 113 | + driver: Optional[str], credentials: FakeCredentials |
| 114 | +) -> None: |
| 115 | + """ |
| 116 | + Test to check whether the __init__ method of AlloyDBClient |
| 117 | + properly sets user agent when passed a database driver. |
| 118 | + """ |
| 119 | + client = AlloyDBClient( |
| 120 | + "www.test-endpoint.com", "my-quota-project", credentials, driver=driver |
| 121 | + ) |
| 122 | + if driver is None: |
| 123 | + assert ( |
| 124 | + client._client.headers["User-Agent"] |
| 125 | + == f"alloydb-python-connector/{version}" |
| 126 | + ) |
| 127 | + else: |
| 128 | + assert ( |
| 129 | + client._client.headers["User-Agent"] |
| 130 | + == f"alloydb-python-connector/{version}+{driver}" |
| 131 | + ) |
| 132 | + # close client |
| 133 | + await client.close() |
| 134 | + |
| 135 | + |
| 136 | +@pytest.mark.parametrize( |
| 137 | + "driver, expected", |
| 138 | + [(None, False), ("pg8000", True), ("asyncpg", False)], |
| 139 | +) |
| 140 | +@pytest.mark.asyncio |
| 141 | +async def test_AlloyDBClient_use_metadata( |
| 142 | + driver: Optional[str], expected: bool, credentials: FakeCredentials |
| 143 | +) -> None: |
| 144 | + """ |
| 145 | + Test to check whether the __init__ method of AlloyDBClient |
| 146 | + properly sets use_metadata. |
| 147 | + """ |
| 148 | + client = AlloyDBClient( |
| 149 | + "www.test-endpoint.com", "my-quota-project", credentials, driver=driver |
| 150 | + ) |
| 151 | + assert client._use_metadata == expected |
| 152 | + # close client |
| 153 | + await client.close() |
0 commit comments