Skip to content
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
1 change: 1 addition & 0 deletions queue_services/business-filer/devops/vaults.gcp.env
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ SUB_SERVICE_ACCOUNT="op://gcp-queue/$APP_ENV/a083gt/BUSINESS_SERVICE_ACCOUNT"
BUSINESS_EVENTS_TOPIC="op://gcp-queue/$APP_ENV/topics/BUSINESS_EVENTS_TOPIC"
BUSINESS_MAILER_TOPIC="op://gcp-queue/$APP_ENV/topics/BUSINESS_EMAILER_TOPIC"
BUSINESS_PAY_TOPIC="op://gcp-queue/$APP_ENV/topics/BUSINESS_PAY_TOPIC"
DOC_CREATE_REC_TOPIC="op://gcp-queue/$APP_ENV/topics/DOC_CREATE_REC_TOPIC"
NAMEX_PAY_TOPIC="op://gcp-queue/$APP_ENV/topics/NAMEX_PAY_TOPIC"
VPC_CONNECTOR="op://CD/$APP_ENV/base/VPC_CONNECTOR"

Expand Down
145 changes: 135 additions & 10 deletions queue_services/business-filer/poetry.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions queue_services/business-filer/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
]
license = {text = "BSD-3-Clause"}
readme = "README.md"
requires-python = ">=3.13,<4"
requires-python = ">=3.13,<3.14"

dependencies = [
"business-model @ git+https://github.com/bcgov/lear.git@main#subdirectory=python/common/business-registry-model",
Expand All @@ -22,7 +22,8 @@ dependencies = [
"pg8000 (>=1.31.2,<2.0.0)",
# "business-model @ file:///Users/thor/Developer/thorwolpert/ServiceBC/GCP/lear/python/common/business-registry-model",
"gunicorn (>=23.0.0,<24.0.0)",
"business-registry-account @ git+https://github.com/bcgov/lear.git@main#subdirectory=python/common/business-registry-account"
"business-registry-account @ git+https://github.com/bcgov/lear.git@main#subdirectory=python/common/business-registry-account",
"pytest-cov (>=7.0.0,<8.0.0)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this to dev dependencies


]

Expand Down Expand Up @@ -143,7 +144,7 @@ minversion = "2.0"
testpaths = [
"tests",
]
## addopts = "--verbose --strict -p no:warnings --cov=src --cov-report html:htmlcov --cov-report xml:coverage.xml"
addopts = "--cov=src/business_filer"
python_files = [
"test*.py"
]
Expand Down
4 changes: 4 additions & 0 deletions queue_services/business-filer/src/business_filer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class _Config: # pylint: disable=too-few-public-methods
BUSINESS_EVENTS_TOPIC = os.getenv("BUSINESS_EVENTS_TOPIC", "business-event-dev")
BUSINESS_MAILER_TOPIC = os.getenv("BUSINESS_MAILER_TOPIC", "business-mailer-dev")
BUSINESS_PAY_TOPIC = os.getenv("BUSINESS_PAY_TOPIC", "business-pay-dev")
DOC_CREATE_REC_TOPIC = os.getenv("DOC_CREATE_REC_TOPIC")
NAMEX_PAY_TOPIC = os.getenv("NAMEX_PAY_TOPIC", "namex-pay-dev")
SUB_AUDIENCE = os.getenv("SUB_AUDIENCE", "")
SUB_SERVICE_ACCOUNT = os.getenv("SUB_SERVICE_ACCOUNT", "")
Expand Down Expand Up @@ -117,6 +118,9 @@ class TestConfig(_Config): # pylint: disable=too-few-public-methods

SUB_AUDIENCE = os.getenv("SUB_AUDIENCE", "test@test.test")
SUB_SERVICE_ACCOUNT = os.getenv("SUB_SERVICE_ACCOUNT", "test@test.test")

# Faked out publishing
DOC_CREATE_REC_TOPIC = os.getenv("TEST_DOC_CREATE_REC_TOPIC", "fake-doc-create-rec-topic")


class ProdConfig(_Config): # pylint: disable=too-few-public-methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import copy

from business_model.models import Business, Filing, PartyRole
from flask import current_app

from business_filer.filing_meta import FilingMeta
from business_filer.filing_processors.filing_components.filings import update_filing_court_order
Expand All @@ -44,6 +45,7 @@
create_relationships,
update_relationship_addresses,
)
from business_filer.services.publish_event import PublishEvent


def process(business: Business, filing_rec: Filing, filing_meta: FilingMeta):
Expand Down Expand Up @@ -75,4 +77,10 @@ def process(business: Business, filing_rec: Filing, filing_meta: FilingMeta):
if court_order := filing_json["filing"]["changeOfLiquidators"].get("courtOrder"):
update_filing_court_order(filing_rec, court_order)

