4
4
5
5
from __future__ import annotations
6
6
7
+ import os
7
8
import pathlib
8
9
from typing import Any , Generator
10
+ from unittest .mock import patch
9
11
10
12
import pytest
11
13
@@ -51,17 +53,24 @@ async def test_valid_pat_async(wiremock_client: WiremockClient) -> None:
51
53
wiremock_generic_data_dir / "snowflake_disconnect_successful.json"
52
54
)
53
55
54
- connection = SnowflakeConnection (
55
- user = "testUser" ,
56
- authenticator = PROGRAMMATIC_ACCESS_TOKEN ,
57
- token = "some PAT" ,
58
- account = "testAccount" ,
59
- protocol = "http" ,
60
- host = wiremock_client .wiremock_host ,
61
- port = wiremock_client .wiremock_http_port ,
62
- )
63
- await connection .connect ()
64
- await connection .close ()
56
+ # Ensure SF_PARTNER is not set so async connector uses default "AsyncioPythonConnector"
57
+ with patch .dict (os .environ , {}, clear = False ):
58
+ # Remove SF_PARTNER if it exists
59
+ if "SF_PARTNER" in os .environ :
60
+ del os .environ ["SF_PARTNER" ]
61
+
62
+ connection = SnowflakeConnection (
63
+ user = "testUser" ,
64
+ authenticator = PROGRAMMATIC_ACCESS_TOKEN ,
65
+ token = "some PAT" ,
66
+ account = "testAccount" ,
67
+ protocol = "http" ,
68
+ host = wiremock_client .wiremock_host ,
69
+ port = wiremock_client .wiremock_http_port ,
70
+ autocommit = True , # Enable autocommit to prevent COMMIT calls during cleanup
71
+ )
72
+ await connection .connect ()
73
+ await connection .close ()
65
74
66
75
67
76
@pytest .mark .skipolddriver
@@ -77,19 +86,27 @@ async def test_invalid_pat_async(wiremock_client: WiremockClient) -> None:
77
86
)
78
87
wiremock_client .import_mapping (wiremock_data_dir / "invalid_token_async.json" )
79
88
80
- with pytest .raises (snowflake .connector .errors .DatabaseError ) as execinfo :
81
- connection = SnowflakeConnection (
82
- user = "testUser" ,
83
- authenticator = PROGRAMMATIC_ACCESS_TOKEN ,
84
- token = "some PAT" ,
85
- account = "testAccount" ,
86
- protocol = "http" ,
87
- host = wiremock_client .wiremock_host ,
88
- port = wiremock_client .wiremock_http_port ,
89
- )
90
- await connection .connect ()
91
-
92
- assert str (execinfo .value ).endswith ("Programmatic access token is invalid." )
89
+ # Ensure SF_PARTNER is not set so async connector uses default "AsyncioPythonConnector"
90
+ with patch .dict (os .environ , {}, clear = False ):
91
+ # Remove SF_PARTNER if it exists
92
+ if "SF_PARTNER" in os .environ :
93
+ del os .environ ["SF_PARTNER" ]
94
+
95
+ with pytest .raises (snowflake .connector .errors .DatabaseError ) as execinfo :
96
+ connection = SnowflakeConnection (
97
+ user = "testUser" ,
98
+ authenticator = PROGRAMMATIC_ACCESS_TOKEN ,
99
+ token = "some PAT" ,
100
+ account = "testAccount" ,
101
+ protocol = "http" ,
102
+ host = wiremock_client .wiremock_host ,
103
+ port = wiremock_client .wiremock_http_port ,
104
+ autocommit = True , # Enable autocommit to prevent COMMIT calls during cleanup
105
+ )
106
+ await connection .connect ()
107
+ await connection .close ()
108
+
109
+ assert str (execinfo .value ).endswith ("Programmatic access token is invalid." )
93
110
94
111
95
112
@pytest .mark .skipolddriver
@@ -119,15 +136,22 @@ async def test_pat_as_password_async(wiremock_client: WiremockClient) -> None:
119
136
wiremock_generic_data_dir / "snowflake_disconnect_successful.json"
120
137
)
121
138
122
- connection = SnowflakeConnection (
123
- user = "testUser" ,
124
- authenticator = PROGRAMMATIC_ACCESS_TOKEN ,
125
- token = None ,
126
- password = "some PAT" ,
127
- account = "testAccount" ,
128
- protocol = "http" ,
129
- host = wiremock_client .wiremock_host ,
130
- port = wiremock_client .wiremock_http_port ,
131
- )
132
- await connection .connect ()
133
- await connection .close ()
139
+ # Ensure SF_PARTNER is not set so async connector uses default "AsyncioPythonConnector"
140
+ with patch .dict (os .environ , {}, clear = False ):
141
+ # Remove SF_PARTNER if it exists
142
+ if "SF_PARTNER" in os .environ :
143
+ del os .environ ["SF_PARTNER" ]
144
+
145
+ connection = SnowflakeConnection (
146
+ user = "testUser" ,
147
+ authenticator = PROGRAMMATIC_ACCESS_TOKEN ,
148
+ token = None ,
149
+ password = "some PAT" ,
150
+ account = "testAccount" ,
151
+ protocol = "http" ,
152
+ host = wiremock_client .wiremock_host ,
153
+ port = wiremock_client .wiremock_http_port ,
154
+ autocommit = True , # Enable autocommit to prevent COMMIT calls during cleanup
155
+ )
156
+ await connection .connect ()
157
+ await connection .close ()
0 commit comments