From 7544c2dcd42b02bd6b6963ba5963378c51c1b769 Mon Sep 17 00:00:00 2001 From: Vysakh Menon Date: Mon, 8 Jan 2024 16:31:55 -0800 Subject: [PATCH] 18804 correcting data model (#2371) --- .../migrations/versions/5238dd8fb805_.py | 34 +++--- .../legal_api/models/amalgamating_business.py | 5 +- .../unit/models/test_amalgamating_business.py | 16 +-- .../tests/unit/models/test_amalgamation.py | 101 ++++++++---------- 4 files changed, 72 insertions(+), 84 deletions(-) diff --git a/legal-api/migrations/versions/5238dd8fb805_.py b/legal-api/migrations/versions/5238dd8fb805_.py index 96cace3f83..e85fdf4e52 100644 --- a/legal-api/migrations/versions/5238dd8fb805_.py +++ b/legal-api/migrations/versions/5238dd8fb805_.py @@ -16,27 +16,28 @@ branch_labels = None depends_on = None -role_enum = postgresql.ENUM('AMALGAMATING', 'HOLDING', name='amalgamating_business_role') +role_enum = postgresql.ENUM('amalgamating', 'holding', 'primary', name='amalgamating_business_role') amalgamation_type_enum = postgresql.ENUM('regular', 'vertical', 'horizontal', name='amalgamation_type') + def upgrade(): - + # add enum values role_enum.create(op.get_bind(), checkfirst=True) amalgamation_type_enum.create(op.get_bind(), checkfirst=True) - + # ========================================================================================== # amalgamating_business/amalgamation tables # ========================================================================================== op.create_table( 'amalgamation', - sa.Column('id', sa.Integer(), autoincrement=False, nullable=False), - sa.Column('business_id', sa.Integer(), autoincrement=False, nullable=False), - sa.Column('filing_id', sa.Integer(), autoincrement=False, nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('business_id', sa.Integer(), nullable=False), + sa.Column('filing_id', sa.Integer(), nullable=False), sa.Column('amalgamation_date', sa.TIMESTAMP(timezone=True), nullable=False), sa.Column('court_approval', sa.Boolean(), nullable=False), sa.ForeignKeyConstraint(['filing_id'], ['filings.id']), @@ -45,26 +46,27 @@ def upgrade(): # enum added after creating table as DuplicateObject error would be thrown otherwise op.add_column('amalgamation', sa.Column('amalgamation_type', amalgamation_type_enum, nullable=False)) - + op.create_table( 'amalgamating_business', sa.Column('id', sa.Integer(), primary_key=False), - sa.Column('business_id', sa.Integer(), nullable=False), + sa.Column('business_id', sa.Integer(), nullable=True), sa.Column('amalgamation_id', sa.Integer(), nullable=False), - sa.Column('foreign_jurisdiction', sa.String(length=10), nullable=False), - sa.Column('foreign_name', sa.String(length=100), nullable=False), - sa.Column('foreign_corp_num', sa.String(length=50), nullable=False), + sa.Column('foreign_jurisdiction', sa.String(length=10), nullable=True), + sa.Column('foreign_name', sa.String(length=100), nullable=True), + sa.Column('foreign_corp_num', sa.String(length=50), nullable=True), sa.ForeignKeyConstraint(['business_id'], ['businesses.id']), sa.ForeignKeyConstraint(['amalgamation_id'], ['amalgamation.id']), sa.PrimaryKeyConstraint('id')) - + # enum added after creating table as DuplicateObject error would be thrown otherwise op.add_column('amalgamating_business', sa.Column('role', role_enum, nullable=False)) - + + def downgrade(): + op.drop_table('amalgamating_business') + op.drop_table('amalgamation') + # Drop enum types from the database amalgamation_type_enum.drop(op.get_bind(), checkfirst=True) role_enum.drop(op.get_bind(), checkfirst=True) - - op.drop_table('amalgamation') - op.drop_table('amalgamating_business') diff --git a/legal-api/src/legal_api/models/amalgamating_business.py b/legal-api/src/legal_api/models/amalgamating_business.py index 9827c0be23..a74bf3c43c 100644 --- a/legal-api/src/legal_api/models/amalgamating_business.py +++ b/legal-api/src/legal_api/models/amalgamating_business.py @@ -29,8 +29,9 @@ class AmalgamatingBusiness(db.Model): # pylint: disable=too-many-instance-attri class Role(BaseEnum): """Enum for the Role Values.""" - AMALGAMATING = auto() - HOLDING = auto() + amalgamating = auto() + holding = auto() + primary = auto() # __versioned__ = {} __tablename__ = 'amalgamating_business' diff --git a/legal-api/tests/unit/models/test_amalgamating_business.py b/legal-api/tests/unit/models/test_amalgamating_business.py index ff63dd5790..d5d71ed217 100644 --- a/legal-api/tests/unit/models/test_amalgamating_business.py +++ b/legal-api/tests/unit/models/test_amalgamating_business.py @@ -41,8 +41,6 @@ def test_valid_amalgamating_business_save(session): """Assert that a valid alias can be saved.""" - identifier = 1234567 - b = factory_business('CP1234567') b.save() @@ -50,7 +48,6 @@ def test_valid_amalgamating_business_save(session): filing.save() amalgamation = Amalgamation( - id=identifier, amalgamation_type=Amalgamation.AmalgamationTypes.horizontal, business_id=b.id, filing_id=filing.id, @@ -61,8 +58,7 @@ def test_valid_amalgamating_business_save(session): amalgamation.save() amalgamating_business_1 = AmalgamatingBusiness( - id=identifier, - role=AmalgamatingBusiness.Role.AMALGAMATING, + role=AmalgamatingBusiness.Role.amalgamating, foreign_jurisdiction="CA", foreign_jurisdiction_region="AB", foreign_name="Testing123", @@ -72,11 +68,8 @@ def test_valid_amalgamating_business_save(session): ) amalgamating_business_1.save() - identifier = 1234568 - amalgamating_business_2 = AmalgamatingBusiness( - id=identifier, - role=AmalgamatingBusiness.Role.HOLDING, + role=AmalgamatingBusiness.Role.holding, foreign_jurisdiction="CA", foreign_jurisdiction_region="AB", foreign_name="Testing123", @@ -90,5 +83,6 @@ def test_valid_amalgamating_business_save(session): assert amalgamating_business_1.id assert amalgamating_business_2.id for type in AmalgamatingBusiness.Role: - assert type in [AmalgamatingBusiness.Role.HOLDING, - AmalgamatingBusiness.Role.AMALGAMATING] + assert type in [AmalgamatingBusiness.Role.holding, + AmalgamatingBusiness.Role.amalgamating, + AmalgamatingBusiness.Role.primary] diff --git a/legal-api/tests/unit/models/test_amalgamation.py b/legal-api/tests/unit/models/test_amalgamation.py index 085c913747..52bc204737 100644 --- a/legal-api/tests/unit/models/test_amalgamation.py +++ b/legal-api/tests/unit/models/test_amalgamation.py @@ -15,12 +15,30 @@ """Tests to assure the AlternateName Model. Test-Suite to ensure that the AlternateName Model is working as expected. """ +from tests.unit.models import ( + factory_business, + factory_business_mailing_address, + factory_completed_filing, + factory_filing, + factory_user, +) +from legal_api.models import Filing +from legal_api.models import Business +from legal_api.models import Amalgamation +from registry_schemas.example_data import ( + ALTERATION_FILING_TEMPLATE, + ANNUAL_REPORT, + CHANGE_OF_DIRECTORS, + CORRECTION_AR, + COURT_ORDER, + FILING_HEADER, + SPECIAL_RESOLUTION, +) from datetime import datetime from legal_api.models import amalgamation - def test_valid_amalgamation_save(session): """Assert that a valid alias can be saved.""" # Copyright © 2023 Province of British Columbia @@ -37,82 +55,55 @@ def test_valid_amalgamation_save(session): # See the License for the specific language governing permissions and # limitations under the License. + """ Tests to assure the Amalgamation Model. Test-Suite to ensure that the Amalgamation Model is working as expected. """ -from datetime import datetime -from registry_schemas.example_data import ( - ALTERATION_FILING_TEMPLATE, - ANNUAL_REPORT, - CHANGE_OF_DIRECTORS, - CORRECTION_AR, - COURT_ORDER, - FILING_HEADER, - SPECIAL_RESOLUTION, -) - -from legal_api.models import Amalgamation -from legal_api.models import Business -from legal_api.models import Filing -from tests.unit.models import ( - factory_business, - factory_business_mailing_address, - factory_completed_filing, - factory_filing, - factory_user, -) def test_valid_amalgamation_save(session): """Assert that a valid alias can be saved.""" - identifier = 1234567 - + b = factory_business('CP1234567') - + b.save() - + filing = factory_filing(b, ANNUAL_REPORT) - + filing.save() - + amalgamation_1 = Amalgamation( - id = identifier, - amalgamation_type = Amalgamation.AmalgamationTypes.horizontal, - business_id = b.id, - filing_id = filing.id, - amalgamation_date = datetime.utcnow(), - court_approval = True + amalgamation_type=Amalgamation.AmalgamationTypes.horizontal, + business_id=b.id, + filing_id=filing.id, + amalgamation_date=datetime.utcnow(), + court_approval=True ) - + amalgamation_1.save() - - identifier = 1234568 - + amalgamation_2 = Amalgamation( - id = identifier, - amalgamation_type = Amalgamation.AmalgamationTypes.vertical, - business_id = b.id, - filing_id = filing.id, - amalgamation_date = datetime.utcnow(), - court_approval = True + amalgamation_type=Amalgamation.AmalgamationTypes.vertical, + business_id=b.id, + filing_id=filing.id, + amalgamation_date=datetime.utcnow(), + court_approval=True ) - + amalgamation_2.save() - - identifier = 12345679 + amalgamation_3 = Amalgamation( - id = identifier, - amalgamation_type = Amalgamation.AmalgamationTypes.regular, - business_id = b.id, - filing_id = filing.id, - amalgamation_date = datetime.utcnow(), - court_approval = True + amalgamation_type=Amalgamation.AmalgamationTypes.regular, + business_id=b.id, + filing_id=filing.id, + amalgamation_date=datetime.utcnow(), + court_approval=True ) - + amalgamation_3.save() - + # verify assert amalgamation_1.id assert amalgamation_2.id