forked from bcgov/lear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
19649 filer - short form amalgamation (bcgov#2445)
- Loading branch information
1 parent
b724198
commit e30435a
Showing
3 changed files
with
268 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,12 @@ | |
from unittest.mock import patch | ||
|
||
import pytest | ||
from legal_api.models import Amalgamation, Business, Filing | ||
from legal_api.models import AmalgamatingBusiness, Amalgamation, Business, Filing | ||
from registry_schemas.example_data import AMALGAMATION_APPLICATION | ||
|
||
from entity_filer.filing_processors.filing_components import business_info, business_profile | ||
from entity_filer.worker import process_filing | ||
from tests.unit import create_entity, create_filing | ||
from tests.unit import create_entity, create_filing, create_office, create_office_address, create_party, create_party_role, create_share_class | ||
|
||
|
||
async def test_amalgamation_application_process(app, session): | ||
|
@@ -42,13 +42,14 @@ async def test_amalgamation_application_process(app, session): | |
filing['filing']['header'] = {'name': filing_type, 'date': '2019-04-08', | ||
'certifiedBy': 'full name', 'email': '[email protected]', 'filingId': 1} | ||
filing['filing'][filing_type] = copy.deepcopy(AMALGAMATION_APPLICATION) | ||
del filing['filing'][filing_type]['amalgamatingBusinesses'][0] | ||
filing['filing'][filing_type]['amalgamatingBusinesses'] = [ | ||
{ | ||
'role': 'amalgamating', | ||
'role': AmalgamatingBusiness.Role.amalgamating.name, | ||
'identifier': amalgamating_identifier_1 | ||
}, | ||
{ | ||
'role': 'amalgamating', | ||
'role': AmalgamatingBusiness.Role.amalgamating.name, | ||
'identifier': amalgamating_identifier_2 | ||
} | ||
] | ||
|
@@ -92,9 +93,140 @@ async def test_amalgamation_application_process(app, session): | |
assert amalgamation.court_approval == filing['filing'][filing_type]['courtApproval'] | ||
|
||
for amalgamating_business in amalgamation.amalgamating_businesses: | ||
assert amalgamating_business.role.name == 'amalgamating' | ||
assert amalgamating_business.business_id in [amalgamating_business_1_id, amalgamating_business_2_id] | ||
dissolved_business = Business.find_by_internal_id(amalgamating_business.business_id) | ||
assert dissolved_business.state == Business.State.HISTORICAL | ||
assert dissolved_business.state_filing_id == filing_rec.id | ||
assert dissolved_business.dissolution_date == effective_date | ||
assert amalgamating_business.role.name == AmalgamatingBusiness.Role.amalgamating.name | ||
if amalgamating_business.business_id: | ||
assert amalgamating_business.business_id in [amalgamating_business_1_id, amalgamating_business_2_id] | ||
dissolved_business = Business.find_by_internal_id(amalgamating_business.business_id) | ||
assert dissolved_business.state == Business.State.HISTORICAL | ||
assert dissolved_business.state_filing_id == filing_rec.id | ||
assert dissolved_business.dissolution_date == effective_date | ||
else: | ||
assert amalgamating_business.foreign_jurisdiction | ||
assert amalgamating_business.foreign_jurisdiction_region | ||
assert amalgamating_business.foreign_name | ||
assert amalgamating_business.foreign_identifier | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'amalgamation_type, amalgamating_role', | ||
[ | ||
(Amalgamation.AmalgamationTypes.horizontal.name, AmalgamatingBusiness.Role.primary.name), | ||
(Amalgamation.AmalgamationTypes.vertical.name, AmalgamatingBusiness.Role.holding.name) | ||
] | ||
) | ||
async def test_short_form_amalgamation_application_process(app, session, amalgamation_type, amalgamating_role): | ||
"""Assert that the amalgamation application object is correctly populated to model objects.""" | ||
filing_type = 'amalgamationApplication' | ||
amalgamating_identifier_1 = 'BC9891234' | ||
amalgamating_identifier_2 = 'BC9891235' | ||
nr_identifier = 'NR 1234567' | ||
next_corp_num = 'BC0001095' | ||
|
||
amalgamating_business_1 = create_entity(amalgamating_identifier_1, 'BC', f'{amalgamating_role} business 1') | ||
|
||
office = create_office(amalgamating_business_1, 'registeredOffice') | ||
office_delivery_address = create_office_address(amalgamating_business_1, office, 'delivery') | ||
office_mailing_address = create_office_address(amalgamating_business_1, office, 'mailing') | ||
|
||
create_share_class(amalgamating_business_1) | ||
|
||
party = create_party({ | ||
'officer': { | ||
'firstName': f'{amalgamating_business_1.identifier} first_name', | ||
'lastName': 'Director', | ||
'middleName': 'P', | ||
}, | ||
'mailingAddress': { | ||
'streetAddress': f'{amalgamating_business_1.identifier} mailing_address', | ||
'addressCity': 'mailing_address city', | ||
'addressCountry': 'CA', | ||
'postalCode': 'H0H0H0', | ||
'addressRegion': 'BC' | ||
}, | ||
'deliveryAddress': { | ||
'streetAddress': f'{amalgamating_business_1.identifier} delivery_address', | ||
'addressCity': 'delivery_address city', | ||
'addressCountry': 'CA', | ||
'postalCode': 'H0H0H0', | ||
'addressRegion': 'BC' | ||
} | ||
}) | ||
create_party_role(amalgamating_business_1, party, ['director'], datetime.utcnow()) | ||
|
||
|
||
amalgamating_business_1_id = amalgamating_business_1.id | ||
amalgamating_business_2_id = create_entity(amalgamating_identifier_2, 'BC', 'amalgamating business 2').id | ||
|
||
filing = {'filing': {}} | ||
filing['filing']['header'] = {'name': filing_type, 'date': '2019-04-08', | ||
'certifiedBy': 'full name', 'email': '[email protected]', 'filingId': 1} | ||
filing['filing'][filing_type] = copy.deepcopy(AMALGAMATION_APPLICATION) | ||
filing['filing'][filing_type]['type'] = amalgamation_type | ||
del filing['filing'][filing_type]['amalgamatingBusinesses'][0] | ||
filing['filing'][filing_type]['amalgamatingBusinesses'] = [ | ||
{ | ||
'role': amalgamating_role, | ||
'identifier': amalgamating_identifier_1 | ||
}, | ||
{ | ||
'role': AmalgamatingBusiness.Role.amalgamating.name, | ||
'identifier': amalgamating_identifier_2 | ||
} | ||
] | ||
|
||
filing['filing'][filing_type]['nameRequest']['nrNumber'] = nr_identifier | ||
|
||
del filing['filing'][filing_type]['offices'] | ||
del filing['filing'][filing_type]['shareStructure'] | ||
del filing['filing'][filing_type]['parties'][0]['roles'][1] | ||
|
||
filing_rec = create_filing('123', filing) | ||
effective_date = datetime.now(timezone.utc) | ||
filing_rec.effective_date = effective_date | ||
filing_rec.save() | ||
|
||
# test | ||
filing_msg = {'filing': {'id': filing_rec.id}} | ||
with patch.object(business_info, 'get_next_corp_num', return_value=next_corp_num): | ||
with patch.object(business_profile, 'update_business_profile', return_value=HTTPStatus.OK): | ||
await process_filing(filing_msg, app) | ||
|
||
# Assertions | ||
filing_rec = Filing.find_by_id(filing_rec.id) | ||
business = Business.find_by_identifier(next_corp_num) | ||
|
||
assert filing_rec.business_id == business.id | ||
assert filing_rec.status == Filing.Status.COMPLETED.value | ||
assert business.identifier | ||
assert business.founding_date == effective_date | ||
assert business.legal_type == filing['filing'][filing_type]['nameRequest']['legalType'] | ||
assert business.legal_name == filing['filing'][filing_type]['nameRequest']['legalName'] | ||
assert business.state == Business.State.ACTIVE | ||
|
||
assert len(business.share_classes.all()) == 1 | ||
assert len(business.offices.all()) == 1 | ||
assert len(business.aliases.all()) == len(filing['filing'][filing_type]['nameTranslations']) | ||
assert business.party_roles[0].role == 'director' | ||
assert filing_rec.filing_party_roles[0].role == 'completing_party' | ||
|
||
assert business.amalgamation | ||
amalgamation: Amalgamation = business.amalgamation[0] | ||
assert amalgamation.amalgamation_date == effective_date | ||
assert amalgamation.filing_id == filing_rec.id | ||
assert amalgamation.amalgamation_type.name == filing['filing'][filing_type]['type'] | ||
assert amalgamation.court_approval == filing['filing'][filing_type]['courtApproval'] | ||
|
||
for amalgamating_business in amalgamation.amalgamating_businesses: | ||
assert amalgamating_business.role.name in [amalgamating_role, AmalgamatingBusiness.Role.amalgamating.name] | ||
if amalgamating_business.business_id: | ||
assert amalgamating_business.business_id in [amalgamating_business_1_id, amalgamating_business_2_id] | ||
dissolved_business = Business.find_by_internal_id(amalgamating_business.business_id) | ||
assert dissolved_business.state == Business.State.HISTORICAL | ||
assert dissolved_business.state_filing_id == filing_rec.id | ||
assert dissolved_business.dissolution_date == effective_date | ||
else: | ||
assert amalgamating_business.foreign_jurisdiction | ||
assert amalgamating_business.foreign_jurisdiction_region | ||
assert amalgamating_business.foreign_name | ||
assert amalgamating_business.foreign_identifier | ||
|