Skip to content

Commit 99af7a2

Browse files
authored
feat: Turn off token cache param (#54)
1 parent bddcae0 commit 99af7a2

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/firebolt_db/firebolt_dialect.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from distutils.util import strtobool
23
from types import ModuleType
34
from typing import Any, Dict, List, Optional, Tuple, Union
45

@@ -112,6 +113,12 @@ def create_connect_args(self, url: URL) -> Tuple[List, Dict]:
112113
parameters = dict(url.query)
113114
if "account_name" in parameters:
114115
kwargs["account_name"] = parameters.pop("account_name")
116+
if "use_token_cache" in parameters:
117+
# parameters are all passed as a string, we need to convert it
118+
# to boolean for SDK compatibility
119+
kwargs["use_token_cache"] = bool(
120+
strtobool(parameters.pop("use_token_cache"))
121+
)
115122
self._set_parameters = parameters
116123
# If URL override is not provided leave it to the sdk to determine the endpoint
117124
if "FIREBOLT_BASE_URL" in os.environ:

tests/unit/test_firebolt_dialect.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import sqlalchemy
55
from conftest import MockCursor, MockDBApi
6+
from pytest import mark
67
from sqlalchemy.engine import url
78
from sqlalchemy.sql import text
89

@@ -46,6 +47,7 @@ def test_create_connect_args(self, dialect: FireboltDialect):
4647
with mock.patch.dict(os.environ, {}, clear=True):
4748
result_list, result_dict = dialect.create_connect_args(u)
4849
assert "api_endpoint" not in result_dict
50+
assert "use_token_cache" not in result_dict
4951
assert result_list == []
5052

5153
def test_create_connect_args_set_params(self, dialect: FireboltDialect):
@@ -60,6 +62,24 @@ def test_create_connect_args_set_params(self, dialect: FireboltDialect):
6062
), "account_name was not parsed correctly from connection string"
6163
assert dialect._set_parameters == {"param1": "1", "param2": "2"}
6264

65+
@mark.parametrize(
66+
"token,expected", [("false", False), ("0", False), ("true", True)]
67+
)
68+
def test_create_connect_args_token_cache(
69+
self, token, expected, dialect: FireboltDialect
70+
):
71+
connection_url = (
72+
"test_engine://test_user@email:test_password@test_db_name/test_engine_name"
73+
f"?use_token_cache={token}&param1=1&param2=2"
74+
)
75+
u = url.make_url(connection_url)
76+
result_list, result_dict = dialect.create_connect_args(u)
77+
assert (
78+
"use_token_cache" in result_dict
79+
), "use_token_cache was not parsed correctly from connection string"
80+
assert result_dict["use_token_cache"] == expected
81+
assert dialect._set_parameters == {"param1": "1", "param2": "2"}
82+
6383
def test_do_execute(
6484
self, dialect: FireboltDialect, cursor: mock.Mock(spec=MockCursor)
6585
):

0 commit comments

Comments
 (0)