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

Skip to content

Commit 7b745c0

Browse files
34494 court order document list in correction fix (#4778)
1 parent f394154 commit 7b745c0

4 files changed

Lines changed: 145 additions & 14 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.28"
3+
version = "3.1.29"
44
description = ""
55
authors = [
66
{name = "thor",email = "[email protected]"}

legal-api/src/legal_api/core/filing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ def _populate_completed_filing_documents( # noqa: PLR0913
588588
filing.storage.transaction_id and
589589
(business_rev := VersionedBusinessDetailsService.get_business_revision_obj(filing.storage, business.id))
590590
):
591+
business_rev.identifier = business.identifier
591592
business = business_rev
592593

593594
adds = [FilingMeta.get_all_outputs(business.legal_type, doc) for doc in legal_filings]

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -576,23 +576,39 @@ def _validate_court_order_documents(court_order_path, court_order):
576576
file_key = court_order.get("fileKey")
577577
files = court_order.get("files", [])
578578

579+
existing_file_keys = []
580+
if filing_id := court_order.get("filingId"): # used for correction filings
581+
filing = Filing.find_by_id(filing_id)
582+
existing_file_keys = [document.file_key for document in filing.documents.all()]
583+
579584
if not court_order.get("orderDetails") and not file_key and not files:
580585
msg.append({"error": _("Court Order is required (in orderDetails/fileKey/files)."), "path": court_order_path})
581586

582587
if file_key:
583588
msg.extend(validate_pdf(file_key, f"{court_order_path}/fileKey"))
584589
elif files:
585-
court_order_document_count = 0
586-
files_path = f"{court_order_path}/files"
587-
for file_index, file in enumerate(files):
588-
if file.get("documentType") == DocumentType.COURT_ORDER.value:
589-
court_order_document_count += 1
590-
msg.extend(validate_pdf(file.get("fileKey"), f"{files_path}/{file_index}/fileKey"))
591-
592-
if court_order_document_count == 0: # if only supporting documents and no court order documents were found
593-
msg.append({"error": _("At least one Court Order document is required."), "path": files_path})
594-
elif court_order_document_count > 1:
595-
msg.append({"error": _("Only one Court Order document is allowed."), "path": files_path})
590+
msg.extend(_validate_court_order_documents_list(f"{court_order_path}/files", files, existing_file_keys))
591+
592+
return msg
593+
594+
595+
def _validate_court_order_documents_list(files_path, files, existing_file_keys):
596+
"""Validate the court order documents list."""
597+
msg = []
598+
court_order_document_count = 0
599+
for file_index, file in enumerate(files):
600+
if file.get("documentType") == DocumentType.COURT_ORDER.value:
601+
court_order_document_count += 1
602+
603+
if file.get("fileKey") in existing_file_keys:
604+
continue # don't validate existing file keys
605+
606+
msg.extend(validate_pdf(file.get("fileKey"), f"{files_path}/{file_index}/fileKey"))
607+
608+
if court_order_document_count == 0: # if only supporting documents and no court order documents were found
609+
msg.append({"error": _("At least one Court Order document is required."), "path": files_path})
610+
elif court_order_document_count > 1:
611+
msg.append({"error": _("Only one Court Order document is allowed."), "path": files_path})
596612

597613
return msg
598614

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

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""Test Correction IA validations."""
1515

16+
import uuid
1617
import copy
1718
import datedelta
1819
import pycountry
@@ -23,7 +24,16 @@
2324

2425
import pytest
2526

26-
from business_model.models import AmalgamatingBusiness, Amalgamation, Business, CourtOrder, PartyRole, Resolution
27+
from business_model.models import (
28+
AmalgamatingBusiness,
29+
Amalgamation,
30+
Business,
31+
CourtOrder,
32+
Document,
33+
DocumentType,
34+
PartyRole,
35+
Resolution
36+
)
2737
from business_common.utils.legislation_datetime import LegislationDatetime
2838
from business_common.utils.datetime import datetime as dt, timedelta
2939
from legal_api.services import NameXService
@@ -933,6 +943,7 @@ def test_validate_continuation_out_date(session, app, jwt, filing_type, test_nam
933943
'date': '2023-06-19'
934944
}
935945
del filing['filing']['correction']['commentOnly']
946+
del filing['filing']['correction']['nameRequest']
936947

937948
if test_name == 'FAIL_IN_FUTURE':
938949
filing['filing']['correction'][filing_type]['date'] = \
@@ -984,7 +995,7 @@ def test_validate_continuation_out_foreign_jurisdiction(session, app, jwt, filin
984995
'date': '2023-06-19'
985996
}
986997
del filing['filing']['correction']['commentOnly']
987-
998+
del filing['filing']['correction']['nameRequest']
988999

9891000
if test_name == 'FAIL_NO_COUNTRY':
9901001
del filing['filing']['correction'][filing_type]['country']
@@ -1042,6 +1053,7 @@ def test_validate_correction_out_existing_foreign_jurisdiction(mocker, app, sess
10421053
'date': '2023-06-19'
10431054
}
10441055
del filing['filing']['correction']['commentOnly']
1056+
del filing['filing']['correction']['nameRequest']
10451057

10461058
with jwt_request_context(app, jwt, [BASIC_USER]):
10471059
err = validate(business, filing)
@@ -1336,6 +1348,7 @@ def test_validate_invalid_court_order(app, jwt, session, invalid_court_order, er
13361348
filing['filing']['header']['identifier'] = identifier
13371349
filing['filing']['correction']['correctedFilingId'] = corrected_filing.id
13381350
del filing['filing']['correction']['commentOnly']
1351+
del filing['filing']['correction']['nameRequest']
13391352
filing['filing']['correction']['courtOrder'] = invalid_court_order
13401353

13411354
with jwt_request_context(app, jwt, [BASIC_USER]):
@@ -1381,6 +1394,7 @@ def test_validate_invalid_court_orders_new(app, jwt, session, invalid_court_orde
13811394
filing['filing']['header']['identifier'] = identifier
13821395
filing['filing']['correction']['correctedFilingId'] = ia_filing.id
13831396
del filing['filing']['correction']['commentOnly']
1397+
del filing['filing']['correction']['nameRequest']
13841398
invalid_court_order["filingId"] = ia_filing.id
13851399

13861400
filing['filing']['correction']['courtOrders'] = [invalid_court_order]
@@ -1426,6 +1440,7 @@ def test_validate_invalid_court_orders_old(app, jwt, session, invalid_court_orde
14261440
filing['filing']['header']['identifier'] = identifier
14271441
filing['filing']['correction']['correctedFilingId'] = ia_filing.id
14281442
del filing['filing']['correction']['commentOnly']
1443+
del filing['filing']['correction']['nameRequest']
14291444
invalid_court_order["filingId"] = ia_filing.id
14301445
invalid_court_order["id"] = court_order.id
14311446

@@ -1460,6 +1475,7 @@ def test_validate_invalid_court_orders(app, jwt, session, test_name, error_msg):
14601475
filing['filing']['header']['identifier'] = identifier
14611476
filing['filing']['correction']['correctedFilingId'] = ia_filing.id
14621477
del filing['filing']['correction']['commentOnly']
1478+
del filing['filing']['correction']['nameRequest']
14631479
if test_name == "court_order_not_found":
14641480
invalid_court_order["filingId"] = ia_filing.id
14651481
invalid_court_order["id"] = 99999999
@@ -1490,6 +1506,103 @@ def test_validate_invalid_court_orders(app, jwt, session, test_name, error_msg):
14901506
assert err.msg[0]['error'] == error_msg
14911507

14921508

1509+
@pytest.mark.parametrize('test_name', [
1510+
('no_change'),
1511+
('add_new_court_order'),
1512+
('replace_existing_court_order')
1513+
])
1514+
def test_validate_correction_court_order_documents(app, session, jwt, mocker, test_name):
1515+
"""Assert the worker process process the court orders correctly."""
1516+
identifier = 'BC1234567'
1517+
business = factory_business(identifier, entity_type='BC')
1518+
1519+
ia_filing = factory_completed_filing(business, INCORPORATION_APPLICATION)
1520+
court_order_filing = factory_completed_filing(business, COURT_ORDER_FILING_TEMPLATE)
1521+
1522+
filing = copy.deepcopy(CORRECTION)
1523+
filing['filing']['header']['identifier'] = identifier
1524+
filing['filing']['correction']['correctedFilingId'] = ia_filing.id
1525+
del filing['filing']['correction']['commentOnly']
1526+
del filing['filing']['correction']['nameRequest']
1527+
1528+
file_number = '#1234-5678/90'
1529+
new_file_number = '#2222-2222/22'
1530+
effect_of_order = 'planOfArrangement'
1531+
order_details = 'Court order details'
1532+
1533+
court_order = CourtOrder(
1534+
filing_id=court_order_filing.id,
1535+
business_id=business.id,
1536+
file_number=file_number,
1537+
effect_of_order=effect_of_order,
1538+
order_details=order_details
1539+
)
1540+
court_order.save()
1541+
1542+
court_order_json = {
1543+
"filingId": court_order_filing.id,
1544+
"fileNumber": file_number,
1545+
"effectOfOrder": effect_of_order,
1546+
"orderDetails": order_details,
1547+
"id": court_order.id
1548+
}
1549+
file_key_1 = f"{uuid.uuid4()}.pdf"
1550+
file_key_2 = f"{uuid.uuid4()}.pdf"
1551+
file_key_3 = f"{uuid.uuid4()}.pdf"
1552+
file_name_1 = f'Court Order {file_number}_01.pdf'
1553+
file_name_2 = f'Court Order {file_number}_02.pdf'
1554+
file_name_3 = f'Court Order {file_number}_03.pdf'
1555+
file_1 = {
1556+
"fileKey": file_key_1,
1557+
"fileName": file_name_1,
1558+
"documentType": DocumentType.COURT_ORDER.value
1559+
}
1560+
file_2 = {
1561+
"fileKey": file_key_2,
1562+
"fileName": file_name_2,
1563+
"documentType": DocumentType.SUPPORTING_DOCUMENT.value
1564+
}
1565+
file_3 = {
1566+
"fileKey": file_key_3,
1567+
"fileName": file_name_3,
1568+
"documentType": DocumentType.COURT_ORDER.value
1569+
}
1570+
1571+
document = Document()
1572+
document.type = file_1.get("documentType")
1573+
document.file_key = file_1.get("fileKey")
1574+
document.file_name = file_1.get("fileName")
1575+
document.filing_id = court_order_filing.id
1576+
document.business_id = business.id
1577+
document.save()
1578+
1579+
if test_name == 'add_new_court_order':
1580+
court_order_json['files'] = [file_1, file_2]
1581+
elif test_name == 'replace_existing_court_order':
1582+
court_order_json['files'] = [file_3]
1583+
else:
1584+
court_order_json['files'] = [file_1]
1585+
1586+
filing['filing']['correction']['courtOrders'] = [court_order_json]
1587+
1588+
1589+
mock_validate_pdf = mocker.patch('legal_api.services.filings.validations.common_validations.validate_pdf', return_value=[])
1590+
1591+
with jwt_request_context(app, jwt, [BASIC_USER]):
1592+
err = validate(business, filing)
1593+
assert not err
1594+
1595+
if test_name == 'add_new_court_order':
1596+
assert len(mock_validate_pdf.call_args_list) == 1
1597+
assert mock_validate_pdf.call_args_list[0].args[0] == file_key_2
1598+
elif test_name == 'replace_existing_court_order':
1599+
assert len(mock_validate_pdf.call_args_list) == 1
1600+
assert mock_validate_pdf.call_args_list[0].args[0] == file_key_3
1601+
else:
1602+
assert len(mock_validate_pdf.call_args_list) == 0
1603+
1604+
1605+
14931606
@pytest.mark.parametrize('test_name, err_msg', [
14941607
("test_completing_party_staff", "Should not provide completing party when correction type is STAFF"),
14951608
("test_multiple_completing_parties", 'Only one completing party is allowed.'),
@@ -1533,6 +1646,7 @@ def test_validate_correction_relationships_roles(session, app, jwt, test_name, e
15331646
filing['filing']['business']['legalType'] = business.legal_type
15341647
del filing['filing']['correction']['commentOnly']
15351648
del filing['filing']['correction']['parties']
1649+
del filing['filing']['correction']['nameRequest']
15361650

15371651
if test_name == "test_completing_party_staff":
15381652
filing['filing']['correction']['type'] = 'STAFF'

0 commit comments

Comments
 (0)