From 9bce1b045116a4521f4d812333c0dd9e8a3ce96a Mon Sep 17 00:00:00 2001 From: Nargis Sultani Date: Fri, 8 Dec 2023 14:24:33 -0500 Subject: [PATCH] Fixed alembic issues --- ...050_update_financial_institutions_table.py | 81 +++++++++---------- .../entities/repos/test_institutions_repo.py | 16 ++-- tests/migrations/test_migrations.py | 2 +- 3 files changed, 47 insertions(+), 52 deletions(-) diff --git a/db_revisions/versions/045aa502e050_update_financial_institutions_table.py b/db_revisions/versions/045aa502e050_update_financial_institutions_table.py index 3f83674..2d5a3c9 100644 --- a/db_revisions/versions/045aa502e050_update_financial_institutions_table.py +++ b/db_revisions/versions/045aa502e050_update_financial_institutions_table.py @@ -18,50 +18,45 @@ def upgrade() -> None: - op.add_column("financial_institutions", sa.Column("tax_id", sa.String(length=9), nullable=True)) - op.add_column("financial_institutions", sa.Column("rssd_id", sa.Integer(), nullable=True)) - op.create_unique_constraint("unique_association", "financial_institutions", ["tax_id", "rssd_id"]) - op.add_column( - "financial_institutions", sa.Column("primary_federal_regulator_id", sa.String(length=4), nullable=True) - ) - op.add_column("financial_institutions", sa.Column("hmda_institution_type_id", sa.String(), nullable=True)) - op.add_column("financial_institutions", sa.Column("sbl_institution_type_id", sa.String(), nullable=True)) - op.add_column("financial_institutions", sa.Column("hq_address_street_1", sa.String(), nullable=False)) - op.add_column("financial_institutions", sa.Column("hq_address_street_2", sa.String(), nullable=True)) - op.add_column("financial_institutions", sa.Column("hq_address_city", sa.String(), nullable=True)) - op.add_column("financial_institutions", sa.Column("hq_address_state", sa.String(length=2), nullable=True)) - op.add_column("financial_institutions", sa.Column("hq_address_zip", sa.String(length=5), nullable=False)) - op.add_column("financial_institutions", sa.Column("parent_lei", sa.String(length=20), nullable=True)) - op.add_column("financial_institutions", sa.Column("parent_legal_name", sa.String(), nullable=True)) - op.add_column("financial_institutions", sa.Column("parent_rssd_id", sa.Integer(), nullable=True)) - op.add_column("financial_institutions", sa.Column("top_holder_lei", sa.String(length=20), nullable=True)) - op.add_column("financial_institutions", sa.Column("top_holder_legal_name", sa.String(), nullable=True)) - op.add_column("financial_institutions", sa.Column("top_holder_rssd_id", sa.Integer(), nullable=True)) - op.create_index( - op.f("ix_financial_institutions_hmda_institution_type_id"), - "financial_institutions", - ["hmda_institution_type_id"], - unique=False, - ) - op.create_index( - op.f("ix_financial_institutions_hq_address_state"), - "financial_institutions", - ["hq_address_state"], - unique=False, - ) - op.create_index( - op.f("ix_financial_institutions_primary_federal_regulator_id"), - "financial_institutions", - ["primary_federal_regulator_id"], - unique=False, - ) - op.create_index( - op.f("ix_financial_institutions_sbl_institution_type_id"), - "financial_institutions", - ["sbl_institution_type_id"], - unique=False, - ) with op.batch_alter_table("financial_institutions") as batch_op: + batch_op.add_column(sa.Column("tax_id", sa.String(length=9), nullable=True)) + batch_op.add_column(sa.Column("rssd_id", sa.Integer(), nullable=True)) + batch_op.add_column(sa.Column("primary_federal_regulator_id", sa.String(length=4), nullable=True)) + batch_op.add_column(sa.Column("hmda_institution_type_id", sa.String(), nullable=True)) + batch_op.add_column(sa.Column("sbl_institution_type_id", sa.String(), nullable=True)) + batch_op.add_column(sa.Column("hq_address_street_1", sa.String(), nullable=False)) + batch_op.add_column(sa.Column("hq_address_street_2", sa.String(), nullable=True)) + batch_op.add_column(sa.Column("hq_address_city", sa.String(), nullable=True)) + batch_op.add_column(sa.Column("hq_address_state", sa.String(length=2), nullable=True)) + batch_op.add_column(sa.Column("hq_address_zip", sa.String(length=5), nullable=False)) + batch_op.add_column(sa.Column("parent_lei", sa.String(length=20), nullable=True)) + batch_op.add_column(sa.Column("parent_legal_name", sa.String(), nullable=True)) + batch_op.add_column(sa.Column("parent_rssd_id", sa.Integer(), nullable=True)) + batch_op.add_column(sa.Column("top_holder_lei", sa.String(length=20), nullable=True)) + batch_op.add_column(sa.Column("top_holder_legal_name", sa.String(), nullable=True)) + batch_op.add_column(sa.Column("top_holder_rssd_id", sa.Integer(), nullable=True)) + batch_op.create_index( + batch_op.f("ix_financial_institutions_hmda_institution_type_id"), + ["hmda_institution_type_id"], + unique=False, + ) + batch_op.create_index( + batch_op.f("ix_financial_institutions_hq_address_state"), + ["hq_address_state"], + unique=False, + ) + batch_op.create_index( + batch_op.f("ix_financial_institutions_primary_federal_regulator_id"), + ["primary_federal_regulator_id"], + unique=False, + ) + batch_op.create_index( + batch_op.f("ix_financial_institutions_sbl_institution_type_id"), + ["sbl_institution_type_id"], + unique=False, + ) + batch_op.create_unique_constraint("unique_financial_institutions_tax_id", ["tax_id"]) + batch_op.create_unique_constraint("unique_financial_institutions_rssd_id", ["rssd_id"]) batch_op.create_foreign_key( "fk_federal_regulator_financial_institutions", "federal_regulator", diff --git a/tests/entities/repos/test_institutions_repo.py b/tests/entities/repos/test_institutions_repo.py index f2095d8..63d93aa 100644 --- a/tests/entities/repos/test_institutions_repo.py +++ b/tests/entities/repos/test_institutions_repo.py @@ -212,34 +212,34 @@ async def test_domain_allowed(self, transaction_session: AsyncSession): assert await repo.is_domain_allowed(transaction_session, "yahoo.com") is False assert await repo.is_domain_allowed(transaction_session, "gmail.com") is True - async def test_institutions_mapped_to_state_dao_valid(self, query_session: AsyncSession): + async def test_institution_mapped_to_state_valid(self, query_session: AsyncSession): res = await repo.get_institutions(query_session, leis=["TESTBANK123"]) assert res[0].hq_address_state.name == "Georgia" - async def test_institutions_mapped_to_state_dao_invalid(self, query_session: AsyncSession): + async def test_institution_mapped_to_state_invalid(self, query_session: AsyncSession): res = await repo.get_institutions(query_session, leis=["TESTBANK456"]) assert res[0].hq_address_state.name != "Georgia" - async def test_institutions_mapped_to_federal_regulator_dao_valid(self, query_session: AsyncSession): + async def test_institution_mapped_to_federal_regulator_valid(self, query_session: AsyncSession): res = await repo.get_institutions(query_session, leis=["TESTBANK456"]) assert res[0].primary_federal_regulator.name != "Test Federal Regulator ID 1" - async def test_institutions_mapped_to_federal_regulator_dao_invalid(self, query_session: AsyncSession): + async def test_institution_mapped_to_federal_regulator_invalid(self, query_session: AsyncSession): res = await repo.get_institutions(query_session, leis=["TESTBANK123"]) assert res[0].primary_federal_regulator.name == "Test Federal Regulator ID 1" - async def test_institutions_mapped_to_hmda_it_dao_valid(self, query_session: AsyncSession): + async def test_institution_mapped_to_hmda_it_valid(self, query_session: AsyncSession): res = await repo.get_institutions(query_session, leis=["TESTBANK123"]) assert res[0].hmda_institution_type.name == "Test HMDA Instituion ID 1" - async def test_institutions_mapped_to_hmda_it_dao_invalid(self, query_session: AsyncSession): + async def test_institution_mapped_to_hmda_it_invalid(self, query_session: AsyncSession): res = await repo.get_institutions(query_session, leis=["TESTBANK456"]) assert res[0].hmda_institution_type.name != "Test HMDA Instituion ID 1" - async def test_institutions_mapped_to_sbl_it_dao_valid(self, query_session: AsyncSession): + async def test_institution_mapped_to_sbl_it_valid(self, query_session: AsyncSession): res = await repo.get_institutions(query_session, leis=["TESTBANK123"]) assert res[0].sbl_institution_type.name == "Test SBL Instituion ID 1" - async def test_institutions_mapped_to_sbl_it_dao_invalid(self, query_session: AsyncSession): + async def test_institution_mapped_to_sbl_it_invalid(self, query_session: AsyncSession): res = await repo.get_institutions(query_session, leis=["TESTBANK456"]) assert res[0].sbl_institution_type.name != "Test SBL Instituion ID 1" diff --git a/tests/migrations/test_migrations.py b/tests/migrations/test_migrations.py index 378e73b..2a27197 100644 --- a/tests/migrations/test_migrations.py +++ b/tests/migrations/test_migrations.py @@ -11,7 +11,7 @@ def test_tables_exist_after_migration(alembic_runner: MigrationContext, alembic_engine: Engine): - alembic_runner.migrate_up_to("20e0d51d8be9") + alembic_runner.migrate_up_to("045aa502e050") inspector = sqlalchemy.inspect(alembic_engine) tables = inspector.get_table_names()