Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

23352 update fe filing meta #3212

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import datetime
from typing import Dict

from entity_queue_common.service_utils import logger
from legal_api.models import Filing

from entity_filer.filing_meta import FilingMeta
Expand All @@ -28,16 +29,18 @@ def process(
): # pylint: disable=W0613, R0914
"""Render the notice_of_withdrawal onto the model objects."""
now_filing = filing.get('noticeOfWithdrawal')
filing_meta.notice_of_withdrawal = {}
logger.debug('start notice_of_withdrawal filing process, noticeOfWithdrawal: %s', now_filing)

if court_order := now_filing.get('courtOrder'):
filings.update_filing_court_order(filing_submission, court_order)
filing_meta.notice_of_withdrawal = {**filing_meta.notice_of_withdrawal,
'withdrawnDate': datetime.datetime.utcnow()}

withdrawn_filing_id = now_filing.get('filingId')
withdrawn_filing = Filing.find_by_id(withdrawn_filing_id)
logger.debug('withdrawn_filing_id: %s', withdrawn_filing.id)

withdrawn_filing._status = Filing.Status.WITHDRAWN.value # pylint: disable=protected-access
withdrawn_filing.withdrawal_pending = False
withdrawn_filing_meta_data = withdrawn_filing.meta_data if withdrawn_filing.meta_data else {}
withdrawn_filing._meta_data = {**withdrawn_filing_meta_data, # pylint: disable=protected-access
'withdrawnDate': f'{datetime.datetime.utcnow()}'}
withdrawn_filing.save_to_session()
Original file line number Diff line number Diff line change
Expand Up @@ -13,65 +13,64 @@
# limitations under the License.
"""The Unit Tests for the Notice Of Withdrawal filing."""
import copy
import datetime
import random
import pytest

from legal_api.models import Business, Filing
from registry_schemas.example_data import FILING_HEADER, INCORPORATION, NOTICE_OF_WITHDRAWAL
from legal_api.models import Filing
from legal_api.services import RegistrationBootstrapService
from registry_schemas.example_data import ALTERATION, FILING_HEADER, INCORPORATION, NOTICE_OF_WITHDRAWAL

from entity_filer.filing_meta import FilingMeta
from entity_filer.filing_processors import notice_of_withdrawal
from tests.unit import create_business, create_filing


