Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8a4229

Browse files
34483 validation of continuationOut and amalgamationOut in correction (#4692)
1 parent b4ae18a commit c8a4229

8 files changed

Lines changed: 200 additions & 40 deletions

File tree

legal-api/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "legal-api"
3-
version = "3.1.11"
3+
version = "3.1.12"
44
description = ""
55
authors = [
66
{name = "thor",email = "[email protected]"}

legal-api/src/legal_api/services/authz.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,13 @@ def get_allowable_filings_dict(is_authorization: bool = False):
448448
}
449449
},
450450
Business.State.HISTORICAL: {
451+
"correction": {
452+
"legalTypes": ["BEN", "BC", "ULC", "CC", "C", "CBEN", "CUL", "CCC"],
453+
"blockerChecks": {
454+
"warningTypes": [WarningType.MISSING_REQUIRED_BUSINESS_INFO],
455+
"business": [BusinessBlocker.DEFAULT]
456+
}
457+
},
451458
"courtOrder": {
452459
"legalTypes": ["SP", "GP", "CP", "BC", "BEN", "CC", "ULC", "C", "CBEN", "CUL", "CCC"],
453460
},

legal-api/src/legal_api/services/filings/validations/amalgamation_out.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def validate(business: Business, filing: dict) -> Error | None:
4444
is_valid_co_date = True
4545
is_valid_foreign_jurisdiction = True
4646

47-
if err := validate_amalgamation_out_date(filing, filing_type):
47+
if err := validate_amalgamation_out_date(filing, f"/filing/{filing_type}/amalgamationOutDate"):
4848
msg.extend(err)
4949
is_valid_co_date = False
5050

@@ -96,10 +96,9 @@ def validate_active_cao(business: Business, filing: dict, filing_type: str) -> l
9696
return msg
9797

9898

99-
def validate_amalgamation_out_date(filing: dict, filing_type: str) -> list:
99+
def validate_amalgamation_out_date(filing: dict, amalgamation_out_date_path: str) -> list:
100100
"""Validate amalgamation out date."""
101101
msg = []
102-
amalgamation_out_date_path = f"/filing/{filing_type}/amalgamationOutDate"
103102
amalgamation_out_date = get_date(filing, amalgamation_out_date_path)
104103

105104
now = LegislationDatetime.now().date()

legal-api/src/legal_api/services/filings/validations/continuation_out.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ def validate(business: Business, filing: dict) -> Error | None:
4141
msg = []
4242
filing_type = "continuationOut"
4343

44-
45-
if err := validate_continuation_out_date(filing, filing_type):
46-
msg.extend(err)
47-
48-
if err := validate_foreign_jurisdiction(filing["filing"][filing_type]["foreignJurisdiction"],
49-
f"/filing/{filing_type}/foreignJurisdiction"):
50-
msg.extend(err)
44+
msg.extend(validate_continuation_out_date(filing, f"/filing/{filing_type}/continuationOutDate"))
45+
msg.extend(validate_foreign_jurisdiction(
46+
filing["filing"][filing_type]["foreignJurisdiction"],
47+
f"/filing/{filing_type}/foreignJurisdiction"
48+
))
5149

5250
if court_order := filing.get("filing", {}).get(filing_type, {}).get("courtOrder", None):
5351
court_order_path: Final = f"/filing/{filing_type}/courtOrder"
@@ -60,10 +58,9 @@ def validate(business: Business, filing: dict) -> Error | None:
6058
return None
6159

6260

63-
def validate_continuation_out_date(filing: dict, filing_type: str) -> list:
61+
def validate_continuation_out_date(filing: dict, continuation_out_date_path: str) -> list:
6462
"""Validate continuation out date."""
6563
msg = []
66-
continuation_out_date_path = f"/filing/{filing_type}/continuationOutDate"
6764
continuation_out_date = get_date(filing, continuation_out_date_path)
6865

6966
now = LegislationDatetime.now().date()

legal-api/src/legal_api/services/filings/validations/correction.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
from legal_api.errors import Error
2626
from legal_api.services import STAFF_ROLE, SYSTEM_ROLE, NaicsService
2727
from legal_api.services.filings.validations.alteration import validate_type_change
28+
from legal_api.services.filings.validations.amalgamation_out import validate_amalgamation_out_date
2829
from legal_api.services.filings.validations.common_validations import (
2930
validate_court_order,
31+
validate_foreign_jurisdiction,
3032
validate_name_request,
3133
validate_offices_addresses,
3234
validate_parties_addresses,
@@ -41,6 +43,7 @@
4143
validate_continuation_in_foreign_jurisdiction,
4244
validate_continuation_in_xpro_business_in_colin,
4345
)
46+
from legal_api.services.filings.validations.continuation_out import validate_continuation_out_date
4447
from legal_api.services.filings.validations.incorporation_application import (
4548
validate_coop_parties_mailing_address,
4649
validate_roles,
@@ -84,6 +87,11 @@ def validate(business: Business, filing: dict) -> Error:
8487
path = "/filing/correction/correctedFilingId"
8588
msg.append({"error": _("Corrected filing is not a valid filing for this business."), "path": path})
8689

90+
elif corrected_filing.filing_type != filing["filing"]["correction"]["correctedFilingType"]:
91+
path = "/filing/correction/correctedFilingType"
92+
msg.append({"error": _("The corrected filing type does not match filing type of corrected filing."),
93+
"path": path})
94+
8795
# skip all the other validation checks if comment only correction
8896
if not is_comment_only_correction:
8997
if filing.get("filing", {}).get("correction", {}).get("parties", None):
@@ -105,19 +113,22 @@ def validate(business: Business, filing: dict) -> Error:
105113
))
106114
if filing.get("filing", {}).get("correction", {}).get("offices", None):
107115
msg.extend(validate_offices_addresses(filing, filing_type))
108-
# validations for firms
109-
if business.legal_type in [Business.LegalTypes.SOLE_PROP.value, Business.LegalTypes.PARTNERSHIP.value]:
110-
_validate_firms_correction(business, filing, business.legal_type, msg)
111-
elif business.legal_type in Business.CORPS:
112-
_validate_corps_correction(business, filing, business.legal_type, msg)
113-
elif business.legal_type == Business.LegalTypes.COOP.value:
114-
_validate_special_resolution_correction(filing, business.legal_type, msg)
116+
117+
_validate_type_specific_props(business, filing, msg)
115118

