Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion legal-api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "legal-api"
version = "3.1.77"
version = "3.1.78"
description = ""
authors = [
{name = "thor",email = "1042854+thorwolpert@users.noreply.github.com"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
Business.LegalTypes.BCOMP.value,
]

# a company continued into BC counts as its BC equivalent (C=BC, CBEN=BEN, CUL=ULC, CCC=CC)
CONTINUED_IN_TO_BC_LEGAL_TYPE: Final = {
Business.LegalTypes.CONTINUE_IN.value: Business.LegalTypes.COMP.value,
Business.LegalTypes.BCOMP_CONTINUE_IN.value: Business.LegalTypes.BCOMP.value,
Business.LegalTypes.ULC_CONTINUE_IN.value: Business.LegalTypes.BC_ULC_COMPANY.value,
Business.LegalTypes.CCC_CONTINUE_IN.value: Business.LegalTypes.BC_CCC.value,
}

# COLIN corps not loaded in LEAR that can amalgamate
COLIN_AMALGAMATION_LEGAL_TYPES: Final = [
Business.LegalTypes.COMP.value,
Expand Down Expand Up @@ -198,8 +206,10 @@ def _augment_with_source_update_hint(errors: list, amalgamation_type: str) -> li
def _is_name_adoptable(legal_type: str, ting_legal_type: str) -> bool:
"""Return whether the resulting business may adopt the name of an amalgamating business of this type.

A BC or BEN resulting business may adopt a BC or BEN name (the resulting business type can be changed).
A continued-in business counts as its BC equivalent. A BC or BEN resulting business may adopt
a BC or BEN name (the resulting business type can be changed).
"""
ting_legal_type = CONTINUED_IN_TO_BC_LEGAL_TYPE.get(ting_legal_type, ting_legal_type)
if legal_type in BC_BEN_LEGAL_TYPES:
return ting_legal_type in BC_BEN_LEGAL_TYPES
return legal_type == ting_legal_type
Expand All @@ -224,6 +234,9 @@ def validate_amalgamating_businesses( # noqa: PLR0912, PLR0915
Business.LegalTypes.BC_CCC.value: False,
Business.LegalTypes.BC_ULC_COMPANY.value: False,
Business.LegalTypes.ULC_CONTINUE_IN.value: False,
Business.LegalTypes.CONTINUE_IN.value: False,
Business.LegalTypes.BCOMP_CONTINUE_IN.value: False,
Business.LegalTypes.CCC_CONTINUE_IN.value: False,
Business.LegalTypes.COOP.value: False
}
is_any_expro_a = False
Expand Down Expand Up @@ -276,6 +289,9 @@ def validate_amalgamating_businesses( # noqa: PLR0912, PLR0915

# aggregate bookkeeping (CC/ULC mixes, name adoption, type match) shared by LEAR and COLIN TINGs
is_any_business[ting_legal_type] = True
bc_legal_type = CONTINUED_IN_TO_BC_LEGAL_TYPE.get(ting_legal_type)
if bc_legal_type:
is_any_business[bc_legal_type] = True
if _is_name_adoptable(legal_type, ting_legal_type):
adoptable_names.append(ting_legal_name)
if amalgamating_business_json["role"] in [AmalgamatingBusiness.Role.primary.name,
Expand Down Expand Up @@ -357,14 +373,8 @@ def validate_amalgamating_businesses( # noqa: PLR0912, PLR0915
})

if primary_or_holding_legal_type:
continued_types_map = {
Business.LegalTypes.CONTINUE_IN.value: Business.LegalTypes.COMP.value,
Business.LegalTypes.BCOMP_CONTINUE_IN.value: Business.LegalTypes.BCOMP.value,
Business.LegalTypes.ULC_CONTINUE_IN.value: Business.LegalTypes.BC_ULC_COMPANY.value,
Business.LegalTypes.CCC_CONTINUE_IN.value: Business.LegalTypes.BC_CCC.value
}
legal_type_to_compare = continued_types_map.get(primary_or_holding_legal_type,
primary_or_holding_legal_type)
legal_type_to_compare = CONTINUED_IN_TO_BC_LEGAL_TYPE.get(primary_or_holding_legal_type,
primary_or_holding_legal_type)
if legal_type_to_compare != legal_type:
msg.append({
"error": "Legal type should be same as the legal type in primary or holding business.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1260,24 +1260,24 @@ def mock_find_by_identifier(identifier):


@pytest.mark.parametrize(
'test_status, role, expected_code, expected_msg',
'test_status, role, ting_legal_type, expected_code, expected_msg',
[
('FAIL', STAFF_ROLE, HTTPStatus.BAD_REQUEST,
('FAIL', STAFF_ROLE, Business.LegalTypes.BC_ULC_COMPANY.value, HTTPStatus.BAD_REQUEST,
'A BC Unlimited Liability Company cannot amalgamate with a foreign company Foreign Co..'),
('SUCCESS', STAFF_ROLE, None, None)
('FAIL', STAFF_ROLE, Business.LegalTypes.ULC_CONTINUE_IN.value, HTTPStatus.BAD_REQUEST,
'A BC Unlimited Liability Company cannot amalgamate with a foreign company Foreign Co..'),
('SUCCESS', STAFF_ROLE, Business.LegalTypes.BCOMP.value, None, None)
]
)
def test_amalgamating_foreign_business_with_ulc_company(mocker, app, session, jwt,
test_status, role, expected_code, expected_msg):
test_status, role, ting_legal_type, expected_code, expected_msg):
"""Assert valid amalgamating foreign business with ulc company."""
account_id = '123456'
filing = _get_amalg_template()
filing['filing']['amalgamationApplication']['nameRequest']['nrNumber'] = 'NR 1234567'

def mock_find_by_identifier(identifier):
return Business(identifier=identifier,
legal_type=Business.LegalTypes.BC_ULC_COMPANY.value
if test_status == 'FAIL' else Business.LegalTypes.BCOMP.value)
return Business(identifier=identifier, legal_type=ting_legal_type)

mocker.patch('legal_api.services.filings.validations.amalgamation_application.validate_name_request',
return_value=[])
Expand All @@ -1299,25 +1299,24 @@ def mock_find_by_identifier(identifier):


@pytest.mark.parametrize(
'test_status, expected_code, expected_msg',
'test_status, ting_legal_type, expected_code, expected_msg',
[
('FAIL', HTTPStatus.BAD_REQUEST,
('FAIL', Business.LegalTypes.BCOMP.value, HTTPStatus.BAD_REQUEST,
'A BC Community Contribution Company must amalgamate to form a new BC Community Contribution Company.'),
('SUCCESS', None, None)
('SUCCESS_CC', Business.LegalTypes.BC_CCC.value, None, None),
('SUCCESS_CONTINUED_IN', Business.LegalTypes.CCC_CONTINUE_IN.value, None, None)
]
)
def test_amalgamating_cc_to_cc(mocker, app, session, jwt,
test_status, expected_code, expected_msg):
test_status, ting_legal_type, expected_code, expected_msg):
"""Assert valid amalgamating cc to cc."""
account_id = '123456'
filing = _get_amalg_template()
filing['filing']['amalgamationApplication']['nameRequest']['legalType'] = 'CC'
filing['filing']['amalgamationApplication']['nameRequest']['nrNumber'] = 'NR 1234567'

def mock_find_by_identifier(identifier):
return Business(identifier=identifier,
legal_type=Business.LegalTypes.BCOMP.value
if test_status == 'FAIL' else Business.LegalTypes.BC_CCC.value)
return Business(identifier=identifier, legal_type=ting_legal_type)

mocker.patch('legal_api.services.filings.validations.amalgamation_application.validate_name_request',
return_value=[])
Expand All @@ -1331,7 +1330,7 @@ def mock_find_by_identifier(identifier):
err = validate(None, filing, account_id)

# validate outcomes
if test_status == 'SUCCESS':
if test_status.startswith('SUCCESS'):
assert not err
else:
assert expected_code == err.code
Expand Down Expand Up @@ -1512,6 +1511,70 @@ def mock_find_by_identifier(identifier):
assert next((x for x in err.msg if x['error'] == expected_msg), None)


@pytest.mark.parametrize(
'test_status, legal_type, adopted_ting_legal_type, other_ting_legal_type',
[
# a continued-in company counts as its BC equivalent: C=BC, CBEN=BEN, CUL=ULC, CCC=CC
('SUCCESS_BC_ADOPT_CBEN_WITH_BC', Business.LegalTypes.COMP.value,
Business.LegalTypes.BCOMP_CONTINUE_IN.value, Business.LegalTypes.COMP.value),
('SUCCESS_BC_ADOPT_C_WITH_BC', Business.LegalTypes.COMP.value,
Business.LegalTypes.CONTINUE_IN.value, Business.LegalTypes.COMP.value),
('SUCCESS_BEN_ADOPT_CBEN_WITH_BC', Business.LegalTypes.BCOMP.value,
Business.LegalTypes.BCOMP_CONTINUE_IN.value, Business.LegalTypes.COMP.value),
('SUCCESS_BEN_ADOPT_C_WITH_BC', Business.LegalTypes.BCOMP.value,
Business.LegalTypes.CONTINUE_IN.value, Business.LegalTypes.COMP.value),
('SUCCESS_ULC_ADOPT_CUL_WITH_ULC', Business.LegalTypes.BC_ULC_COMPANY.value,
Business.LegalTypes.ULC_CONTINUE_IN.value, Business.LegalTypes.BC_ULC_COMPANY.value),
('SUCCESS_CC_ADOPT_CCC_WITH_CC', Business.LegalTypes.BC_CCC.value,
Business.LegalTypes.CCC_CONTINUE_IN.value, Business.LegalTypes.COMP.value),
# a continued-in ULC is still a ULC - its name is not adoptable by a BC or BEN
('FAIL_BC_ADOPT_CUL_WITH_BC', Business.LegalTypes.COMP.value,
Business.LegalTypes.ULC_CONTINUE_IN.value, Business.LegalTypes.COMP.value),
('FAIL_BEN_ADOPT_CUL_WITH_BC', Business.LegalTypes.BCOMP.value,
Business.LegalTypes.ULC_CONTINUE_IN.value, Business.LegalTypes.COMP.value),
]
)
def test_regular_amalgamation_adopt_continued_in_name(mocker, app, session, jwt, test_status, legal_type,
adopted_ting_legal_type, other_ting_legal_type):
"""Assert the name of a continued-in amalgamating business is adoptable as its BC equivalent."""
account_id = '123456'
filing = _get_amalg_template()
filing['filing']['amalgamationApplication']['nameRequest']['legalType'] = legal_type
filing['filing']['amalgamationApplication']['nameRequest']['legalName'] = 'CONTINUED IN TEST LTD.'
filing['filing']['amalgamationApplication']['amalgamatingBusinesses'] = [
{'role': AmalgamatingBusiness.Role.amalgamating.name, 'identifier': 'C1234567'},
{'role': AmalgamatingBusiness.Role.amalgamating.name, 'identifier': 'BC1234568'}
]

def mock_find_by_identifier(identifier):
if identifier == 'C1234567':
return Business(identifier=identifier,
legal_name='CONTINUED IN TEST LTD.',
legal_type=adopted_ting_legal_type)
return Business(identifier=identifier,
legal_name='OTHER TEST LTD.',
legal_type=other_ting_legal_type)

mocker.patch('legal_api.services.filings.validations.amalgamation_application.validate_name_request',
return_value=[])
mocker.patch('legal_api.services.filings.validations.amalgamation_application._has_pending_filing',
return_value=False)
mocker.patch('legal_api.services.filings.validations.amalgamation_application._is_business_affliated',
return_value=True)
mocker.patch('business_model.models.business.Business.find_by_identifier', side_effect=mock_find_by_identifier)

with jwt_request_context(app, jwt, [STAFF_ROLE], 'staff-user', account_id):
err = validate(None, filing, account_id)

# validate outcomes
expected_msg = 'Adopt a name that have the same business type as the resulting business.'
if test_status.startswith('SUCCESS'):
assert not err, err.msg
else:
assert HTTPStatus.BAD_REQUEST == err.code
assert next((x for x in err.msg if x['error'] == expected_msg), None)


@pytest.mark.parametrize(
'test_status, amalgamating_businesses, expected_code, expected_msg',
[
Expand Down Expand Up @@ -2203,8 +2266,10 @@ def _mock_expro_snapshot_response(**overrides):
('NOT_GOOD_STANDING_IGNORED', None),
('HORIZONTAL', 'A foreign corporation or extra-Pro cannot be part of a Horizontal amalgamation.'),
('HOLDING_ROLE', 'A EXPRO TEST COMPANY LTD. foreign corporation cannot be marked as Primary or Holding.'),
('ULC_TING', 'A BC Unlimited Liability Company cannot amalgamate with '
'a foreign company EXPRO TEST COMPANY LTD..'),
('ULC_TING', 'A BC Unlimited Liability Company cannot amalgamate with a foreign company '
'EXPRO TEST COMPANY LTD..'),
('ULC_CONTINUED_IN_TING', 'A BC Unlimited Liability Company cannot amalgamate with a foreign company '
'EXPRO TEST COMPANY LTD..'),
]
)
def test_expro_amalgamating_business(mocker, app, session, jwt, test_status, expected_msg):
Expand All @@ -2228,6 +2293,7 @@ def mock_find_by_identifier(identifier):
if identifier == EXPRO_IDENTIFIER:
return None
legal_type = (Business.LegalTypes.BC_ULC_COMPANY.value if test_status == 'ULC_TING'
else Business.LegalTypes.ULC_CONTINUE_IN.value if test_status == 'ULC_CONTINUED_IN_TING'
else Business.LegalTypes.BCOMP.value)
return Business(identifier=identifier,
founding_date=datetime.now(timezone.utc),
Expand Down Expand Up @@ -2885,3 +2951,4 @@ def test_amalgamation_entity_not_enabled(mocker, app, session, jwt, flag_value):

assert err.code == HTTPStatus.FORBIDDEN
assert err.msg[0]['error'] == 'CP is not enabled for amalgamation entities.'