Skip to content

Commit

Permalink
22367 Emailer - Fix emailer unit tests (#2982)
Browse files Browse the repository at this point in the history
* Fix emailer unit tests

* Fix lint
  • Loading branch information
leodube-aot authored Sep 12, 2024
1 parent 0019a3d commit 32878fd
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 19 deletions.
48 changes: 40 additions & 8 deletions queue_services/entity-emailer/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from random import randrange
from unittest.mock import Mock

from legal_api.models import Batch, Business, Filing, Furnishing, RegistrationBootstrap, User
from legal_api.models import Batch, Business, Filing, Furnishing, Party, PartyRole, RegistrationBootstrap, User
from registry_schemas.example_data import (
AGM_EXTENSION,
AGM_LOCATION_CHANGE,
Expand Down Expand Up @@ -67,12 +67,21 @@ def create_user(user_name: str):
return user


def create_business(identifier, legal_type=None, legal_name=None):
def create_business(identifier, legal_type=None, legal_name=None, parties=None):
"""Return a test business."""
business = Business()
business.identifier = identifier
business.legal_type = legal_type
business.legal_name = legal_name

for party in (parties or []):
if business.legal_type == Business.LegalTypes.SOLE_PROP:
proprietor_role = create_party_role(None, None, party, None, None, PartyRole.RoleTypes.PROPRIETOR)
business.party_roles.append(proprietor_role)
elif legal_type == Business.LegalTypes.PARTNERSHIP:
partner_role = create_party_role(None, None, party, None, None, PartyRole.RoleTypes.PARTNER)
business.party_roles.append(partner_role)

business.save()
return business

Expand Down Expand Up @@ -191,9 +200,10 @@ def prep_registration_filing(session, identifier, payment_id, option, legal_type
return filing


def prep_dissolution_filing(session, identifier, payment_id, option, legal_type, legal_name, submitter_role):
def prep_dissolution_filing(session, identifier, payment_id, option, legal_type,
legal_name, submitter_role, parties=None):
"""Return a new dissolution filing prepped for email notification."""
business = create_business(identifier, legal_type, legal_name)
business = create_business(identifier, legal_type, legal_name, parties)
filing_template = copy.deepcopy(FILING_HEADER)
filing_template['filing']['header']['name'] = 'dissolution'
if submitter_role:
Expand Down Expand Up @@ -322,9 +332,10 @@ def prep_restoration_filing(identifier, payment_id, legal_type, legal_name, r_ty
return filing


def prep_change_of_registration_filing(session, identifier, payment_id, legal_type, legal_name, submitter_role):
def prep_change_of_registration_filing(session, identifier, payment_id, legal_type,
legal_name, submitter_role, parties=None):
"""Return a new change of registration filing prepped for email notification."""
business = create_business(identifier, legal_type, legal_name)
business = create_business(identifier, legal_type, legal_name, parties)

gp_change_of_registration = copy.deepcopy(FILING_HEADER)
gp_change_of_registration['filing']['header']['name'] = 'changeOfRegistration'
Expand Down Expand Up @@ -489,9 +500,9 @@ def prep_incorporation_correction_filing(session, business, original_filing_id,
return filing


def prep_firm_correction_filing(session, identifier, payment_id, legal_type, legal_name, submitter_role):
def prep_firm_correction_filing(session, identifier, payment_id, legal_type, legal_name, submitter_role, parties=None):
"""Return a firm correction filing prepped for email notification."""
business = create_business(identifier, legal_type, legal_name)
business = create_business(identifier, legal_type, legal_name, parties)

gp_correction = copy.deepcopy(CORRECTION_REGISTRATION)
gp_correction['filing']['correction']['parties'][0]['officer']['email'] = '[email protected]'
Expand Down Expand Up @@ -741,3 +752,24 @@ def create_furnishing(session, business=None, batch_id=None,
furnishing.batch_id = batch_id
furnishing.save()
return furnishing


def create_party_role(delivery_address, mailing_address, officer, appointment_date, cessation_date, role_type):
"""Create a role."""
party = Party(
first_name=officer['firstName'],
last_name=officer['lastName'],
middle_initial=officer['middleInitial'],
party_type=officer['partyType'],
organization_name=officer['organizationName']
)
party.delivery_address = delivery_address
party.mailing_address = mailing_address
party.save()
party_role = PartyRole(
role=role_type.value,
appointment_date=appointment_date,
cessation_date=cessation_date,
party_id=party.id
)
return party_role
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ def test_change_of_registration_notification(app, session, mocker, status, legal
"""Assert that email attributes are correct."""
# setup filing + business for email
legal_name = 'test business'
filing = prep_change_of_registration_filing(session, 'FM1234567', '1', legal_type, legal_name, submitter_role)
parties = [{
'firstName': 'Jane',
'lastName': 'Doe',
'middleInitial': 'A',
'partyType': 'person',
'organizationName': ''
}]
filing = prep_change_of_registration_filing(session, 'FM1234567', '1', legal_type,
legal_name, submitter_role, parties)
token = 'token'
# test processor
mocker.patch(
Expand All @@ -46,10 +54,10 @@ def test_change_of_registration_notification(app, session, mocker, status, legal
email = change_of_registration_notification.process(
{'filingId': filing.id, 'type': 'changeOfRegistration', 'option': status}, token)
if status == 'PAID':
assert email['content']['subject'] == legal_name + ' - Confirmation of Filing from the Business Registry'
assert email['content']['subject'] == 'JANE A DOE - Confirmation of Filing from the Business Registry'
else:
assert email['content']['subject'] == \
legal_name + ' - Change of Registration Documents from the Business Registry'
'JANE A DOE - Change of Registration Documents from the Business Registry'

if submitter_role:
assert f'{submitter_role}@email.com' in email['recipients']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,24 @@ def test_firm_correction_notification(app, session, status, legal_type):
"""Assert that email attributes are correct."""
# setup filing + business for email
legal_name = 'test business'
filing = prep_firm_correction_filing(session, 'FM1234567', '1', legal_type, legal_name, 'staff')
parties = [{
'firstName': 'Jane',
'lastName': 'Doe',
'middleInitial': 'A',
'partyType': 'person',
'organizationName': ''
}]
filing = prep_firm_correction_filing(session, 'FM1234567', '1', legal_type, legal_name, 'staff', parties)
token = 'token'
# test processor
with patch.object(correction_notification, '_get_pdfs', return_value=[]) as mock_get_pdfs:
email = correction_notification.process(
{'filingId': filing.id, 'type': 'correction', 'option': status}, token)
if status == 'PAID':
assert email['content']['subject'] == legal_name + ' - Confirmation of Filing from the Business Registry'
assert email['content']['subject'] == 'JANE A DOE - Confirmation of Filing from the Business Registry'
else:
assert email['content']['subject'] == \
legal_name + COMPLETED_SUBJECT_SUFIX
'JANE A DOE' + COMPLETED_SUBJECT_SUFIX

if status == 'COMPLETED':
assert '[email protected]' in email['recipients']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ def test_firms_dissolution_notification(app, session, status, legal_type, submit
"""Assert that the dissolution email processor for firms works as expected."""
# setup filing + business for email
legal_name = 'test business'
filing = prep_dissolution_filing(session, 'FM1234567', '1', status, legal_type, legal_name, submitter_role)
parties = [{
'firstName': 'Jane',
'lastName': 'Doe',
'middleInitial': 'A',
'partyType': 'person',
'organizationName': ''
}]
filing = prep_dissolution_filing(session, 'FM1234567', '1', status, legal_type, legal_name, submitter_role, parties)
token = 'token'
# test processor
with patch.object(dissolution_notification, '_get_pdfs', return_value=[]) as mock_get_pdfs:
Expand All @@ -89,11 +96,11 @@ def test_firms_dissolution_notification(app, session, status, legal_type, submit
email = dissolution_notification.process(
{'filingId': filing.id, 'type': 'dissolution', 'option': status}, token)
if status == 'PAID':
assert email['content']['subject'] == legal_name + \
' - Confirmation of Filing from the Business Registry'
assert email['content']['subject'] == \
'JANE A DOE - Confirmation of Filing from the Business Registry'
else:
assert email['content']['subject'] == \
legal_name + ' - Dissolution Documents from the Business Registry'
'JANE A DOE - Dissolution Documents from the Business Registry'

if submitter_role:
assert f'{submitter_role}@email.com' in email['recipients']
Expand All @@ -106,6 +113,6 @@ def test_firms_dissolution_notification(app, session, status, legal_type, submit
assert mock_get_pdfs.call_args[0][0] == status
assert mock_get_pdfs.call_args[0][1] == token
assert mock_get_pdfs.call_args[0][2]['identifier'] == 'FM1234567'
assert mock_get_pdfs.call_args[0][2]['legalName'] == legal_name
assert mock_get_pdfs.call_args[0][2]['legalName'] == 'JANE A DOE'
assert mock_get_pdfs.call_args[0][2]['legalType'] == legal_type
assert mock_get_pdfs.call_args[0][3] == filing

0 comments on commit 32878fd

Please sign in to comment.