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.38"
version = "3.1.39"
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 @@ -127,7 +127,11 @@ def _validate_name_request_section(amalgamation_json, amalgamation_type, legal_t
"path": f"/filing/{filing_type}/nameRequest/nrNumber"
}]

return validate_name_request(amalgamation_json, legal_type, filing_type)
# a BC or BEN resulting business may use an NR of either type
bc_ben_legal_types = [Business.LegalTypes.COMP.value, Business.LegalTypes.BCOMP.value]
accepted_legal_types = bc_ben_legal_types if legal_type in bc_ben_legal_types else None
return validate_name_request(amalgamation_json, legal_type, filing_type,
accepted_legal_types=accepted_legal_types)


def _structural_validation_errors(amalgamation_json, legal_type, filing_type) -> list:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1059,11 +1059,12 @@ def _validate_relationship_date(date_value: date,
return msg


def validate_name_request(filing_json: dict, # pylint: disable=too-many-locals
def validate_name_request(filing_json: dict, # noqa: PLR0913 # pylint: disable=too-many-locals
legal_type: str,
filing_type: str,
accepted_request_types: list | None = None,
filing_id: int | None = None) -> list:
filing_id: int | None = None,
accepted_legal_types: list | None = None) -> list:
"""Validate name request section."""
nr_path = f"/filing/{filing_type}/nameRequest"
nr_number_path = f"{nr_path}/nrNumber"
Expand All @@ -1076,12 +1077,11 @@ def validate_name_request(filing_json: dict, # pylint: disable=too-many-locals
if not nr_number and not legal_name:
if legal_type in Business.CORPS:
return [] # It's numbered company
else:
# CP, SP, GP doesn't support numbered company
return [{"error": _("Legal name and nrNumber is missing in nameRequest."), "path": nr_path}]
elif nr_number and not legal_name:
# CP, SP, GP doesn't support numbered company
return [{"error": _("Legal name and nrNumber is missing in nameRequest."), "path": nr_path}]
if nr_number and not legal_name:
return [{"error": _("Legal name is missing in nameRequest."), "path": legal_name_path}]
elif not nr_number and legal_name:
if not nr_number and legal_name:
# expecting nrNumber when legalName provided
return [{
"error": _("nrNumber is missing for the legal name provided in nameRequest."),
Expand All @@ -1108,7 +1108,7 @@ def validate_name_request(filing_json: dict, # pylint: disable=too-many-locals

# ensure business type
nr_legal_type = nr_response_json.get("legalType")
if legal_type != nr_legal_type:
if nr_legal_type not in (accepted_legal_types or [legal_type]):
msg.append({"error": _("Name Request legal type is not same as the business legal type."),
"path": legal_type_path})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,40 @@ def test_invalid_nr_amalgamation(mocker, app, session):
assert err.msg[0]['error'] == 'Name Request is not approved.'


@pytest.mark.parametrize(
'test_name, legal_type, nr_legal_type, expected_msg',
[
('SUCCESS_BC_NR_BC', Business.LegalTypes.COMP.value, Business.LegalTypes.COMP.value, None),
('SUCCESS_BEN_NR_BEN', Business.LegalTypes.BCOMP.value, Business.LegalTypes.BCOMP.value, None),
('SUCCESS_BEN_NR_BC', Business.LegalTypes.BCOMP.value, Business.LegalTypes.COMP.value, None),
('SUCCESS_BC_NR_BEN', Business.LegalTypes.COMP.value, Business.LegalTypes.BCOMP.value, None),
('FAIL_BC_NR_ULC', Business.LegalTypes.COMP.value, Business.LegalTypes.BC_ULC_COMPANY.value,
'Name Request legal type is not same as the business legal type.'),
('FAIL_ULC_NR_BC', Business.LegalTypes.BC_ULC_COMPANY.value, Business.LegalTypes.COMP.value,
'Name Request legal type is not same as the business legal type.'),
('FAIL_CC_NR_BEN', Business.LegalTypes.BC_CCC.value, Business.LegalTypes.BCOMP.value,
'Name Request legal type is not same as the business legal type.'),
]
)
def test_amalgamation_nr_legal_type(mocker, app, session, test_name, legal_type, nr_legal_type, expected_msg):
"""Assert a BC or BEN resulting business accepts an NR of either type; other mismatches are rejected."""
filing = _get_amalg_template()
filing['filing']['amalgamationApplication']['nameRequest']['nrNumber'] = 'NR 1234567'
filing['filing']['amalgamationApplication']['nameRequest']['legalType'] = legal_type

mocker.patch('legal_api.services.filings.validations.amalgamation_application.validate_amalgamating_businesses',
return_value=[])
with patch.object(NameXService, 'query_nr_number', return_value=_mock_nr_response(nr_legal_type)):
err = validate(None, filing)

if expected_msg:
assert err.code == HTTPStatus.BAD_REQUEST
assert lists_are_equal(err.msg, [{'error': expected_msg,
'path': '/filing/amalgamationApplication/nameRequest/legalType'}])
else:
assert err is None


@pytest.mark.parametrize(
'amalgamation_type',
[
Expand Down
Loading