def test_incorp_notification(app, session, status):
    """Assert that the legal name is changed."""
    # setup filing + business for email
    filing = prep_incorp_filing(session, 'BC1234567', '1', status)
    token = 'token'
    # test processor
    with patch.object(filing_notification, '_get_pdfs',
                      return_value=[]) as mock_get_pdfs:
        email = filing_notification.process(
            {
                'filingId': filing.id,
                'type': 'incorporationApplication',
                'option': status
            }, token)
        if status == 'PAID':
            assert '*****@*****.**' in email['recipients']
            assert email['content'][
                'subject'] == 'Confirmation of Filing from the Business Registry'
        else:
            assert email['content'][
                'subject'] == 'Incorporation Documents from the Business Registry'

        assert '*****@*****.**' in email['recipients']
        assert email['content']['body']
        assert email['content']['attachments'] == []
        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': 'BC1234567'}
        assert mock_get_pdfs.call_args[0][3] == filing
def test_maintenance_notification(app, session, status, filing_type):
    """Assert that the legal name is changed."""
    # setup filing + business for email
    filing = prep_maintenance_filing(session, 'BC1234567', '1', status,
                                     filing_type)
    token = 'token'
    # test processor
    with patch.object(filing_notification, '_get_pdfs',
                      return_value=[]) as mock_get_pdfs:
        with patch.object(filing_notification, 'get_recipients', return_value='*****@*****.**') \
          as mock_get_recipients:
            email = filing_notification.process(
                {
                    'filingId': filing.id,
                    'type': filing_type,
                    'option': status
                }, token)

            assert '*****@*****.**' in email['recipients']
            assert email['content']['body']
            assert email['content']['attachments'] == []
            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': 'BC1234567', 'legalype': Business.LegalTypes.BCOMP.value, 'legalName': 'test business'}
            assert mock_get_pdfs.call_args[0][3] == filing
            assert mock_get_recipients.call_args[0][0] == status
            assert mock_get_recipients.call_args[0][1] == filing.filing_json
            assert mock_get_recipients.call_args[0][2] == token
Exemplo n.º 3
0
def test_correction_incorporation_notification(app, session, status, has_name_change_with_new_nr):
    """Assert that the legal name is changed."""
    # setup filing + business for email
    original_filing = prep_incorp_filing(session, 'BC1234567', '1', status)
    token = 'token'
    business = Business.find_by_identifier('BC1234567')
    filing = prep_incorporation_correction_filing(session, business, original_filing.id, '1', status,
                                                  has_name_change_with_new_nr)
    # test processor
    with patch.object(filing_notification, '_get_pdfs', return_value=[]) as mock_get_pdfs:
        email = filing_notification.process(
            {'filingId': filing.id, 'type': 'correction', 'option': status}, token)
        if status == 'PAID':
            assert '*****@*****.**' not in email['recipients']
            assert email['content']['subject'] == 'Confirmation of Correction of Incorporation Application'
            assert 'Incorporation Application (Corrected)' in email['content']['body']
        else:
            assert email['content']['subject'] == \
                'Incorporation Application Correction Documents from the Business Registry'

        assert '*****@*****.**' in email['recipients']
        assert email['content']['body']
        if has_name_change_with_new_nr:
            assert 'Incorporation Certificate (Corrected)' in email['content']['body']
        else:
            assert 'Incorporation Certificate (Corrected)' not in email['content']['body']
        assert email['content']['attachments'] == []
        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': 'BC1234567'}
        assert mock_get_pdfs.call_args[0][3] == filing
Exemplo n.º 4
0
def process_email(email_msg: dict, flask_app: Flask):  # pylint: disable=too-many-branches
    """Process the email contained in the submission."""
    if not flask_app:
        raise QueueException('Flask App not available.')

    with flask_app.app_context():
        logger.debug('Attempting to process email: %s', email_msg)
        token = AccountService.get_bearer_token()
        etype = email_msg.get('type', None)
        if etype and etype == 'bc.registry.names.request':
            option = email_msg.get('data', {}).get('request',
                                                   {}).get('option', None)
            if option and option in [
                    nr_notification.Option.BEFORE_EXPIRY.value,
                    nr_notification.Option.EXPIRED.value,
                    nr_notification.Option.RENEWAL.value,
                    nr_notification.Option.UPGRADE.value,
                    nr_notification.Option.REFUND.value
            ]:
                email = nr_notification.process(email_msg, option)
            else:
                email = name_request.process(email_msg)
            send_email(email, token)
        elif etype and etype == 'bc.registry.affiliation':
            email = affiliation_notification.process(email_msg, token)
            send_email(email, token)
        else:
            etype = email_msg['email']['type']
            option = email_msg['email']['option']
            if etype == 'businessNumber':
                email = bn_notification.process(email_msg['email'])
                send_email(email, token)
            elif etype == 'incorporationApplication' and option == 'mras':
                email = mras_notification.process(email_msg['email'])
                send_email(email, token)
            elif etype == 'annualReport' and option == 'reminder':
                email = ar_reminder_notification.process(
                    email_msg['email'], token)
                send_email(email, token)
            elif etype == 'dissolution':
                email = dissolution_notification.process(
                    email_msg['email'], token)
                send_email(email, token)
            elif etype in filing_notification.FILING_TYPE_CONVERTER.keys():
                if etype == 'annualReport' and option == Filing.Status.COMPLETED.value:
                    logger.debug('No email to send for: %s', email_msg)
                else:
                    email = filing_notification.process(
                        email_msg['email'], token)
                    if email:
                        send_email(email, token)
                    else:
                        # should only be if this was for a a coops filing
                        logger.debug('No email to send for: %s', email_msg)
            else:
                logger.debug('No email to send for: %s', email_msg)
Exemplo n.º 5
0
def process_email(email_msg: dict, flask_app: Flask):  # pylint: disable=too-many-branches
    """Process the email contained in the submission."""
    if not flask_app:
        raise QueueException('Flask App not available.')

    with flask_app.app_context():
        logger.debug('Attempting to process email: %s', email_msg)
        token = AccountService.get_bearer_token()
        etype = email_msg.get('type', None)
        if etype and etype == 'bc.registry.names.request':
            email = name_request.process(email_msg)
            send_email(email, token)
        else:
            etype = email_msg['email']['type']
            option = email_msg['email']['option']
            if etype == 'businessNumber':
                email = bn_notification.process(email_msg['email'])
                send_email(email, token)
            elif etype == 'incorporationApplication' and option == 'mras':
                email = mras_notification.process(email_msg['email'])
                send_email(email, token)
            elif etype in filing_notification.FILING_TYPE_CONVERTER.keys():
                if etype == 'annualReport' and option == Filing.Status.COMPLETED.value:
                    logger.debug('No email to send for: %s', email_msg)
                # Remove this when self serve alteration is implemented.
                elif etype == 'alteration' and option == Filing.Status.PAID.value:
                    logger.debug('No email to send for: %s', email_msg)
                else:
                    email = filing_notification.process(
                        email_msg['email'], token)
                    if email:
                        send_email(email, token)
                    else:
                        # should only be if this was for a a coops filing
                        logger.debug('No email to send for: %s', email_msg)
            else:
                logger.debug('No email to send for: %s', email_msg)