|
13 | 13 | # limitations under the License. |
14 | 14 | """Test Correction IA validations.""" |
15 | 15 |
|
| 16 | +import uuid |
16 | 17 | import copy |
17 | 18 | import datedelta |
18 | 19 | import pycountry |
|
23 | 24 |
|
24 | 25 | import pytest |
25 | 26 |
|
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 | +) |
27 | 37 | from business_common.utils.legislation_datetime import LegislationDatetime |
28 | 38 | from business_common.utils.datetime import datetime as dt, timedelta |
29 | 39 | from legal_api.services import NameXService |
@@ -933,6 +943,7 @@ def test_validate_continuation_out_date(session, app, jwt, filing_type, test_nam |
933 | 943 | 'date': '2023-06-19' |
934 | 944 | } |
935 | 945 | del filing['filing']['correction']['commentOnly'] |
| 946 | + del filing['filing']['correction']['nameRequest'] |
936 | 947 |
|
937 | 948 | if test_name == 'FAIL_IN_FUTURE': |
938 | 949 | filing['filing']['correction'][filing_type]['date'] = \ |
@@ -984,7 +995,7 @@ def test_validate_continuation_out_foreign_jurisdiction(session, app, jwt, filin |
984 | 995 | 'date': '2023-06-19' |
985 | 996 | } |
986 | 997 | del filing['filing']['correction']['commentOnly'] |
987 | | - |
| 998 | + del filing['filing']['correction']['nameRequest'] |
988 | 999 |
|
989 | 1000 | if test_name == 'FAIL_NO_COUNTRY': |
990 | 1001 | del filing['filing']['correction'][filing_type]['country'] |
@@ -1042,6 +1053,7 @@ def test_validate_correction_out_existing_foreign_jurisdiction(mocker, app, sess |
1042 | 1053 | 'date': '2023-06-19' |
1043 | 1054 | } |
1044 | 1055 | del filing['filing']['correction']['commentOnly'] |
| 1056 | + del filing['filing']['correction']['nameRequest'] |
1045 | 1057 |
|
1046 | 1058 | with jwt_request_context(app, jwt, [BASIC_USER]): |
1047 | 1059 | err = validate(business, filing) |
@@ -1336,6 +1348,7 @@ def test_validate_invalid_court_order(app, jwt, session, invalid_court_order, er |
1336 | 1348 | filing['filing']['header']['identifier'] = identifier |
1337 | 1349 | filing['filing']['correction']['correctedFilingId'] = corrected_filing.id |
1338 | 1350 | del filing['filing']['correction']['commentOnly'] |
| 1351 | + del filing['filing']['correction']['nameRequest'] |
1339 | 1352 | filing['filing']['correction']['courtOrder'] = invalid_court_order |
1340 | 1353 |
|
1341 | 1354 | 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 |
1381 | 1394 | filing['filing']['header']['identifier'] = identifier |
1382 | 1395 | filing['filing']['correction']['correctedFilingId'] = ia_filing.id |
1383 | 1396 | del filing['filing']['correction']['commentOnly'] |
| 1397 | + del filing['filing']['correction']['nameRequest'] |
1384 | 1398 | invalid_court_order["filingId"] = ia_filing.id |
1385 | 1399 |
|
1386 | 1400 | filing['filing']['correction']['courtOrders'] = [invalid_court_order] |
@@ -1426,6 +1440,7 @@ def test_validate_invalid_court_orders_old(app, jwt, session, invalid_court_orde |
1426 | 1440 | filing['filing']['header']['identifier'] = identifier |
1427 | 1441 | filing['filing']['correction']['correctedFilingId'] = ia_filing.id |
1428 | 1442 | del filing['filing']['correction']['commentOnly'] |
| 1443 | + del filing['filing']['correction']['nameRequest'] |
1429 | 1444 | invalid_court_order["filingId"] = ia_filing.id |
1430 | 1445 | invalid_court_order["id"] = court_order.id |
1431 | 1446 |
|
@@ -1460,6 +1475,7 @@ def test_validate_invalid_court_orders(app, jwt, session, test_name, error_msg): |
1460 | 1475 | filing['filing']['header']['identifier'] = identifier |
1461 | 1476 | filing['filing']['correction']['correctedFilingId'] = ia_filing.id |
1462 | 1477 | del filing['filing']['correction']['commentOnly'] |
| 1478 | + del filing['filing']['correction']['nameRequest'] |
1463 | 1479 | if test_name == "court_order_not_found": |
1464 | 1480 | invalid_court_order["filingId"] = ia_filing.id |
1465 | 1481 | invalid_court_order["id"] = 99999999 |
@@ -1490,6 +1506,103 @@ def test_validate_invalid_court_orders(app, jwt, session, test_name, error_msg): |
1490 | 1506 | assert err.msg[0]['error'] == error_msg |
1491 | 1507 |
|
1492 | 1508 |
|
| 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 | + |
1493 | 1606 | @pytest.mark.parametrize('test_name, err_msg', [ |
1494 | 1607 | ("test_completing_party_staff", "Should not provide completing party when correction type is STAFF"), |
1495 | 1608 | ("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 |
1533 | 1646 | filing['filing']['business']['legalType'] = business.legal_type |
1534 | 1647 | del filing['filing']['correction']['commentOnly'] |
1535 | 1648 | del filing['filing']['correction']['parties'] |
| 1649 | + del filing['filing']['correction']['nameRequest'] |
1536 | 1650 |
|
1537 | 1651 | if test_name == "test_completing_party_staff": |
1538 | 1652 | filing['filing']['correction']['type'] = 'STAFF' |
|
0 commit comments