Skip to content

Commit 13ac187

Browse files
committed
add more integration tests
1 parent 5dff0fe commit 13ac187

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

Diff for: databend_sqlalchemy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
from databend_sqlalchemy.entry_points import validate_entrypoints
55

6-
VERSION = (0, 2, 1)
6+
VERSION = (0, 2, 2)
77
__version__ = '.'.join(str(x) for x in VERSION)

Diff for: databend_sqlalchemy/databend_dialect.py

+11
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,17 @@ def connect(self, *cargs, **cparams):
235235
# inherits the docstring from interfaces.Dialect.connect
236236
return self.dbapi.connect(*cargs, **cparams)
237237

238+
def create_connect_args(self, url):
239+
parameters = dict(url.query)
240+
kwargs = {
241+
'db_url': 'databend://%s:%s@%s:%d/%s' % (
242+
url.username, url.password, url.host, url.port or 8000, url.database),
243+
}
244+
for k, v in parameters.items():
245+
kwargs['db_url'] = kwargs['db_url'] + "?" + k + "=" + v
246+
247+
return ([], kwargs)
248+
238249
def _get_default_schema_name(self, connection):
239250
return connection.scalar("select currentDatabase()")
240251

Diff for: tests/integration/conftest.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def engine(
4444
username: str, password: str, host_port_name: str, database_name: str
4545
) -> Engine:
4646
return create_engine(
47-
f"databend://{username}:{password}@{host_port_name}/{database_name}"
47+
f"databend://{username}:{password}@{host_port_name}/{database_name}?secure=false"
4848
)
4949

5050

@@ -74,7 +74,7 @@ def setup_test_tables(
7474
connection.execute(
7575
text(
7676
f"""
77-
CREATE FACT TABLE IF NOT EXISTS {fact_table_name}
77+
CREATE TABLE IF NOT EXISTS {fact_table_name}
7878
(
7979
idx INT,
8080
dummy VARCHAR
@@ -85,7 +85,7 @@ def setup_test_tables(
8585
connection.execute(
8686
text(
8787
f"""
88-
CREATE DIMENSION TABLE IF NOT EXISTS {dimension_table_name}
88+
CREATE TABLE IF NOT EXISTS {dimension_table_name}
8989
(
9090
idx INT,
9191
dummy VARCHAR

Diff for: tests/integration/test_sqlalchemy_integration.py

+25-9
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ def test_set_params(
1212
self, username: str, password: str, database_name: str, host_port_name: str
1313
):
1414
engine = create_engine(
15-
f"databend://{username}:{password}@{host_port_name}/{database_name}"
15+
f"databend://{username}:{password}@{host_port_name}/{database_name}?secure=false"
1616
)
1717
connection = engine.connect()
1818
result = connection.execute(text("SELECT 1"))
19-
print(result)
2019
assert len(result.fetchall()) == 1
2120
engine.dispose()
2221

@@ -30,10 +29,27 @@ def test_data_write(self, connection: Connection, fact_table_name: str):
3029
assert result.fetchall() == [(1, "some_text")]
3130
result = connection.execute(text(f"SELECT * FROM {fact_table_name}"))
3231
assert len(result.fetchall()) == 1
33-
# Update not supported
34-
with pytest.raises(OperationalError):
35-
connection.execute(
36-
text(
37-
f"UPDATE {fact_table_name} SET dummy='some_other_text' WHERE idx=1"
38-
)
39-
)
32+
33+
def test_databend_types(self, connection: Connection):
34+
result = connection.execute(text("SELECT to_date('1896-01-01')"))
35+
print(str(date(1896, 1, 1)))
36+
assert result.fetchall() == [('1896-01-01',)]
37+
38+
def test_has_table(
39+
self, engine: Engine, connection: Connection, fact_table_name: str
40+
):
41+
results = engine.dialect.has_table(connection, fact_table_name)
42+
assert results == 1
43+
44+
def test_get_columns(
45+
self, engine: Engine, connection: Connection, fact_table_name: str
46+
):
47+
results = engine.dialect.get_columns(connection, fact_table_name)
48+
assert len(results) > 0
49+
row = results[0]
50+
assert isinstance(row, dict)
51+
row_keys = list(row.keys())
52+
assert row_keys[0] == "name"
53+
assert row_keys[1] == "type"
54+
assert row_keys[2] == "nullable"
55+
assert row_keys[3] == "default"

0 commit comments

Comments
 (0)