|
17 | 17 |
|
18 | 18 | import snowflake.connector
|
19 | 19 | from snowflake.connector.compat import IS_WINDOWS
|
| 20 | +from snowflake.connector.config_manager import CONFIG_MANAGER |
20 | 21 | from snowflake.connector.connection import DefaultConverterClass
|
21 | 22 |
|
22 | 23 | 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 | + |
24 | 30 |
|
25 | 31 | try:
|
26 | 32 | from ..parameters import CLIENT_FAILOVER_PARAMETERS # type: ignore
|
|
34 | 40 | RUNNING_ON_GH = os.getenv("GITHUB_ACTIONS") == "true"
|
35 | 41 | TEST_USING_VENDORED_ARROW = os.getenv("TEST_USING_VENDORED_ARROW") == "true"
|
36 | 42 |
|
37 |
| -if not isinstance(CONNECTION_PARAMETERS["host"], str): |
| 43 | +if CONNECTION_PARAMETERS and not isinstance(CONNECTION_PARAMETERS.get("host"), str): |
38 | 44 | 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 | +) |
40 | 48 |
|
41 | 49 | try:
|
42 | 50 | from ..parameters import CONNECTION_PARAMETERS_ADMIN # type: ignore
|
@@ -110,30 +118,38 @@ def get_db_parameters(connection_name: str = "default") -> dict[str, Any]:
|
110 | 118 | os.environ["TZ"] = "UTC"
|
111 | 119 | if not IS_WINDOWS:
|
112 | 120 | 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) |
137 | 153 |
|
138 | 154 | # a unique table name
|
139 | 155 | ret["name"] = "python_tests_" + str(uuid.uuid4()).replace("-", "_")
|
@@ -170,13 +186,7 @@ def init_test_schema(db_parameters) -> Generator[None, None, None]:
|
170 | 186 | """
|
171 | 187 | ret = db_parameters
|
172 | 188 | 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, |
180 | 190 | ) as con:
|
181 | 191 | con.cursor().execute(f"CREATE SCHEMA IF NOT EXISTS {TEST_SCHEMA}")
|
182 | 192 | yield
|
|
0 commit comments