|
15 | 15 |
|
16 | 16 | import copy |
17 | 17 | import datedelta |
| 18 | +import pycountry |
18 | 19 | from datetime import datetime, timezone |
19 | 20 | from freezegun import freeze_time |
20 | 21 | from http import HTTPStatus |
|
23 | 24 | import pytest |
24 | 25 |
|
25 | 26 | from business_model.models import Business, Resolution |
| 27 | +from business_common.utils.legislation_datetime import LegislationDatetime |
26 | 28 | from business_common.utils.datetime import datetime as dt, timedelta |
27 | 29 | from legal_api.services import NameXService |
28 | 30 | from legal_api.services.authz import BASIC_USER, STAFF_ROLE |
29 | 31 | from legal_api.services.filings import validate |
30 | 32 | from registry_schemas.example_data import ( |
31 | | - CORRECTION_INCORPORATION, |
| 33 | + AMALGAMATION_OUT, |
| 34 | + CORRECTION_INCORPORATION, |
32 | 35 | CONTINUATION_IN_FILING_TEMPLATE, |
| 36 | + CONTINUATION_OUT, |
| 37 | + FILING_HEADER, |
33 | 38 | INCORPORATION_FILING_TEMPLATE |
34 | 39 | ) |
35 | 40 |
|
|
39 | 44 | from tests.unit.services.utils import jwt_request_context |
40 | 45 |
|
41 | 46 |
|
| 47 | +date_format = '%Y-%m-%d' |
42 | 48 | INCORPORATION_APPLICATION = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) |
43 | 49 | CORRECTION = copy.deepcopy(CORRECTION_INCORPORATION) |
44 | 50 |
|
@@ -808,3 +814,108 @@ def test_validate_continuation_in_xpro_founding_date_match(mocker, app, session, |
808 | 814 | err = validate(business, filing) |
809 | 815 | assert not err |
810 | 816 |
|
| 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