-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
21952 Furnishings job - Implement stage three (#2833)
* Implement stage three * Add business name * Save new furnishing properly
- Loading branch information
1 parent
a628d79
commit 271c9f3
Showing
5 changed files
with
172 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
jobs/furnishings/src/furnishings/stage_processors/stage_three.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Copyright © 2024 Province of British Columbia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Furnishings job procssing rules for stage three of involuntary dissolution.""" | ||
from datetime import datetime | ||
|
||
from flask import Flask | ||
from legal_api.models import Batch, BatchProcessing, Business, Furnishing, db | ||
from sqlalchemy import exists, not_ | ||
|
||
|
||
def process(app: Flask): | ||
"""Run process to manage and track notifications for dissolution stage three process.""" | ||
try: | ||
furnishing_subquery = exists().where( | ||
Furnishing.batch_id == BatchProcessing.batch_id, | ||
Furnishing.business_id == BatchProcessing.business_id, | ||
Furnishing.furnishing_name.in_([ | ||
Furnishing.FurnishingName.CORP_DISSOLVED, | ||
Furnishing.FurnishingName.CORP_DISSOLVED_XPRO | ||
]) | ||
) | ||
batch_processings = ( | ||
db.session.query(BatchProcessing) | ||
.filter(BatchProcessing.status == BatchProcessing.BatchProcessingStatus.PROCESSING) | ||
.filter(BatchProcessing.step == BatchProcessing.BatchProcessingStep.DISSOLUTION) | ||
.filter(Batch.id == BatchProcessing.batch_id) | ||
.filter(Batch.batch_type == Batch.BatchType.INVOLUNTARY_DISSOLUTION) | ||
.filter(Batch.status == Batch.BatchStatus.PROCESSING) | ||
.filter(not_(furnishing_subquery)) | ||
).all() | ||
|
||
grouping_identifier = Furnishing.get_next_grouping_identifier() | ||
|
||
for batch_processing in batch_processings: | ||
business = batch_processing.business | ||
furnishing_name = ( | ||
Furnishing.FurnishingName.CORP_DISSOLVED_XPRO | ||
if business.legal_type == Business.LegalTypes.EXTRA_PRO_A.value | ||
else Furnishing.FurnishingName.CORP_DISSOLVED | ||
) | ||
new_furnishing = Furnishing( | ||
furnishing_type=Furnishing.FurnishingType.GAZETTE, | ||
furnishing_name=furnishing_name, | ||
batch_id=batch_processing.batch_id, | ||
business_id=batch_processing.business_id, | ||
business_identifier=batch_processing.business_identifier, | ||
created_date=datetime.utcnow(), | ||
last_modified=datetime.utcnow(), | ||
status=Furnishing.FurnishingStatus.QUEUED, | ||
grouping_identifier=grouping_identifier, | ||
business_name=business.legal_name | ||
) | ||
new_furnishing.save() | ||
# TODO: create data files and SFTPing to BC Laws | ||
# TODO: mark furnishings entry processed | ||
|
||
except Exception as err: | ||
app.logger.error(err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
jobs/furnishings/tests/unit/stage_processors/test_stage_three.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Copyright © 2024 Province of British Columbia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Tests for the Furnishings Job. | ||
Test suite to ensure that the Furnishings Job stage three is working as expected. | ||
""" | ||
from datetime import datetime | ||
|
||
import pytest | ||
from datedelta import datedelta | ||
from legal_api.models import BatchProcessing, Business, Furnishing | ||
|
||
from furnishings.stage_processors.stage_three import process | ||
|
||
from .. import factory_batch, factory_batch_processing, factory_business, factory_furnishing | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'test_name, entity_type, step, new_entry', [ | ||
( | ||
'BC_NEW_FURNISHING', | ||
Business.LegalTypes.COMP.value, | ||
BatchProcessing.BatchProcessingStep.DISSOLUTION, | ||
True | ||
), | ||
( | ||
'XPRO_NEW_FURNISHING', | ||
Business.LegalTypes.EXTRA_PRO_A.value, | ||
BatchProcessing.BatchProcessingStep.DISSOLUTION, | ||
True | ||
), | ||
( | ||
'STAGE_3_ALREADY_RUN', | ||
Business.LegalTypes.COMP.value, | ||
BatchProcessing.BatchProcessingStep.DISSOLUTION, | ||
False | ||
), | ||
( | ||
'NOT_IN_STAGE_3', | ||
Business.LegalTypes.COMP.value, | ||
BatchProcessing.BatchProcessingStep.WARNING_LEVEL_2, | ||
False | ||
) | ||
] | ||
) | ||
def test_process_create_furnishings(app, session, test_name, entity_type, step, new_entry): | ||
"""Assert that new furnishing entries are created correctly.""" | ||
business = factory_business(identifier='BC1234567', entity_type=entity_type) | ||
batch = factory_batch() | ||
factory_batch_processing( | ||
batch_id=batch.id, | ||
business_id=business.id, | ||
identifier=business.identifier, | ||
step=step | ||
) | ||
|
||
if test_name == 'STAGE_3_ALREADY_RUN': | ||
existing_furnishing = factory_furnishing( | ||
batch_id=batch.id, | ||
business_id=business.id, | ||
identifier=business.identifier, | ||
furnishing_name=Furnishing.FurnishingName.CORP_DISSOLVED, | ||
furnishing_type=Furnishing.FurnishingType.GAZETTE, | ||
created_date=datetime.utcnow()+datedelta(years=1), | ||
last_modified=datetime.utcnow()+datedelta(years=1), | ||
business_name=business.legal_name | ||
) | ||
|
||
process(app) | ||
|
||
furnishings = Furnishing.find_by(business_id=business.id) | ||
if new_entry: | ||
assert len(furnishings) == 1 | ||
furnishing = furnishings[0] | ||
assert furnishing.furnishing_type == Furnishing.FurnishingType.GAZETTE | ||
assert furnishing.business_name == business.legal_name | ||
if entity_type == Business.LegalTypes.EXTRA_PRO_A.value: | ||
assert furnishing.furnishing_name == Furnishing.FurnishingName.CORP_DISSOLVED_XPRO | ||
else: | ||
assert furnishing.furnishing_name == Furnishing.FurnishingName.CORP_DISSOLVED | ||
else: | ||
if test_name == 'STAGE_3_ALREADY_RUN': | ||
assert len(furnishings) == 1 | ||
furnishing = furnishings[0] | ||
assert furnishing == existing_furnishing | ||
else: | ||
assert len(furnishings) == 0 |