Skip to content

Commit

Permalink
21952 Furnishings job - Implement stage three (#2833)
Browse files Browse the repository at this point in the history
* Implement stage three

* Add business name

* Save new furnishing properly
  • Loading branch information
leodube-aot authored Jul 18, 2024
1 parent a628d79 commit 271c9f3
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ async def _send_first_round_notification(self, batch_processing: BatchProcessing
# TODO: send AR and transition pdf to BCMail+
new_furnishing.status = Furnishing.FurnishingStatus.PROCESSED
new_furnishing.processed_date = datetime.utcnow()
new_furnishing.save()

async def _send_second_round_notification(self, batch_processing: BatchProcessing):
"""Send paper letter if business is still not in good standing after 5 days of email letter sent out."""
Expand Down Expand Up @@ -142,6 +143,7 @@ async def _send_second_round_notification(self, batch_processing: BatchProcessin
# TODO: send AR and transition pdf to BCMail+
new_furnishing.status = Furnishing.FurnishingStatus.PROCESSED
new_furnishing.processed_date = datetime.utcnow()
new_furnishing.save()

def _create_new_furnishing( # pylint: disable=too-many-arguments
self,
Expand Down
69 changes: 69 additions & 0 deletions jobs/furnishings/src/furnishings/stage_processors/stage_three.py
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)
4 changes: 2 additions & 2 deletions jobs/furnishings/src/furnishings/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from sentry_sdk.integrations.logging import LoggingIntegration

from furnishings.config import get_named_config # pylint: disable=import-error
from furnishings.stage_processors import stage_one, stage_two
from furnishings.stage_processors import stage_one, stage_three, stage_two
from furnishings.utils.logging import setup_logging # pylint: disable=import-error


Expand Down Expand Up @@ -119,4 +119,4 @@ async def run(application: Flask, qsm: QueueService): # pylint: disable=redefin
if stage_2_valid:
stage_two.process(application)
if stage_3_valid:
pass
stage_three.process(application)
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ async def test_process_first_notification(app, session, test_name, entity_type,
@pytest.mark.asyncio
@pytest.mark.parametrize(
'test_name, has_email_furnishing, has_mail_furnishing, is_email_elapsed', [
(
'NO_EMAIL_FURNISHING',
False,
False,
False
),
(
'EMAIL_FURNISHING_NOT_ELAPSED',
True,
Expand Down
99 changes: 99 additions & 0 deletions jobs/furnishings/tests/unit/stage_processors/test_stage_three.py
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

0 comments on commit 271c9f3

Please sign in to comment.