Skip to content

Commit c29899a

Browse files
author
Jesse Whitehouse
committed
(6/x) Add smoke tests for inspector behaviour
Use samples catalog to avoid flakiness on our internal infrastructure Signed-off-by: Jesse Whitehouse <[email protected]>
1 parent be758d7 commit c29899a

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

tests/e2e/sqlalchemy/test_basic.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from sqlalchemy import create_engine, select, insert, Column, MetaData, Table
55
from sqlalchemy.orm import Session
66
from sqlalchemy.types import SMALLINT, Integer, BOOLEAN, String, DECIMAL, Date
7+
from sqlalchemy.engine import Engine
78

89
try:
910
from sqlalchemy.orm import declarative_base
@@ -32,7 +33,7 @@ def version_agnostic_select(object_to_select, *args, **kwargs):
3233

3334

3435
@pytest.fixture
35-
def db_engine():
36+
def db_engine() -> Engine:
3637

3738
HOST = os.environ.get("host")
3839
HTTP_PATH = os.environ.get("http_path")
@@ -56,8 +57,24 @@ def db_engine():
5657
)
5758
return engine
5859

60+
@pytest.fixture
61+
def samples_engine() -> Engine:
62+
HOST = os.environ.get("host")
63+
HTTP_PATH = os.environ.get("http_path")
64+
ACCESS_TOKEN = os.environ.get("access_token")
65+
CATALOG = "samples"
66+
67+
connect_args = {"_user_agent_entry": USER_AGENT_TOKEN}
68+
69+
connect_args = {
70+
**connect_args,
71+
"http_path": HTTP_PATH,
72+
"server_hostname": HOST,
73+
"catalog": CATALOG,
74+
}
75+
5976
engine = create_engine(
60-
f"databricks://token:{ACCESS_TOKEN}@{HOST}?http_path={HTTP_PATH}&catalog={CATALOG}&schema={SCHEMA}",
77+
f"databricks://token:{ACCESS_TOKEN}@{HOST}",
6178
connect_args=connect_args,
6279
)
6380
return engine
@@ -123,7 +140,7 @@ def test_pandas_upload(db_engine, metadata_obj):
123140
db_engine.execute("DROP TABLE mock_data")
124141

125142

126-
def test_create_table_not_null(db_engine, metadata_obj):
143+
def test_create_table_not_null(db_engine, metadata_obj:MetaData):
127144

128145
table_name = "PySQLTest_{}".format(datetime.datetime.utcnow().strftime("%s"))
129146

@@ -293,3 +310,30 @@ def test_dialect_type_mappings(base, db_engine, metadata_obj: MetaData):
293310
assert this_row["date_example"] == date_example
294311

295312
metadata_obj.drop_all()
313+
314+
def test_inspector_smoke_test(samples_engine: Engine):
315+
"""It does not appear that 3L namespace is supported here
316+
"""
317+
318+
from sqlalchemy.engine.reflection import Inspector
319+
schema, table = "nyctaxi", "trips"
320+
321+
try:
322+
inspector = Inspector.from_engine(samples_engine)
323+
except Exception as e:
324+
assert False, f"Could not build inspector: {e}"
325+
326+
# Expect six columns
327+
columns = inspector.get_columns(table, schema=schema)
328+
329+
# Expect zero views, but the method should return
330+
views = inspector.get_view_names(schema=schema)
331+
332+
assert len(columns) == 6, "Dialect did not find the expected number of columns in samples.nyctaxi.trips"
333+
assert len(views) == 0, "Views could not be fetched"
334+
335+
def test_get_table_names_smoke_test(samples_engine: Engine):
336+
337+
with samples_engine.connect() as conn:
338+
_names = samples_engine.table_names(schema="nyctaxi", connection=conn)
339+
_names is not None, "get_table_names did not succeed"

0 commit comments

Comments
 (0)