Skip to content

Commit

Permalink
harcoded table names in the revision script and test cases instead of…
Browse files Browse the repository at this point in the history
… coupling them with dao
  • Loading branch information
Nargis Sultani committed Dec 15, 2023
1 parent 4424a46 commit 35d8c4c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
23 changes: 13 additions & 10 deletions tests/migrations/test_lookup_tables_data_feed.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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

0 comments on commit 35d8c4c

Please sign in to comment.