Skip to content

Commit faa40e8

Browse files
rod-gloverNospamas
authored andcommitted
Finish smoke test
1 parent 2395f5f commit faa40e8

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

tests/alembic_migrations/helpers.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,40 @@ def check_triggers(connection, table, expected, present=True):
5555
else:
5656
assert item not in triggers
5757

58+
59+
def check_orm_actual_tables_match(engine, orm_table, schema_name=get_schema_name()):
60+
"""Check that table defined in ORM matches the actual table in the database.
61+
This method is useful in smoke tests."""
62+
63+
# Check actual table existence
64+
names = set(get_schema_item_names(engine, "tables", schema_name=schema_name))
65+
assert orm_table.__tablename__ in names
66+
67+
# Reflect table
68+
metadata = MetaData(schema=schema_name, bind=engine)
69+
actual_table = Table(orm_table.__tablename__, metadata, autoload_with=engine)
70+
71+
# Check that table columns match
72+
def type_match(class1, class2):
73+
return (
74+
# This is usually the case if they match
75+
issubclass(class1, class2)
76+
or issubclass(class2, class1)
77+
# Ad-hocery around dialect vs non-dialect types
78+
or all(issubclass(c, sqltypes._AbstractInterval) for c in (class1, class2))
79+
)
80+
81+
# This checks column order as well as type.
82+
for actual_col, orm_col in zip(actual_table.columns, orm_table.__table__.columns):
83+
assert actual_col.name == orm_col.name
84+
# print(
85+
# f"{actual_col.name}: actual {actual_col.type.__class__} orm: {orm_col.type.__class__}"
86+
# )
87+
assert type_match(
88+
actual_col.type.__class__, orm_col.type.__class__
89+
), f"{actual_col.name}: actual {actual_col.type.__class__} orm: {orm_col.type.__class__}"
90+
91+
5892
def check_history_tracking_upgrade(
5993
connection: Connection,
6094
table_name: str,

tests/alembic_migrations/versions/v_758be4f4ce0f_support_multiple_climatological_normals/test_smoke.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_downgrade(
6969
from pycds import ClimatologicalStation, ClimatologicalStationXHistory, ClimatologicalVariable, ClimatologicalValue
7070
from pycds.alembic.change_history_utils import pri_table_name, hx_table_name, hx_id_name
7171
from pycds.database import get_schema_item_names
72-
from tests.alembic_migrations.helpers import check_table_orm_actual_match
72+
from tests.alembic_migrations.helpers import check_orm_actual_tables_match
7373

7474
logger = logging.getLogger("tests")
7575

@@ -92,7 +92,7 @@ def test_upgrade(
9292
engine, script = prepared_schema_from_migrations_left
9393

9494
# Check that table has been created as expected.
95-
check_table_orm_actual_match(engine, orm_table, schema_name=schema_name)
95+
check_orm_actual_tables_match(engine, orm_table, schema_name=schema_name)
9696

9797

9898
@pytest.mark.usefixtures("new_db_left")
@@ -108,6 +108,6 @@ def test_downgrade(
108108
# Run downgrade migration
109109
command.downgrade(alembic_config_left, "-1")
110110

111-
# Check that tables have been altered or dropped as expected.
111+
# Check that tables have been dropped as expected.
112112
names = set(get_schema_item_names(engine, "tables", schema_name=schema_name))
113113
assert table.__tablename__ not in names

0 commit comments

Comments
 (0)