# FUTURE: DRS integration with document id
try:
# Create DRS record
PublishEvent.publish_drs_create_message(current_app, business, filing_rec)
except Exception as err:
# log error for ops, but don't prevent filing from completing
current_app.logger.warning(err.with_traceback(None))
current_app.logger.warning(f"Failed to create DRS Record for {filing_rec.id}.")
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import copy

from business_model.models import Business, Filing, PartyRole
from flask import current_app

from business_filer.filing_meta import FilingMeta
from business_filer.filing_processors.filing_components.filings import update_filing_court_order
Expand All @@ -44,6 +45,7 @@
update_relationship_addresses,
update_relationship_entity_info,
)
from business_filer.services.publish_event import PublishEvent


def process(business: Business, filing_rec: Filing, filing_meta: FilingMeta):
Expand All @@ -69,4 +71,11 @@ def process(business: Business, filing_rec: Filing, filing_meta: FilingMeta):
if court_order := filing_json["filing"]["changeOfReceivers"].get("courtOrder"):
update_filing_court_order(filing_rec, court_order)

# FUTURE: DRS integration with document id
try:
# Create DRS record
PublishEvent.publish_drs_create_message(current_app, business, filing_rec)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its better to move this after commit, that's what we follow in filer for other messages https://github.com/bcgov/lear/blob/main/queue_services/business-filer/src/business_filer/services/filer.py#L277

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that makes sense - will do


except Exception as err:
# log error for ops, but don't prevent filing from completing
current_app.logger.warning(err.with_traceback(None))
current_app.logger.warning(f"Failed to create DRS Record for {filing_rec.id}.")
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ def publish_event(app: Flask, business: Business, filing: Filing):

except Exception as err: # pylint: disable=broad-except;
raise PublishException(err) from err

@staticmethod
def publish_drs_create_message(app: Flask, business: Business, filing: Filing):
"""Publish the drs create record message."""
try:
subject = app.config.get("DOC_CREATE_REC_TOPIC")
document_id = filing.filing_json["filing"][filing.filing_type].get("documentId", "")
data = {
"accountId": "business-api",
"consumerDocumentId": document_id,
"consumerIdentifier": business.identifier,
"consumerFilingType": filing.filing_type,
"consumerReferenceId": str(filing.id),
"documentClass": "CORP"
}

ce = PublishEvent._create_cloud_event(app, business, filing, subject, data)
gcp_queue.publish(subject, to_queue_message(ce))

except Exception as err: # pylint: disable=broad-except;
raise PublishException(err) from err

@staticmethod
def publish_mras_email(app: Flask, business: Business, filing: Filing):
Expand Down
18 changes: 18 additions & 0 deletions queue_services/business-filer/tests/unit/test_filer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,21 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
"""The Unit Tests for the Worker."""
import json
from flask import Flask
from unittest.mock import MagicMock

from business_model.models import Business, Filing

def check_drs_publish(mock_publish: MagicMock, app: Flask, business: Business, filing: Filing, document_id: str):
"""Assert the drs publish was triggered with the expected values."""
assert mock_publish.call_count == 1
subject, payload = mock_publish.call_args.args
assert subject == app.config["DOC_CREATE_REC_TOPIC"]
payload_data = (json.loads(payload)).get('data')
assert payload_data.get('accountId') == 'business-api'
assert payload_data.get('consumerDocumentId') == document_id
assert payload_data.get('consumerFilingType') == filing.filing_type
assert payload_data.get('consumerIdentifier') == business.identifier
assert payload_data.get('consumerReferenceId') == str(filing.id)
assert payload_data.get('documentClass') == 'CORP'
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@

from business_filer.common.filing_message import FilingMessage
from business_filer.services.filer import process_filing
from tests.unit import (
create_business,
create_filing
)
from tests.unit import create_business, create_filing
from tests.unit.filing_processors.filing_components.test_offices import LIQUIDATION_RECORDS_OFFICE
from tests.unit.test_filer import check_drs_publish

CHANGE_OF_LIQUIDATORS_INTENT = {
'type': 'intentToLiquidate',
Expand Down Expand Up @@ -109,12 +107,12 @@
}


def test_process_col_filing(app, session):
def test_process_col_filing(app, session, mocker):
"""Assert that all COL filings can be applied to the model correctly."""
payment_id = str(random.SystemRandom().getrandbits(0x58))
effective_date = datetime(2023, 10, 10, 10, 0, 0, tzinfo=timezone.utc)
identifier = f'BC{random.randint(1000000, 9999999)}'

drs_publish_mock = mocker.patch('business_filer.services.gcp_queue.publish', return_value=None)

business = create_business(identifier)

Expand Down Expand Up @@ -144,6 +142,8 @@ def test_process_col_filing(app, session):
assert intent_filing.business_id == business.id
assert intent_filing.status == Filing.Status.COMPLETED.value
assert business.in_liquidation == True
check_drs_publish(drs_publish_mock, app, business, intent_filing, '')
drs_publish_mock.reset_mock()

