Skip to content

Commit

Permalink
18804 correcting data model (bcgov#2371)
Browse files Browse the repository at this point in the history
  • Loading branch information
vysakh-menon-aot authored Jan 9, 2024
1 parent 403b189 commit 7544c2d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 84 deletions.
34 changes: 18 additions & 16 deletions legal-api/migrations/versions/5238dd8fb805_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand All @@ -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')
5 changes: 3 additions & 2 deletions legal-api/src/legal_api/models/amalgamating_business.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
16 changes: 5 additions & 11 deletions legal-api/tests/unit/models/test_amalgamating_business.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@

def test_valid_amalgamating_business_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 = Amalgamation(
id=identifier,
amalgamation_type=Amalgamation.AmalgamationTypes.horizontal,
business_id=b.id,
filing_id=filing.id,
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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]
101 changes: 46 additions & 55 deletions legal-api/tests/unit/models/test_amalgamation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7544c2d

Please sign in to comment.