From 35d8c4c4cce6c4e5c28321702d09100591642df2 Mon Sep 17 00:00:00 2001 From: Nargis Sultani Date: Fri, 15 Dec 2023 13:40:48 -0500 Subject: [PATCH] harcoded table names in the revision script and test cases instead of coupling them with dao --- ...a742d97ad9_feed_federal_regulator_table.py | 2 +- .../7b6ff51002b5_feed_address_state_table.py | 2 +- ...1b1e109_feed_sbl_institution_type_table.py | 2 +- ...1aa6df_feed_hmda_institution_type_table.py | 2 +- .../test_lookup_tables_data_feed.py | 23 +++++++++++-------- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/db_revisions/versions/26a742d97ad9_feed_federal_regulator_table.py b/db_revisions/versions/26a742d97ad9_feed_federal_regulator_table.py index 31d69cf..5302b0d 100644 --- a/db_revisions/versions/26a742d97ad9_feed_federal_regulator_table.py +++ b/db_revisions/versions/26a742d97ad9_feed_federal_regulator_table.py @@ -19,7 +19,7 @@ def upgrade() -> None: - data = get_feed_data_from_file(FederalRegulatorDao.__tablename__) + data = get_feed_data_from_file("federal_regulator") op.bulk_insert(FederalRegulatorDao.__table__, data) diff --git a/db_revisions/versions/7b6ff51002b5_feed_address_state_table.py b/db_revisions/versions/7b6ff51002b5_feed_address_state_table.py index 35fe95a..5a1ed40 100644 --- a/db_revisions/versions/7b6ff51002b5_feed_address_state_table.py +++ b/db_revisions/versions/7b6ff51002b5_feed_address_state_table.py @@ -19,7 +19,7 @@ def upgrade() -> None: - data = get_feed_data_from_file(AddressStateDao.__tablename__) + data = get_feed_data_from_file("address_state") op.bulk_insert(AddressStateDao.__table__, data) diff --git a/db_revisions/versions/a41281b1e109_feed_sbl_institution_type_table.py b/db_revisions/versions/a41281b1e109_feed_sbl_institution_type_table.py index b79001b..058087f 100644 --- a/db_revisions/versions/a41281b1e109_feed_sbl_institution_type_table.py +++ b/db_revisions/versions/a41281b1e109_feed_sbl_institution_type_table.py @@ -18,7 +18,7 @@ def upgrade() -> None: - data = get_feed_data_from_file(SBLInstitutionTypeDao.__tablename__) + data = get_feed_data_from_file("sbl_institution_type") op.bulk_insert(SBLInstitutionTypeDao.__table__, data) diff --git a/db_revisions/versions/f4ff7d1aa6df_feed_hmda_institution_type_table.py b/db_revisions/versions/f4ff7d1aa6df_feed_hmda_institution_type_table.py index 297f5d8..1502c9e 100644 --- a/db_revisions/versions/f4ff7d1aa6df_feed_hmda_institution_type_table.py +++ b/db_revisions/versions/f4ff7d1aa6df_feed_hmda_institution_type_table.py @@ -19,7 +19,7 @@ def upgrade() -> None: - data = get_feed_data_from_file(HMDAInstitutionTypeDao.__tablename__) + data = get_feed_data_from_file("hmda_institution_type") op.bulk_insert(HMDAInstitutionTypeDao.__table__, data) diff --git a/tests/migrations/test_lookup_tables_data_feed.py b/tests/migrations/test_lookup_tables_data_feed.py index 9d983a4..6181871 100644 --- a/tests/migrations/test_lookup_tables_data_feed.py +++ b/tests/migrations/test_lookup_tables_data_feed.py @@ -1,6 +1,6 @@ import os import csv -from sqlalchemy import select +from sqlalchemy import text from sqlalchemy.engine import Engine from pytest_alembic import MigrationContext from entities.models import AddressStateDao, FederalRegulatorDao, HMDAInstitutionTypeDao, SBLInstitutionTypeDao @@ -21,11 +21,11 @@ def test_address_state_data_feed(alembic_runner: MigrationContext, alembic_engin alembic_runner.migrate_up_before("7b6ff51002b5") # Test address_state feed + address_state_tablename = "address_state" alembic_runner.migrate_up_one() - with alembic_engine.connect() as conn: - address_state_rows = conn.execute(select(AddressStateDao.code, AddressStateDao.name)).fetchall() - address_state_expected = data_feed_helper(AddressStateDao.__tablename__) + address_state_rows = conn.execute(text("SELECT code, name from %s" % address_state_tablename)).fetchall() + address_state_expected = data_feed_helper(address_state_tablename) assert address_state_rows == address_state_expected @@ -34,10 +34,11 @@ def test_federal_regulator_data_feed(alembic_runner: MigrationContext, alembic_e alembic_runner.migrate_up_before("26a742d97ad9") # Test federal_regulator feed + federal_regulator_tablename = "federal_regulator" alembic_runner.migrate_up_one() with alembic_engine.connect() as conn: - federal_regulator_rows = conn.execute(select(FederalRegulatorDao.id, FederalRegulatorDao.name)).fetchall() - federal_regulator_expected = data_feed_helper(FederalRegulatorDao.__tablename__) + federal_regulator_rows = conn.execute(text("SELECT id, name from %s" % federal_regulator_tablename)).fetchall() + federal_regulator_expected = data_feed_helper(federal_regulator_tablename) assert federal_regulator_rows == federal_regulator_expected @@ -46,12 +47,13 @@ def test_hmda_institution_type_data_feed(alembic_runner: MigrationContext, alemb alembic_runner.migrate_up_before("f4ff7d1aa6df") # Test hmda_institution_type feed + hmda_institution_type_tablename = "hmda_institution_type" alembic_runner.migrate_up_one() with alembic_engine.connect() as conn: hmda_institution_type_rows = conn.execute( - select(HMDAInstitutionTypeDao.id, HMDAInstitutionTypeDao.name) + text("SELECT id, name from %s" % hmda_institution_type_tablename) ).fetchall() - hmda_institution_type_expected = data_feed_helper(HMDAInstitutionTypeDao.__tablename__) + hmda_institution_type_expected = data_feed_helper(hmda_institution_type_tablename) assert hmda_institution_type_rows == hmda_institution_type_expected @@ -60,10 +62,11 @@ def test_sbl_institution_type_data_feed(alembic_runner: MigrationContext, alembi alembic_runner.migrate_up_before("a41281b1e109") # Test sbl_institution_type feed + sbl_institution_type_tablename = "sbl_institution_type" alembic_runner.migrate_up_one() with alembic_engine.connect() as conn: sbl_institution_type_rows = conn.execute( - select(SBLInstitutionTypeDao.id, SBLInstitutionTypeDao.name) + text("SELECT id, name from %s" % sbl_institution_type_tablename) ).fetchall() - sbl_institution_type_expected = data_feed_helper(SBLInstitutionTypeDao.__tablename__) + sbl_institution_type_expected = data_feed_helper(sbl_institution_type_tablename) assert sbl_institution_type_rows == sbl_institution_type_expected