Skip to content

Commit

Permalink
21515 - unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ketaki-deodhar committed Sep 5, 2024
1 parent 89d9d73 commit d3d5c89
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ def process(email_msg: dict) -> dict:

# get filing and business json
business = Business.find_by_identifier(email_msg['identifier'])

# get filings by types. There will be only one of the listed filing types at once
filings = Filing.get_filings_by_types(business.id, ['amalgamationApplication', 'continuationIn',
'incorporationApplication', 'registration'])
filing_type = filings[0].filing_type

filing = (Filing.get_a_businesses_most_recent_filing_of_a_type(business.id, filing_type))
corp_type = CorpType.find_by_id(business.legal_type)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def process(email_msg: dict) -> dict:
)

# get recipients
recipients = get_recipients(email_msg['option'], filing.filing_json)
recipients = get_recipients(email_msg['option'], filing.filing_json, None, filing_type)

return {
'recipients': recipients,
Expand All @@ -56,15 +56,15 @@ def process(email_msg: dict) -> dict:
'attachments': []
}
}



def get_filing_data(filing, filing_type):
"""Get filing data based on filing type."""
filing_data = []
if filing_type == 'amalgamationApplication':
filing_data=(filing.json)['filing']['amalgamationApplication']

filing_data = (filing.json)['filing']['amalgamationApplication']
if filing_type == 'continuationIn':
filing_data=(filing.json)['filing']['continuationIn']

filing_data = (filing.json)['filing']['continuationIn']
if filing_type == 'incorporationApplication':
filing_data=(filing.json)['filing']['incorporationApplication']
filing_data = (filing.json)['filing']['incorporationApplication']
return filing_data
4 changes: 3 additions & 1 deletion queue_services/entity-emailer/src/entity_emailer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ def process_email(email_msg: dict, flask_app: Flask): # pylint: disable=too-man
if etype == 'businessNumber':
email = bn_notification.process(email_msg['email'])
send_email(email, token)
elif etype in ['amalgamationApplication', 'continuationIn','incorporationApplication'] and option == 'mras':
elif etype in ['amalgamationApplication',
'continuationIn',
'incorporationApplication'] and option == 'mras':
email = mras_notification.process(email_msg['email'])
send_email(email, token)
elif etype == 'annualReport' and option == 'reminder':
Expand Down
4 changes: 2 additions & 2 deletions queue_services/entity-emailer/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def prep_amalgamation_filing(session, identifier, payment_id, option, legal_name
business_id=business.id, bootstrap_id=temp_identifier)
filing.payment_completion_date = filing.filing_date
filing.save()
if option == Filing.Status.COMPLETED.value:
if option in [Filing.Status.COMPLETED.value, 'bn']:
uow = versioning_manager.unit_of_work(session)
transaction = uow.create_transaction(session)
filing.transaction_id = transaction.id
Expand Down Expand Up @@ -679,7 +679,7 @@ def prep_continuation_in_filing(session, identifier, payment_id, option):
business_id=business.id, bootstrap_id=temp_identifier)
filing.payment_completion_date = filing.filing_date
filing.save()
if option == Filing.Status.COMPLETED.value:
if option in [Filing.Status.COMPLETED.value, 'bn']:
uow = versioning_manager.unit_of_work(session)
transaction = uow.create_transaction(session)
filing.transaction_id = transaction.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
from legal_api.models import Business

from entity_emailer.email_processors import bn_notification
from tests.unit import prep_incorp_filing, prep_registration_filing
from tests.unit import (
prep_amalgamation_filing,
prep_continuation_in_filing,
prep_incorp_filing,
prep_registration_filing,
)


def test_bn_notificaton(app, session):
def test_incorporation_bn_notificaton(app, session):
"""Assert that the bn email processor builds the email correctly."""
# setup filing + business for email
identifier = 'BC1234567'
Expand All @@ -40,6 +45,46 @@ def test_bn_notificaton(app, session):
assert email['content']['attachments'] == []


def test_amalgamation_bn_notificaton(app, session):
"""Assert bn notification email for Amalgamation filing."""
# setup filing + business for email
identifier = 'BC1234567'
filing = prep_amalgamation_filing(session, identifier, '1', 'bn', 'TED business')
business = Business.find_by_identifier(identifier)
# sanity check
assert filing.id
assert business.id
# run processor
email = bn_notification.process(
{'filingId': None, 'type': 'businessNumber', 'option': 'bn', 'identifier': 'BC1234567'})
# check email values
assert '[email protected]' in email['recipients']
assert '[email protected]' in email['recipients']
assert email['content']['subject'] == f'{business.legal_name} - Business Number Information'
assert email['content']['body']
assert email['content']['attachments'] == []


def test_continuation_bn_notificaton(mocker, app, session):
"""Assert bn notification email for Continuation filing."""
# setup filing + business for email
identifier = 'BC1234567'
filing = prep_continuation_in_filing(session, identifier, '1', 'bn')
business = Business.find_by_identifier(identifier)
# sanity check
assert filing.id
assert business.id
# run processor
email = bn_notification.process(
{'filingId': None, 'type': 'businessNumber', 'option': 'bn', 'identifier': 'BC1234567'})
# check email values
assert '[email protected]' in email['recipients']
assert '[email protected]' in email['recipients']
assert email['content']['subject'] == f'{business.legal_name} - Business Number Information'
assert email['content']['body']
assert email['content']['attachments'] == []


def test_bn_move_notificaton(app, session):
"""Assert that the bn move email processor builds the email correctly."""
# setup filing + business for email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# limitations under the License.
"""The Unit Tests for the mras email processor."""
from entity_emailer.email_processors import mras_notification
from tests.unit import prep_incorp_filing
from tests.unit import prep_amalgamation_filing, prep_continuation_in_filing, prep_incorp_filing


def test_mras_notification(app, session):
"""Assert that the legal name is changed."""
def test_incorporation_app_mras_notification(app, session):
"""Assert mras notification email for Incorporation application filing."""
# setup filing + business for email
filing = prep_incorp_filing(session, 'BC1234567', '1', 'mras')
# run processor
Expand All @@ -28,3 +28,32 @@ def test_mras_notification(app, session):
assert email['content']['subject'] == 'BC Business Registry Partner Information'
assert email['content']['body']
assert email['content']['attachments'] == []


def test_amalgamation_mras_notification(app, session):
"""Assert mras notification email for Amalgamation filing."""
# setup filing + business for email
filing = prep_amalgamation_filing(session, 'BC1234567', '1', 'mras', 'TED business')
# run processor
email = mras_notification.process(
{'filingId': filing.id, 'type': 'amalgamationApplication', 'option': 'mras'})
# check email values
assert email['recipients'] == '[email protected]'
assert email['content']['subject'] == 'BC Business Registry Partner Information'
assert email['content']['body']
assert email['content']['attachments'] == []


def test_continuation_mras_notification(app, session):
"""Assert mras notification email for Continuation In filing."""
# setup filing + business for email
filing = prep_continuation_in_filing(session, 'BC1234567', '1', 'mras')

# run processor
email = mras_notification.process(
{'filingId': filing.id, 'type': 'continuationIn', 'option': 'mras'})
# check email values
assert email['recipients'] == '[email protected]'
assert email['content']['subject'] == 'BC Business Registry Partner Information'
assert email['content']['body']
assert email['content']['attachments'] == []

0 comments on commit d3d5c89

Please sign in to comment.