|
1 | 1 | import configparser |
2 | 2 | import os |
| 3 | +import random |
3 | 4 | import socket |
| 5 | +import string |
4 | 6 | import struct |
5 | 7 | import sys |
6 | 8 |
|
7 | 9 | import pytest # type: ignore |
8 | 10 |
|
9 | 11 | import redshift_connector |
| 12 | +from redshift_connector import DriverInfo |
10 | 13 | from redshift_connector.config import ClientProtocolVersion |
11 | 14 |
|
12 | 15 | conf = configparser.ConfigParser() |
@@ -198,3 +201,49 @@ def test_client_protocol_version_invalid_warns_user(db_kwargs): |
198 | 201 | del db_kwargs["cluster_identifier"] |
199 | 202 | with pytest.warns(UserWarning): |
200 | 203 | redshift_connector.Connection(**db_kwargs) |
| 204 | + |
| 205 | + |
| 206 | +def test_stl_connection_log_contains_driver_version(db_kwargs): |
| 207 | + with redshift_connector.connect(**db_kwargs) as conn: |
| 208 | + with conn.cursor() as cursor: |
| 209 | + # verify stl_connection_log contains driver version as expected |
| 210 | + cursor.execute( |
| 211 | + "select top 1 1 from stl_connection_log where driver_version = '{}'".format( |
| 212 | + DriverInfo.driver_full_name() |
| 213 | + ) |
| 214 | + ) |
| 215 | + res = cursor.fetchone() |
| 216 | + assert res is not None |
| 217 | + assert res[0] == 1 |
| 218 | + |
| 219 | + |
| 220 | +def test_stl_connection_log_contains_os_version(db_kwargs): |
| 221 | + with redshift_connector.connect(**db_kwargs) as conn: |
| 222 | + with conn.cursor() as cursor: |
| 223 | + # verify stl_connection_log contains driver version as expected |
| 224 | + cursor.execute( |
| 225 | + "select top 1 1 from stl_connection_log where driver_version = '{}' and os_version = '{}'".format( |
| 226 | + DriverInfo.driver_full_name(), conn.client_os_version |
| 227 | + ) |
| 228 | + ) |
| 229 | + res = cursor.fetchone() |
| 230 | + assert res is not None |
| 231 | + assert res[0] == 1 |
| 232 | + |
| 233 | + |
| 234 | +def test_stl_connection_log_contains_application_name(db_kwargs): |
| 235 | + # make some connection so this unique application name is logged |
| 236 | + mock_application_name: str = "".join(random.choice(string.ascii_letters) for x in range(10)) |
| 237 | + db_kwargs["application_name"] = mock_application_name |
| 238 | + |
| 239 | + with redshift_connector.connect(**db_kwargs) as conn: |
| 240 | + with conn.cursor() as cursor: |
| 241 | + # verify stl_connection_log contains driver version as expected |
| 242 | + cursor.execute( |
| 243 | + "select top 1 1 from stl_connection_log where driver_version = '{}' and application_name = '{}'".format( |
| 244 | + DriverInfo.driver_full_name(), mock_application_name |
| 245 | + ) |
| 246 | + ) |
| 247 | + res = cursor.fetchone() |
| 248 | + assert res is not None |
| 249 | + assert res[0] == 1 |
0 commit comments