116119
if msg:
117120
return Error(HTTPStatus.BAD_REQUEST, msg)
118121

119122
return None
120123

124+
def _validate_type_specific_props(business: Business, filing: dict, msg: list):
125+
if business.legal_type in [Business.LegalTypes.SOLE_PROP.value, Business.LegalTypes.PARTNERSHIP.value]:
126+
_validate_firms_correction(business, filing, business.legal_type, msg)
127+
elif business.legal_type in Business.CORPS:
128+
_validate_corps_correction(business, filing, business.legal_type, msg)
129+
elif business.legal_type == Business.LegalTypes.COOP.value:
130+
_validate_special_resolution_correction(filing, business.legal_type, msg)
131+
121132

122133
def _validate_firms_correction(business: Business, filing, legal_type, msg):
123134
filing_type = "correction"
@@ -160,6 +171,7 @@ def _validate_corps_correction(business: Business, filing_dict, legal_type, msg)
160171
msg.extend(validate_resolution_date_in_share_structure(filing_dict, filing_type, business))
161172

162173
msg.extend(_validate_continuation_in_correction(filing_dict, filing_type, legal_type))
174+
msg.extend(_validate_out_correction(filing_dict, filing_type))
163175

164176

165177
def _validate_continuation_in_correction(filing_dict, filing_type, legal_type):
@@ -179,6 +191,17 @@ def _validate_continuation_in_correction(filing_dict, filing_type, legal_type):
179191
return msg
180192

181193

194+
def _validate_out_correction(filing_dict, filing_type):
195+
msg = []
196+
if continuation_out := filing_dict["filing"][filing_type].get("continuationOut"):
197+
msg.extend(validate_continuation_out_date(filing_dict, f"/filing/{filing_type}/continuationOut/date"))
198+
msg.extend(validate_foreign_jurisdiction(continuation_out, f"/filing/{filing_type}/continuationOut"))
199+
elif amalgamation_out := filing_dict["filing"][filing_type].get("amalgamationOut"):
200+
msg.extend(validate_amalgamation_out_date(filing_dict, f"/filing/{filing_type}/amalgamationOut/date"))
201+
msg.extend(validate_foreign_jurisdiction(amalgamation_out, f"/filing/{filing_type}/amalgamationOut"))
202+
return msg
203+
204+
182205
def _validate_special_resolution_correction(filing_dict, legal_type, msg):
183206
filing_type = "correction"
184207
if filing_dict.get("filing", {}).get(filing_type, {}).get("nameRequest", {}).get("nrNumber", None):

legal-api/tests/unit/services/filings/validations/test_correction_firms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def test_valid_firms_correction(app, session, jwt, test_name, filing):
9090

