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.28"
version = "3.1.29"
description = ""
authors = [
{name = "thor",email = "1042854+thorwolpert@users.noreply.github.com"}
Expand Down
1 change: 1 addition & 0 deletions legal-api/src/legal_api/core/filing.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ def _populate_completed_filing_documents( # noqa: PLR0913
filing.storage.transaction_id and
(business_rev := VersionedBusinessDetailsService.get_business_revision_obj(filing.storage, business.id))
):
business_rev.identifier = business.identifier

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

business = business_rev

adds = [FilingMeta.get_all_outputs(business.legal_type, doc) for doc in legal_filings]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,23 +576,39 @@ def _validate_court_order_documents(court_order_path, court_order):
file_key = court_order.get("fileKey")
files = court_order.get("files", [])

existing_file_keys = []
if filing_id := court_order.get("filingId"): # used for correction filings
filing = Filing.find_by_id(filing_id)
existing_file_keys = [document.file_key for document in filing.documents.all()]

if not court_order.get("orderDetails") and not file_key and not files:
msg.append({"error": _("Court Order is required (in orderDetails/fileKey/files)."), "path": court_order_path})

if file_key:
msg.extend(validate_pdf(file_key, f"{court_order_path}/fileKey"))
elif files:
court_order_document_count = 0
files_path = f"{court_order_path}/files"
for file_index, file in enumerate(files):
if file.get("documentType") == DocumentType.COURT_ORDER.value:
court_order_document_count += 1
msg.extend(validate_pdf(file.get("fileKey"), f"{files_path}/{file_index}/fileKey"))

if court_order_document_count == 0: # if only supporting documents and no court order documents were found
msg.append({"error": _("At least one Court Order document is required."), "path": files_path})
elif court_order_document_count > 1:
msg.append({"error": _("Only one Court Order document is allowed."), "path": files_path})
msg.extend(_validate_court_order_documents_list(f"{court_order_path}/files", files, existing_file_keys))

return msg


def _validate_court_order_documents_list(files_path, files, existing_file_keys):
"""Validate the court order documents list."""
msg = []
court_order_document_count = 0
for file_index, file in enumerate(files):
if file.get("documentType") == DocumentType.COURT_ORDER.value:
court_order_document_count += 1

if file.get("fileKey") in existing_file_keys:
continue # don't validate existing file keys

msg.extend(validate_pdf(file.get("fileKey"), f"{files_path}/{file_index}/fileKey"))

if court_order_document_count == 0: # if only supporting documents and no court order documents were found
msg.append({"error": _("At least one Court Order document is required."), "path": files_path})
elif court_order_document_count > 1:
msg.append({"error": _("Only one Court Order document is allowed."), "path": files_path})

return msg

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
"""Test Correction IA validations."""

import uuid
import copy
import datedelta
import pycountry
Expand All @@ -23,7 +24,16 @@

import pytest

from business_model.models import AmalgamatingBusiness, Amalgamation, Business, CourtOrder, PartyRole, Resolution
from business_model.models import (
AmalgamatingBusiness,
Amalgamation,
Business,
CourtOrder,
Document,
DocumentType,
PartyRole,
Resolution
)
from business_common.utils.legislation_datetime import LegislationDatetime
from business_common.utils.datetime import datetime as dt, timedelta
from legal_api.services import NameXService
Expand Down Expand Up @@ -933,6 +943,7 @@ def test_validate_continuation_out_date(session, app, jwt, filing_type, test_nam
'date': '2023-06-19'
}
del filing['filing']['correction']['commentOnly']
del filing['filing']['correction']['nameRequest']

if test_name == 'FAIL_IN_FUTURE':
filing['filing']['correction'][filing_type]['date'] = \
Expand Down Expand Up @@ -984,7 +995,7 @@ def test_validate_continuation_out_foreign_jurisdiction(session, app, jwt, filin
'date': '2023-06-19'
}
del filing['filing']['correction']['commentOnly']

del filing['filing']['correction']['nameRequest']

if test_name == 'FAIL_NO_COUNTRY':
del filing['filing']['correction'][filing_type]['country']
Expand Down Expand Up @@ -1042,6 +1053,7 @@ def test_validate_correction_out_existing_foreign_jurisdiction(mocker, app, sess
'date': '2023-06-19'
}
del filing['filing']['correction']['commentOnly']
del filing['filing']['correction']['nameRequest']

with jwt_request_context(app, jwt, [BASIC_USER]):
err = validate(business, filing)
Expand Down Expand Up @@ -1336,6 +1348,7 @@ def test_validate_invalid_court_order(app, jwt, session, invalid_court_order, er
filing['filing']['header']['identifier'] = identifier
filing['filing']['correction']['correctedFilingId'] = corrected_filing.id
del filing['filing']['correction']['commentOnly']
del filing['filing']['correction']['nameRequest']
filing['filing']['correction']['courtOrder'] = invalid_court_order

with jwt_request_context(app, jwt, [BASIC_USER]):
Expand Down Expand Up @@ -1381,6 +1394,7 @@ def test_validate_invalid_court_orders_new(app, jwt, session, invalid_court_orde
filing['filing']['header']['identifier'] = identifier
filing['filing']['correction']['correctedFilingId'] = ia_filing.id
del filing['filing']['correction']['commentOnly']
del filing['filing']['correction']['nameRequest']
invalid_court_order["filingId"] = ia_filing.id

filing['filing']['correction']['courtOrders'] = [invalid_court_order]
Expand Down Expand Up @@ -1426,6 +1440,7 @@ def test_validate_invalid_court_orders_old(app, jwt, session, invalid_court_orde
filing['filing']['header']['identifier'] = identifier
filing['filing']['correction']['correctedFilingId'] = ia_filing.id
del filing['filing']['correction']['commentOnly']
del filing['filing']['correction']['nameRequest']
invalid_court_order["filingId"] = ia_filing.id
invalid_court_order["id"] = court_order.id

Expand Down Expand Up @@ -1460,6 +1475,7 @@ def test_validate_invalid_court_orders(app, jwt, session, test_name, error_msg):
filing['filing']['header']['identifier'] = identifier
filing['filing']['correction']['correctedFilingId'] = ia_filing.id
del filing['filing']['correction']['commentOnly']
del filing['filing']['correction']['nameRequest']
if test_name == "court_order_not_found":
invalid_court_order["filingId"] = ia_filing.id
invalid_court_order["id"] = 99999999
Expand Down Expand Up @@ -1490,6 +1506,103 @@ def test_validate_invalid_court_orders(app, jwt, session, test_name, error_msg):
assert err.msg[0]['error'] == error_msg


@pytest.mark.parametrize('test_name', [
('no_change'),
('add_new_court_order'),
('replace_existing_court_order')
])
def test_validate_correction_court_order_documents(app, session, jwt, mocker, test_name):
"""Assert the worker process process the court orders correctly."""
identifier = 'BC1234567'
business = factory_business(identifier, entity_type='BC')

ia_filing = factory_completed_filing(business, INCORPORATION_APPLICATION)
court_order_filing = factory_completed_filing(business, COURT_ORDER_FILING_TEMPLATE)

filing = copy.deepcopy(CORRECTION)
filing['filing']['header']['identifier'] = identifier
filing['filing']['correction']['correctedFilingId'] = ia_filing.id
del filing['filing']['correction']['commentOnly']
del filing['filing']['correction']['nameRequest']

file_number = '#1234-5678/90'
new_file_number = '#2222-2222/22'
effect_of_order = 'planOfArrangement'
order_details = 'Court order details'

court_order = CourtOrder(
filing_id=court_order_filing.id,
business_id=business.id,
file_number=file_number,
effect_of_order=effect_of_order,
order_details=order_details
)
court_order.save()

court_order_json = {
"filingId": court_order_filing.id,
"fileNumber": file_number,
"effectOfOrder": effect_of_order,
"orderDetails": order_details,
"id": court_order.id
}
file_key_1 = f"{uuid.uuid4()}.pdf"
file_key_2 = f"{uuid.uuid4()}.pdf"
file_key_3 = f"{uuid.uuid4()}.pdf"
file_name_1 = f'Court Order {file_number}_01.pdf'
file_name_2 = f'Court Order {file_number}_02.pdf'
file_name_3 = f'Court Order {file_number}_03.pdf'
file_1 = {
"fileKey": file_key_1,
"fileName": file_name_1,
"documentType": DocumentType.COURT_ORDER.value
}
file_2 = {
"fileKey": file_key_2,
"fileName": file_name_2,
"documentType": DocumentType.SUPPORTING_DOCUMENT.value
}
file_3 = {
"fileKey": file_key_3,
"fileName": file_name_3,
"documentType": DocumentType.COURT_ORDER.value
}

document = Document()
document.type = file_1.get("documentType")
document.file_key = file_1.get("fileKey")
document.file_name = file_1.get("fileName")
document.filing_id = court_order_filing.id
document.business_id = business.id
document.save()

if test_name == 'add_new_court_order':
court_order_json['files'] = [file_1, file_2]
elif test_name == 'replace_existing_court_order':
court_order_json['files'] = [file_3]
else:
court_order_json['files'] = [file_1]

filing['filing']['correction']['courtOrders'] = [court_order_json]


mock_validate_pdf = mocker.patch('legal_api.services.filings.validations.common_validations.validate_pdf', return_value=[])

with jwt_request_context(app, jwt, [BASIC_USER]):
err = validate(business, filing)
assert not err

if test_name == 'add_new_court_order':
assert len(mock_validate_pdf.call_args_list) == 1
assert mock_validate_pdf.call_args_list[0].args[0] == file_key_2
elif test_name == 'replace_existing_court_order':
assert len(mock_validate_pdf.call_args_list) == 1
assert mock_validate_pdf.call_args_list[0].args[0] == file_key_3
else:
assert len(mock_validate_pdf.call_args_list) == 0



@pytest.mark.parametrize('test_name, err_msg', [
("test_completing_party_staff", "Should not provide completing party when correction type is STAFF"),
("test_multiple_completing_parties", 'Only one completing party is allowed.'),
Expand Down Expand Up @@ -1533,6 +1646,7 @@ def test_validate_correction_relationships_roles(session, app, jwt, test_name, e
filing['filing']['business']['legalType'] = business.legal_type
del filing['filing']['correction']['commentOnly']
del filing['filing']['correction']['parties']
del filing['filing']['correction']['nameRequest']

if test_name == "test_completing_party_staff":
filing['filing']['correction']['type'] = 'STAFF'
Expand Down