party_roles: list[PartyRole] = business.party_roles.all()
assert len(party_roles) == 2
Expand Down Expand Up @@ -211,6 +211,8 @@ def test_process_col_filing(app, session):
assert cease_filing.transaction_id
assert cease_filing.business_id == business.id
assert cease_filing.status == Filing.Status.COMPLETED.value
check_drs_publish(drs_publish_mock, app, business, cease_filing, '')
drs_publish_mock.reset_mock()

party_roles: list[PartyRole] = business.party_roles.all()
assert len(party_roles) == 2
Expand Down Expand Up @@ -287,6 +289,8 @@ def test_process_col_filing(app, session):
assert change_address_filing.transaction_id
assert change_address_filing.business_id == business.id
assert change_address_filing.status == Filing.Status.COMPLETED.value
check_drs_publish(drs_publish_mock, app, business, change_address_filing, '')
drs_publish_mock.reset_mock()

party_roles: list[PartyRole] = business.party_roles.all()

Expand Down Expand Up @@ -346,8 +350,10 @@ def test_process_col_filing(app, session):
}
]
}
new_document_id = '12345677'
filing['filing']['changeOfLiquidators'] = {
'type': 'appointLiquidator',
'documentId': new_document_id,
'relationships': [
new_relationship
]
Expand All @@ -372,6 +378,8 @@ def test_process_col_filing(app, session):
assert appoint_filing.transaction_id
assert appoint_filing.business_id == business.id
assert appoint_filing.status == Filing.Status.COMPLETED.value
check_drs_publish(drs_publish_mock, app, business, appoint_filing, new_document_id)
drs_publish_mock.reset_mock()

party_roles: list[PartyRole] = business.party_roles.all()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@
from business_model.models import Address, Business, Filing, PartyRole, Party
from registry_schemas.example_data import FILING_TEMPLATE

from business_filer.services.filer import process_filing
from tests.unit import (
create_business,
create_filing
)
from business_filer.common.filing_message import FilingMessage
from business_filer.services.filer import process_filing
from tests.unit import create_business, create_filing
from tests.unit.test_filer import check_drs_publish

CHANGE_OF_RECEIVERS_APPOINT = {
'type': 'appointReceiver',
Expand Down Expand Up @@ -157,12 +155,12 @@
}


def test_process_cor_filing(app, session):
def test_process_cor_filing(app, session, mocker):
"""Assert that all COR filings can be applied to the model correctly."""
payment_id = str(random.SystemRandom().getrandbits(0x58))
effective_date = datetime(2023, 10, 10, 10, 0, 0, tzinfo=timezone.utc)
identifier = f'BC{random.randint(1000000, 9999999)}'

drs_publish_mock = mocker.patch('business_filer.services.gcp_queue.publish', return_value=None)

business = create_business(identifier)

Expand Down Expand Up @@ -191,6 +189,8 @@ def test_process_cor_filing(app, session):
assert appoint_filing.transaction_id
assert appoint_filing.business_id == business.id
assert appoint_filing.status == Filing.Status.COMPLETED.value
check_drs_publish(drs_publish_mock, app, business, appoint_filing, '')
drs_publish_mock.reset_mock()

party_roles: list[PartyRole] = business.party_roles.all()
assert len(party_roles) == 4
Expand Down Expand Up @@ -244,6 +244,8 @@ def test_process_cor_filing(app, session):
assert cease_filing.transaction_id
assert cease_filing.business_id == business.id
assert cease_filing.status == Filing.Status.COMPLETED.value
check_drs_publish(drs_publish_mock, app, business, cease_filing, '')
drs_publish_mock.reset_mock()

party_roles: list[PartyRole] = business.party_roles.all()

Expand Down Expand Up @@ -308,6 +310,8 @@ def test_process_cor_filing(app, session):
assert change_address_filing.transaction_id
assert change_address_filing.business_id == business.id
assert change_address_filing.status == Filing.Status.COMPLETED.value
check_drs_publish(drs_publish_mock, app, business, change_address_filing, '')
drs_publish_mock.reset_mock()

party_roles: list[PartyRole] = business.party_roles.all()

Expand Down Expand Up @@ -368,7 +372,9 @@ def test_process_cor_filing(app, session):
}
]
}
expected_document_id = '12345678'
filing['filing']['changeOfReceivers'] = {
'documentId': expected_document_id,
'type': 'amendReceiver',
'relationships': [
{
Expand Down Expand Up @@ -415,6 +421,8 @@ def test_process_cor_filing(app, session):
assert amend_filing.transaction_id
assert amend_filing.business_id == business.id
assert amend_filing.status == Filing.Status.COMPLETED.value
check_drs_publish(drs_publish_mock, app, business, amend_filing, expected_document_id)
drs_publish_mock.reset_mock()

party_roles: list[PartyRole] = business.party_roles.all()

Expand Down
Loading