9191
f['filing']['header']['identifier'] = identifier
9292
f['filing']['correction']['correctedFilingId'] = corrected_filing.id
93+
f['filing']['correction']['correctedFilingType'] = 'changeOfRegistration'
9394

9495
nr_res = copy.deepcopy(nr_response)
9596
nr_res['legalType'] = legal_type
@@ -121,6 +122,7 @@ def test_firms_correction_invalid_parties(app, session, jwt, test_name, filing,
121122

122123
f['filing']['header']['identifier'] = identifier
123124
f['filing']['correction']['correctedFilingId'] = corrected_filing.id
125+
f['filing']['correction']['correctedFilingType'] = 'changeOfRegistration'
124126

125127
del f['filing']['correction']['parties'][0]['roles'][0]
126128
nr_res = copy.deepcopy(nr_response)
@@ -189,6 +191,7 @@ def test_firms_correction_naics(app, session, jwt, test_name, filing, existing_n
189191

190192
f['filing']['header']['identifier'] = identifier
191193
f['filing']['correction']['correctedFilingId'] = corrected_filing.id
194+
f['filing']['correction']['correctedFilingType'] = 'changeOfRegistration'
192195
if correction_naics_code:
193196
f['filing']['correction']['business']['naics']['naicsCode'] = correction_naics_code
194197
else:
@@ -252,6 +255,7 @@ def test_firms_correction_start_date(app, session, jwt, test_name, filing, usern
252255

253256
f['filing']['header']['identifier'] = identifier
254257
f['filing']['correction']['correctedFilingId'] = corrected_filing.id
258+
f['filing']['correction']['correctedFilingType'] = 'changeOfRegistration'
255259
f['filing']['correction']['startDate'] = start_date.strftime('%Y-%m-%d')
256260

257261
nr_res = copy.deepcopy(nr_response)

legal-api/tests/unit/services/filings/validations/test_correction_ia.py

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import copy
1717
import datedelta
18+
import pycountry
1819
from datetime import datetime, timezone
1920
from freezegun import freeze_time
2021
from http import HTTPStatus
@@ -23,13 +24,17 @@
2324
import pytest
2425

2526
from business_model.models import Business, Resolution
27+
from business_common.utils.legislation_datetime import LegislationDatetime
2628
from business_common.utils.datetime import datetime as dt, timedelta
2729
from legal_api.services import NameXService
2830
from legal_api.services.authz import BASIC_USER, STAFF_ROLE
2931
from legal_api.services.filings import validate
3032
from registry_schemas.example_data import (
31-
CORRECTION_INCORPORATION,
33+
AMALGAMATION_OUT,
34+
CORRECTION_INCORPORATION,
3235
CONTINUATION_IN_FILING_TEMPLATE,
36+
CONTINUATION_OUT,
37+
FILING_HEADER,
3338
INCORPORATION_FILING_TEMPLATE
3439
)
3540

@@ -39,6 +44,7 @@
3944
from tests.unit.services.utils import jwt_request_context
4045

4146

47+
date_format = '%Y-%m-%d'
4248
INCORPORATION_APPLICATION = copy.deepcopy(INCORPORATION_FILING_TEMPLATE)
4349
CORRECTION = copy.deepcopy(CORRECTION_INCORPORATION)
4450

@@ -808,3 +814,108 @@ def test_validate_continuation_in_xpro_founding_date_match(mocker, app, session,
808814
err = validate(business, filing)
809815
assert not err
810816

817+
818+
@pytest.mark.parametrize('filing_type', ['continuationOut', 'amalgamationOut'])
819+
@pytest.mark.parametrize(
820+
'test_name, expected_code, message',
821+
[
822+
('FAIL_IN_FUTURE', HTTPStatus.BAD_REQUEST, '{0} out date must be today or past.'),
823+
('SUCCESS_NO_CCO', None, None),
824+
('SUCCESS', None, None)
825+
]
826+
)
827+
def test_validate_continuation_out_date(session, app, jwt, filing_type, test_name, expected_code, message):
828+
"""Assert validate continuation_out_date."""
829+
identifier = 'BC1234567'
830+
business = factory_business(identifier, entity_type='BC')
831+
continuation_out_filing = copy.deepcopy(FILING_HEADER)
832+
continuation_out_filing['filing'][filing_type] = copy.deepcopy(CONTINUATION_OUT if filing_type == 'continuationOut' else AMALGAMATION_OUT)
833+
continuation_out_filing['filing']['header']['name'] = filing_type
834+
835+
corrected_filing = factory_completed_filing(business, continuation_out_filing)
836+
837+
838+
filing = copy.deepcopy(CORRECTION)
839+
filing['filing']['header']['identifier'] = identifier
840+
filing['filing']['correction']['correctedFilingId'] = corrected_filing.id
841+
filing['filing']['correction']['correctedFilingType'] = filing_type
842+
filing['filing']['correction'][filing_type] = {
843+
'country': 'CA',
844+
'region': 'AB',
845+
'legalName': 'HAULER SERVICES',
846+
'date': '2023-06-19'
847+
}
848+
del filing['filing']['correction']['commentOnly']
849+
850+
if test_name == 'FAIL_IN_FUTURE':
851+
filing['filing']['correction'][filing_type]['date'] = \
852+
(LegislationDatetime.now() + datedelta.datedelta(days=1)).strftime(date_format)
853+
854+
with jwt_request_context(app, jwt, [BASIC_USER]):
855+
err = validate(business, filing)
856+
857+
# validate outcomes
858+
if test_name == 'FAIL_IN_FUTURE':
859+
assert expected_code == err.code
860+
assert message.format(filing_type.replace('Out', '').capitalize()) == err.msg[0]['error']
861+
else:
862+
assert not err
863+
864+
865+
@pytest.mark.parametrize('filing_type', ['continuationOut', 'amalgamationOut'])
866+
@pytest.mark.parametrize(
867+
'test_name, expected_code, message',
868+
[
869+
('FAIL_NO_COUNTRY', HTTPStatus.UNPROCESSABLE_ENTITY, None),
870+
('FAIL_INVALID_COUNTRY', HTTPStatus.BAD_REQUEST, 'Invalid country.'),
871+
('FAIL_REGION_BC', HTTPStatus.BAD_REQUEST, 'Region should not be BC.'),
872+
('FAIL_INVALID_REGION', HTTPStatus.BAD_REQUEST, 'Invalid region.'),
873+
('FAIL_INVALID_US_REGION', HTTPStatus.BAD_REQUEST, 'Invalid region.'),
874+
('SUCCESS', None, None)
875+
]
876+
)
877+
def test_validate_continuation_out_foreign_jurisdiction(session, app, jwt, filing_type, test_name, expected_code, message):
878+
"""Assert validate continuation_out foreign jurisdiction."""
879+
identifier = 'BC1234567'
880+
business = factory_business(identifier, entity_type='BC')
881+
continuation_out_filing = copy.deepcopy(FILING_HEADER)
882+
continuation_out_filing['filing'][filing_type] = copy.deepcopy(CONTINUATION_OUT if filing_type == 'continuationOut' else AMALGAMATION_OUT)
883+
continuation_out_filing['filing']['header']['name'] = filing_type
884+
885+
corrected_filing = factory_completed_filing(business, continuation_out_filing)
886+
887+
filing = copy.deepcopy(CORRECTION)
888+
filing['filing']['header']['identifier'] = identifier
889+
filing['filing']['correction']['correctedFilingId'] = corrected_filing.id
890+
filing['filing']['correction']['correctedFilingType'] = filing_type
891+
filing['filing']['correction'][filing_type] = {
892+
'country': 'CA',
893+
'region': 'AB',
894+
'legalName': 'HAULER SERVICES',
895+
'date': '2023-06-19'
896+
}
897+
del filing['filing']['correction']['commentOnly']
898+
899+
900+
if test_name == 'FAIL_NO_COUNTRY':
901+
del filing['filing']['correction'][filing_type]['country']
902+
elif test_name == 'FAIL_INVALID_COUNTRY':
903+
filing['filing']['correction'][filing_type]['country'] = 'NONE'
904+
elif test_name == 'FAIL_REGION_BC':
905+
filing['filing']['correction'][filing_type]['region'] = 'BC'
906+
elif test_name == 'FAIL_INVALID_REGION':
907+
filing['filing']['correction'][filing_type]['region'] = 'NONE'
908+
elif test_name == 'FAIL_INVALID_US_REGION':
909+
filing['filing']['correction'][filing_type]['country'] = 'US'
910+
filing['filing']['correction'][filing_type]['region'] = 'NONE'
911+
912+
with jwt_request_context(app, jwt, [BASIC_USER]):
913+
err = validate(business, filing)
914+
915+
# validate outcomes
916+
if test_name != 'SUCCESS':
917+
assert expected_code == err.code
918+
if message:
919+
assert message == err.msg[0]['error']
920+
else:
921+
assert not err

0 commit comments

Comments
 (0)