From a92a62cfd3989c2bf74e1d3a892ea995caaf9e83 Mon Sep 17 00:00:00 2001 From: leodube-aot Date: Thu, 12 Sep 2024 08:40:50 -0700 Subject: [PATCH 1/2] Fix emailer unit tests --- .../entity-emailer/tests/unit/__init__.py | 45 +++++++++++++++---- ...est_change_of_registration_notification.py | 14 ++++-- .../test_correction_notification.py | 13 ++++-- .../test_dissolution_notification.py | 17 ++++--- 4 files changed, 68 insertions(+), 21 deletions(-) diff --git a/queue_services/entity-emailer/tests/unit/__init__.py b/queue_services/entity-emailer/tests/unit/__init__.py index c642e3032b..78160bceba 100644 --- a/queue_services/entity-emailer/tests/unit/__init__.py +++ b/queue_services/entity-emailer/tests/unit/__init__.py @@ -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, @@ -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 @@ -191,9 +200,9 @@ 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: @@ -322,9 +331,9 @@ 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' @@ -489,9 +498,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'] = 'party@email.com' @@ -741,3 +750,23 @@ 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 \ No newline at end of file diff --git a/queue_services/entity-emailer/tests/unit/email_processors/test_change_of_registration_notification.py b/queue_services/entity-emailer/tests/unit/email_processors/test_change_of_registration_notification.py index 601cf18683..50311e9e71 100644 --- a/queue_services/entity-emailer/tests/unit/email_processors/test_change_of_registration_notification.py +++ b/queue_services/entity-emailer/tests/unit/email_processors/test_change_of_registration_notification.py @@ -36,7 +36,14 @@ 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( @@ -46,10 +53,9 @@ 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' + assert email['content']['subject'] == 'JANE A DOE - Change of Registration Documents from the Business Registry' if submitter_role: assert f'{submitter_role}@email.com' in email['recipients'] diff --git a/queue_services/entity-emailer/tests/unit/email_processors/test_correction_notification.py b/queue_services/entity-emailer/tests/unit/email_processors/test_correction_notification.py index acc398fd95..06649d64b3 100644 --- a/queue_services/entity-emailer/tests/unit/email_processors/test_correction_notification.py +++ b/queue_services/entity-emailer/tests/unit/email_processors/test_correction_notification.py @@ -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 'no_one@never.get' in email['recipients'] diff --git a/queue_services/entity-emailer/tests/unit/email_processors/test_dissolution_notification.py b/queue_services/entity-emailer/tests/unit/email_processors/test_dissolution_notification.py index be47961e30..5bceefa596 100644 --- a/queue_services/entity-emailer/tests/unit/email_processors/test_dissolution_notification.py +++ b/queue_services/entity-emailer/tests/unit/email_processors/test_dissolution_notification.py @@ -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: @@ -89,11 +96,9 @@ 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' + assert email['content']['subject'] == 'JANE A DOE - Dissolution Documents from the Business Registry' if submitter_role: assert f'{submitter_role}@email.com' in email['recipients'] @@ -106,6 +111,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 From 664d676d11f8322975bcc36d6316c135f8ee0bc7 Mon Sep 17 00:00:00 2001 From: leodube-aot Date: Thu, 12 Sep 2024 09:11:11 -0700 Subject: [PATCH 2/2] Fix lint --- queue_services/entity-emailer/tests/unit/__init__.py | 9 ++++++--- .../test_change_of_registration_notification.py | 6 ++++-- .../email_processors/test_dissolution_notification.py | 6 ++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/queue_services/entity-emailer/tests/unit/__init__.py b/queue_services/entity-emailer/tests/unit/__init__.py index 78160bceba..be8c73a95e 100644 --- a/queue_services/entity-emailer/tests/unit/__init__.py +++ b/queue_services/entity-emailer/tests/unit/__init__.py @@ -200,7 +200,8 @@ 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, parties=None): +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, parties) filing_template = copy.deepcopy(FILING_HEADER) @@ -331,7 +332,8 @@ 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, parties=None): +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, parties) @@ -751,6 +753,7 @@ def create_furnishing(session, business=None, batch_id=None, furnishing.save() return furnishing + def create_party_role(delivery_address, mailing_address, officer, appointment_date, cessation_date, role_type): """Create a role.""" party = Party( @@ -769,4 +772,4 @@ def create_party_role(delivery_address, mailing_address, officer, appointment_da cessation_date=cessation_date, party_id=party.id ) - return party_role \ No newline at end of file + return party_role diff --git a/queue_services/entity-emailer/tests/unit/email_processors/test_change_of_registration_notification.py b/queue_services/entity-emailer/tests/unit/email_processors/test_change_of_registration_notification.py index 50311e9e71..784495c030 100644 --- a/queue_services/entity-emailer/tests/unit/email_processors/test_change_of_registration_notification.py +++ b/queue_services/entity-emailer/tests/unit/email_processors/test_change_of_registration_notification.py @@ -43,7 +43,8 @@ def test_change_of_registration_notification(app, session, mocker, status, legal 'partyType': 'person', 'organizationName': '' }] - filing = prep_change_of_registration_filing(session, 'FM1234567', '1', legal_type, legal_name, submitter_role, parties) + filing = prep_change_of_registration_filing(session, 'FM1234567', '1', legal_type, + legal_name, submitter_role, parties) token = 'token' # test processor mocker.patch( @@ -55,7 +56,8 @@ def test_change_of_registration_notification(app, session, mocker, status, legal if status == 'PAID': assert email['content']['subject'] == 'JANE A DOE - Confirmation of Filing from the Business Registry' else: - assert email['content']['subject'] == 'JANE A DOE - Change of Registration Documents from the Business Registry' + assert email['content']['subject'] == \ + 'JANE A DOE - Change of Registration Documents from the Business Registry' if submitter_role: assert f'{submitter_role}@email.com' in email['recipients'] diff --git a/queue_services/entity-emailer/tests/unit/email_processors/test_dissolution_notification.py b/queue_services/entity-emailer/tests/unit/email_processors/test_dissolution_notification.py index 5bceefa596..603fd58031 100644 --- a/queue_services/entity-emailer/tests/unit/email_processors/test_dissolution_notification.py +++ b/queue_services/entity-emailer/tests/unit/email_processors/test_dissolution_notification.py @@ -96,9 +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'] == 'JANE A DOE - 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'] == 'JANE A DOE - Dissolution Documents from the Business Registry' + assert email['content']['subject'] == \ + 'JANE A DOE - Dissolution Documents from the Business Registry' if submitter_role: assert f'{submitter_role}@email.com' in email['recipients']