Skip to content

Commit 610a6e5

Browse files
modifying test execution to use config_manager
1 parent a429377 commit 610a6e5

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

test/integ/conftest.py

+44-34
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@
1717

1818
import snowflake.connector
1919
from snowflake.connector.compat import IS_WINDOWS
20+
from snowflake.connector.config_manager import CONFIG_MANAGER
2021
from snowflake.connector.connection import DefaultConverterClass
2122

2223
from .. import running_on_public_ci
23-
from ..parameters import CONNECTION_PARAMETERS
24+
25+
try:
26+
from ..parameters import CONNECTION_PARAMETERS
27+
except ImportError:
28+
CONNECTION_PARAMETERS: dict[str, Any] = {} # type: ignore
29+
2430

2531
try:
2632
from ..parameters import CLIENT_FAILOVER_PARAMETERS # type: ignore
@@ -34,9 +40,11 @@
3440
RUNNING_ON_GH = os.getenv("GITHUB_ACTIONS") == "true"
3541
TEST_USING_VENDORED_ARROW = os.getenv("TEST_USING_VENDORED_ARROW") == "true"
3642

37-
if not isinstance(CONNECTION_PARAMETERS["host"], str):
43+
if CONNECTION_PARAMETERS and not isinstance(CONNECTION_PARAMETERS.get("host"), str):
3844
raise Exception("default host is not a string in parameters.py")
39-
RUNNING_AGAINST_LOCAL_SNOWFLAKE = CONNECTION_PARAMETERS["host"].endswith("local")
45+
RUNNING_AGAINST_LOCAL_SNOWFLAKE = CONNECTION_PARAMETERS.get("host", "").endswith(
46+
"local"
47+
)
4048

4149
try:
4250
from ..parameters import CONNECTION_PARAMETERS_ADMIN # type: ignore
@@ -110,30 +118,38 @@ def get_db_parameters(connection_name: str = "default") -> dict[str, Any]:
110118
os.environ["TZ"] = "UTC"
111119
if not IS_WINDOWS:
112120
time.tzset()
113-
114-
connections = {
115-
"default": CONNECTION_PARAMETERS,
116-
"client_failover": CLIENT_FAILOVER_PARAMETERS,
117-
"admin": CONNECTION_PARAMETERS_ADMIN,
118-
}
119-
120-
chosen_connection = connections[connection_name]
121-
if "account" not in chosen_connection:
122-
pytest.skip(f"{connection_name} connection is unavailable in parameters.py")
123-
124-
# testaccount connection info
125-
ret = {**DEFAULT_PARAMETERS, **chosen_connection}
126-
127-
# snowflake admin account. Not available in GH actions
128-
for k, v in CONNECTION_PARAMETERS_ADMIN.items():
129-
ret["sf_" + k] = v
130-
131-
if "host" in ret and ret["host"] == DEFAULT_PARAMETERS["host"]:
132-
ret["host"] = ret["account"] + ".snowflakecomputing.com"
133-
134-
if "account" in ret and ret["account"] == DEFAULT_PARAMETERS["account"]:
135-
print_help()
136-
sys.exit(2)
121+
cm_connection_name = (
122+
CONFIG_MANAGER["default_connection_name"]
123+
if connection_name == "default"
124+
else connection_name
125+
)
126+
if cm_connection_name in CONFIG_MANAGER["connections"]:
127+
# If config_manager knows of this connection then use it
128+
ret = CONFIG_MANAGER["connections"][cm_connection_name].value.value
129+
else:
130+
connections = {
131+
"default": CONNECTION_PARAMETERS,
132+
"failover": CLIENT_FAILOVER_PARAMETERS,
133+
"admin": CONNECTION_PARAMETERS_ADMIN,
134+
}
135+
136+
chosen_connection = connections[connection_name]
137+
if "account" not in chosen_connection:
138+
pytest.skip(f"{connection_name} connection is unavailable in parameters.py")
139+
140+
# testaccount connection info
141+
ret = {**DEFAULT_PARAMETERS, **chosen_connection}
142+
143+
# snowflake admin account. Not available in GH actions
144+
for k, v in CONNECTION_PARAMETERS_ADMIN.items():
145+
ret["sf_" + k] = v
146+
147+
if "host" in ret and ret["host"] == DEFAULT_PARAMETERS["host"]:
148+
ret["host"] = ret["account"] + ".snowflakecomputing.com"
149+
150+
if "account" in ret and ret["account"] == DEFAULT_PARAMETERS["account"]:
151+
print_help()
152+
sys.exit(2)
137153

138154
# a unique table name
139155
ret["name"] = "python_tests_" + str(uuid.uuid4()).replace("-", "_")
@@ -170,13 +186,7 @@ def init_test_schema(db_parameters) -> Generator[None, None, None]:
170186
"""
171187
ret = db_parameters
172188
with snowflake.connector.connect(
173-
user=ret["user"],
174-
password=ret["password"],
175-
host=ret["host"],
176-
port=ret["port"],
177-
database=ret["database"],
178-
account=ret["account"],
179-
protocol=ret["protocol"],
189+
**ret,
180190
) as con:
181191
con.cursor().execute(f"CREATE SCHEMA IF NOT EXISTS {TEST_SCHEMA}")
182192
yield

test/integ/test_connection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ def test_client_prefetch_threads_setting(conn_cnx):
11331133

11341134
@pytest.mark.external
11351135
def test_client_failover_connection_url(conn_cnx):
1136-
with conn_cnx("client_failover") as conn:
1136+
with conn_cnx("failover") as conn:
11371137
with conn.cursor() as cur:
11381138
assert cur.execute("select 1;").fetchall() == [
11391139
(1,),

0 commit comments

Comments
 (0)