4
4
from sqlalchemy import create_engine , select , insert , Column , MetaData , Table
5
5
from sqlalchemy .orm import Session
6
6
from sqlalchemy .types import SMALLINT , Integer , BOOLEAN , String , DECIMAL , Date
7
+ from sqlalchemy .engine import Engine
7
8
8
9
try :
9
10
from sqlalchemy .orm import declarative_base
@@ -32,7 +33,7 @@ def version_agnostic_select(object_to_select, *args, **kwargs):
32
33
33
34
34
35
@pytest .fixture
35
- def db_engine ():
36
+ def db_engine () -> Engine :
36
37
37
38
HOST = os .environ .get ("host" )
38
39
HTTP_PATH = os .environ .get ("http_path" )
@@ -56,8 +57,24 @@ def db_engine():
56
57
)
57
58
return engine
58
59
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
+
59
76
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 } " ,
61
78
connect_args = connect_args ,
62
79
)
63
80
return engine
@@ -123,7 +140,7 @@ def test_pandas_upload(db_engine, metadata_obj):
123
140
db_engine .execute ("DROP TABLE mock_data" )
124
141
125
142
126
- def test_create_table_not_null (db_engine , metadata_obj ):
143
+ def test_create_table_not_null (db_engine , metadata_obj : MetaData ):
127
144
128
145
table_name = "PySQLTest_{}" .format (datetime .datetime .utcnow ().strftime ("%s" ))
129
146
@@ -293,3 +310,30 @@ def test_dialect_type_mappings(base, db_engine, metadata_obj: MetaData):
293
310
assert this_row ["date_example" ] == date_example
294
311
295
312
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