forked from bcgov/lear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hongjing Chen <[email protected]>
- Loading branch information
1 parent
8c53fdc
commit a231a2c
Showing
6 changed files
with
194 additions
and
5 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
68 changes: 68 additions & 0 deletions
68
jobs/furnishings/src/furnishings/stage_processors/stage_two.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,68 @@ | ||
# 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 two 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 two process.""" | ||
try: | ||
furnishing_subquery = exists().where( | ||
Furnishing.batch_id == BatchProcessing.batch_id, | ||
Furnishing.business_id == BatchProcessing.business_id, | ||
Furnishing.furnishing_name.in_([ | ||
Furnishing.FurnishingName.INTENT_TO_DISSOLVE, | ||
Furnishing.FurnishingName.INTENT_TO_DISSOLVE_XPRO | ||
]) | ||
) | ||
batch_processings = ( | ||
db.session.query(BatchProcessing) | ||
.filter(BatchProcessing.status == BatchProcessing.BatchProcessingStatus.PROCESSING) | ||
.filter(BatchProcessing.step == BatchProcessing.BatchProcessingStep.WARNING_LEVEL_2) | ||
.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.INTENT_TO_DISSOLVE_XPRO | ||
if business.legal_type == Business.LegalTypes.EXTRA_PRO_A.value | ||
else Furnishing.FurnishingName.INTENT_TO_DISSOLVE | ||
) | ||
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 | ||
) | ||
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
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
97 changes: 97 additions & 0 deletions
97
jobs/furnishings/tests/unit/stage_processors/test_stage_two.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,97 @@ | ||
# 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 two 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_two 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.WARNING_LEVEL_2, | ||
True | ||
), | ||
( | ||
'XPRO_NEW_FURNISHING', | ||
Business.LegalTypes.EXTRA_PRO_A.value, | ||
BatchProcessing.BatchProcessingStep.WARNING_LEVEL_2, | ||
True | ||
), | ||
( | ||
'STAGE_2_ALREADY_RUN', | ||
Business.LegalTypes.COMP.value, | ||
BatchProcessing.BatchProcessingStep.WARNING_LEVEL_2, | ||
False | ||
), | ||
( | ||
'NOT_IN_STAGE_2', | ||
Business.LegalTypes.COMP.value, | ||
BatchProcessing.BatchProcessingStep.WARNING_LEVEL_1, | ||
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_2_ALREADY_RUN': | ||
existing_furnishing = factory_furnishing( | ||
batch_id=batch.id, | ||
business_id=business.id, | ||
identifier=business.identifier, | ||
furnishing_name=Furnishing.FurnishingName.INTENT_TO_DISSOLVE, | ||
furnishing_type=Furnishing.FurnishingType.GAZETTE, | ||
created_date=datetime.utcnow()+datedelta(years=1), | ||
last_modified=datetime.utcnow()+datedelta(years=1) | ||
) | ||
|
||
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 | ||
if entity_type == Business.LegalTypes.EXTRA_PRO_A.value: | ||
assert furnishing.furnishing_name == Furnishing.FurnishingName.INTENT_TO_DISSOLVE_XPRO | ||
else: | ||
assert furnishing.furnishing_name == Furnishing.FurnishingName.INTENT_TO_DISSOLVE | ||
else: | ||
if test_name == 'STAGE_2_ALREADY_RUN': | ||
assert len(furnishings) == 1 | ||
furnishing = furnishings[0] | ||
assert furnishing == existing_furnishing | ||
else: | ||
assert len(furnishings) == 0 |