|
| 1 | +# Copyright © 2026 Province of British Columbia |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +"""Tests for Filing._process_amalgamating_businesses entry classification.""" |
| 15 | +from unittest.mock import MagicMock |
| 16 | + |
| 17 | +from colin_api.models import Business |
| 18 | +from colin_api.models.corp_involved import CorpInvolved |
| 19 | +from colin_api.models.filing import Filing |
| 20 | + |
| 21 | + |
| 22 | +def _process(mocker, amalgamating_businesses): |
| 23 | + """Run _process_amalgamating_businesses over the entries; return (corp_involved rows, state updates).""" |
| 24 | + created = [] |
| 25 | + mocker.patch.object(CorpInvolved, 'create_corp_involved', side_effect=lambda _cursor, obj: created.append(obj)) |
| 26 | + update_corp_state = mocker.patch.object(Business, 'update_corp_state') |
| 27 | + |
| 28 | + filing = Filing() |
| 29 | + filing.event_id = 1234567 |
| 30 | + filing.body = {'amalgamatingBusinesses': amalgamating_businesses} |
| 31 | + Filing._process_amalgamating_businesses(MagicMock(), filing) # pylint: disable=protected-access |
| 32 | + |
| 33 | + return created, update_corp_state |
| 34 | + |
| 35 | + |
| 36 | +def test_identifier_entry_bc_corp(mocker): |
| 37 | + """Assert a BC identifier entry is HAM'd under its bare corp num.""" |
| 38 | + created, update_corp_state = _process(mocker, [ |
| 39 | + {'role': 'amalgamating', 'identifier': 'BC0870226'} |
| 40 | + ]) |
| 41 | + |
| 42 | + assert len(created) == 1 |
| 43 | + assert created[0].corp_num == '0870226' |
| 44 | + assert created[0].home_juri_num is None |
| 45 | + assert created[0].adopted_corp_ind is None |
| 46 | + update_corp_state.assert_called_once() |
| 47 | + assert update_corp_state.call_args.args[2] == '0870226' |
| 48 | + assert update_corp_state.call_args.args[3] == Business.CorpStateTypes.AMALGAMATED.value |
| 49 | + |
| 50 | + |
| 51 | +def test_identifier_entry_expro(mocker): |
| 52 | + """Assert an identifier-only extraprovincial (A) entry is HAM'd under its full identifier.""" |
| 53 | + created, update_corp_state = _process(mocker, [ |
| 54 | + {'role': 'amalgamating', 'identifier': 'A0077777'} |
| 55 | + ]) |
| 56 | + |
| 57 | + assert len(created) == 1 |
| 58 | + assert created[0].corp_num == 'A0077777' |
| 59 | + assert created[0].home_juri_num is None |
| 60 | + assert created[0].foreign_nme is None |
| 61 | + update_corp_state.assert_called_once() |
| 62 | + assert update_corp_state.call_args.args[2] == 'A0077777' |
| 63 | + assert update_corp_state.call_args.args[3] == Business.CorpStateTypes.AMALGAMATED.value |
| 64 | + |
| 65 | + |
| 66 | +def test_holding_entry_marks_adopted(mocker): |
| 67 | + """Assert a holding/primary identifier entry sets the adopted corp indicator.""" |
| 68 | + created, _ = _process(mocker, [ |
| 69 | + {'role': 'holding', 'identifier': 'BC0870226'} |
| 70 | + ]) |
| 71 | + |
| 72 | + assert created[0].adopted_corp_ind == 'Y' |
| 73 | + |
| 74 | + |
| 75 | +def test_foreign_entry(mocker): |
| 76 | + """Assert a true foreign entry records home jurisdiction data and no corp state change.""" |
| 77 | + created, update_corp_state = _process(mocker, [ |
| 78 | + { |
| 79 | + 'role': 'amalgamating', |
| 80 | + 'identifier': 'AB-1234567', |
| 81 | + 'legalName': 'FOREIGN CO.', |
| 82 | + 'foreignJurisdiction': {'country': 'CA', 'region': 'AB'} |
| 83 | + } |
| 84 | + ]) |
| 85 | + |
| 86 | + assert len(created) == 1 |
| 87 | + assert created[0].corp_num is None |
| 88 | + assert created[0].home_juri_num == 'AB-1234567' |
| 89 | + assert created[0].foreign_nme == 'FOREIGN CO.' |
| 90 | + assert created[0].can_jur_typ_cd == 'AB' |
| 91 | + update_corp_state.assert_not_called() |
| 92 | + |
| 93 | + |
| 94 | +def test_foreign_federal_and_international_entries(mocker): |
| 95 | + """Assert federal and non-Canadian foreign entries map their jurisdiction codes.""" |
| 96 | + created, _ = _process(mocker, [ |
| 97 | + { |
| 98 | + 'role': 'amalgamating', |
| 99 | + 'identifier': '7654321', |
| 100 | + 'legalName': 'FEDERAL CO.', |
| 101 | + 'foreignJurisdiction': {'country': 'CA', 'region': 'FEDERAL'} |
| 102 | + }, |
| 103 | + { |
| 104 | + 'role': 'amalgamating', |
| 105 | + 'identifier': 'US-1', |
| 106 | + 'legalName': 'US CO.', |
| 107 | + 'foreignJurisdiction': {'country': 'US', 'region': 'DE'} |
| 108 | + } |
| 109 | + ]) |
| 110 | + |
| 111 | + assert created[0].can_jur_typ_cd == 'FD' |
| 112 | + assert created[1].can_jur_typ_cd == 'OT' |
| 113 | + assert created[1].othr_juri_desc == 'US, DE' |
0 commit comments