@pytest.mark.parametrize('test_name, withdrawal_pending,withdrawn_filing_status', [
('Process the Filing', False, False),
('Dont process the Filing', False, True),
('Dont process the Filing', True, False),
('Dont process the Filing', True, True),
@pytest.mark.parametrize('test_name,filing_type,filing_template,identifier', [
('IA Withdrawn Filing', 'incorporationApplication', INCORPORATION, 'TJO4XI2qMo'),
('alteration Withdrawn Filing', 'alteration', ALTERATION, 'BC1234567')
])
def test_worker_notice_of_withdrawal(session, test_name, withdrawal_pending, withdrawn_filing_status):
def test_worker_notice_of_withdrawal(session, test_name, filing_type, filing_template, identifier):
"""Assert that the notice of withdrawal filing processes correctly."""
# Setup
identifier = 'BC1234567'
business = create_business(identifier, legal_type='BC')
payment_id = str(random.SystemRandom().getrandbits(0x58))

# Create IA filing
ia_filing_json = copy.deepcopy(FILING_HEADER)
ia_filing_json['filing']['business']['identifier'] = identifier
ia_filing_json['filing']['incorporationApplication'] = copy.deepcopy(INCORPORATION)
ia_filing = create_filing(payment_id, ia_filing_json, business_id=business.id)
ia_filing.withdrawal_pending = withdrawal_pending
if withdrawn_filing_status:
ia_filing._status = Filing.Status.WITHDRAWN.value
# Create withdrawn_filing
withdrawn_filing_json = copy.deepcopy(FILING_HEADER)
withdrawn_filing_json['filing']['business']['legalType'] = 'BC'
withdrawn_filing_json['filing']['business']['identifier'] = identifier
withdrawn_filing_json['filing'][filing_type] = copy.deepcopy(filing_template)
if identifier.startswith('T'):
business = RegistrationBootstrapService.create_bootstrap(account=28)
withdrawn_filing = create_filing(payment_id, withdrawn_filing_json, bootstrap_id=business.identifier)
else:
ia_filing._status = 'PENDING'
ia_filing.skip_status_listener = True
ia_filing.save()
business = create_business(identifier, legal_type='BC')
withdrawn_filing = create_filing(payment_id, withdrawn_filing_json, business_id=business.id)
withdrawn_filing.payment_completion_date = datetime.datetime.utcnow() # for setting the filing status PAID
withdrawn_filing._meta_data = {}
withdrawn_filing.save()

# Create NoW filing
now_filing_json = copy.deepcopy(FILING_HEADER)
now_filing_json['filing']['business']['identifier'] = identifier
now_filing_json['filing']['business']['identifier'] = business.identifier
now_filing_json['filing']['noticeOfWithdrawal'] = copy.deepcopy(NOTICE_OF_WITHDRAWAL)
now_filing_json['filing']['noticeOfWithdrawal']['filingId'] = ia_filing.id
now_filing = create_filing(payment_id, now_filing_json, business_id=business.id)
now_filing.withdrawn_filing_id = ia_filing.id
now_filing_json['filing']['noticeOfWithdrawal']['filingId'] = withdrawn_filing.id
now_filing = create_filing(payment_id, now_filing_json)
now_filing.withdrawn_filing_id = withdrawn_filing.id
now_filing.save()

filing_meta = FilingMeta()


assert withdrawn_filing.status == Filing.Status.PAID.value

# Test
notice_of_withdrawal.process(now_filing, now_filing_json['filing'], filing_meta)
business.save()
withdrawn_filing.save()

# Check results
final_ia_filing = Filing.find_by_id(ia_filing.id)
final_withdrawn_filing = Filing.find_by_id(withdrawn_filing.id)
final_now_filing = Filing.find_by_id(now_filing.id)

assert now_filing_json['filing']['noticeOfWithdrawal']['courtOrder']['orderDetails'] == final_now_filing.order_details
if withdrawal_pending or withdrawn_filing_status:
assert final_ia_filing.status == ia_filing.status
assert final_ia_filing.withdrawal_pending == ia_filing.withdrawal_pending
else:
assert final_ia_filing.status == Filing.Status.WITHDRAWN.value
assert final_ia_filing.withdrawal_pending == False
assert final_withdrawn_filing.status == Filing.Status.WITHDRAWN.value
assert final_withdrawn_filing.withdrawal_pending == False
assert final_withdrawn_filing.meta_data.get('withdrawnDate')
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"""The Test Suites to ensure that the worker is operating correctly."""
import copy
import datetime
from datetime import timezone
from http import HTTPStatus
import random
from unittest.mock import patch

Expand All @@ -26,12 +28,14 @@
from registry_schemas.example_data import (
ANNUAL_REPORT,
CHANGE_OF_ADDRESS,
CONTINUATION_IN_FILING_TEMPLATE,
CORRECTION_AR,
FILING_HEADER,
INCORPORATION_FILING_TEMPLATE,
)

from entity_filer.filing_processors.filing_components import create_party, create_role
from entity_queue_common.service_utils import QueueException
from entity_filer.filing_processors.filing_components import business_info, business_profile, create_party, create_role
from entity_filer.worker import process_filing
from tests.unit import (
COD_FILING,
Expand Down Expand Up @@ -467,3 +471,42 @@ async def test_publish_event():
}

mock_publish.publish.assert_called_with('entity.events', payload)


@pytest.mark.parametrize('test_name,withdrawal_pending,filing_status', [
('Process the Filing', False, 'PAID'),
('Dont process the Filing', False, 'WITHDRAWN'),
('Dont process the Filing', True, 'PAID'),
('Dont process the Filing', True, 'WITHDRAWN'),
])
async def test_process_filing_completed(app, session, mocker, test_name, withdrawal_pending, filing_status):
"""Assert that an filling can be processed."""
# vars
filing_type = 'continuationIn'
nr_identifier = 'NR 1234567'
next_corp_num = 'C0001095'

filing = copy.deepcopy(CONTINUATION_IN_FILING_TEMPLATE)
filing['filing'][filing_type]['nameRequest']['nrNumber'] = nr_identifier
filing['filing'][filing_type]['nameTranslations'] = [{'name': 'ABCD Ltd.'}]
filing_rec = create_filing('123', filing)
effective_date = datetime.datetime.now(timezone.utc)
filing_rec.effective_date = effective_date
filing_rec._status = filing_status
filing_rec.withdrawal_pending = withdrawal_pending
filing_rec.save()

# test
filing_msg = {'filing': {'id': filing_rec.id}}

with patch.object(business_info, 'get_next_corp_num', return_value=next_corp_num):
with patch.object(business_profile, 'update_business_profile', return_value=HTTPStatus.OK):
if withdrawal_pending and filing_status != 'WITHDRAWN':
with pytest.raises(QueueException):
await process_filing(filing_msg, app)
else:
await process_filing(filing_msg, app)

business = Business.find_by_identifier(next_corp_num)
if not withdrawal_pending and filing_status == 'PAID':
assert business.state == Business.State.ACTIVE