def test_alteration_process(app, session, orig_legal_type, new_legal_type):
    """Assert that the business legal type is altered."""
    # setup
    identifier = 'BC1234567'
    business = create_business(identifier)
    business.legal_type = orig_legal_type

    alteration_filing = copy.deepcopy(FILING_HEADER)
    alteration_filing['filing']['business']['legalType'] = orig_legal_type
    alteration_filing['filing']['alteration'] = copy.deepcopy(ALTERATION)
    alteration_filing['filing']['alteration']['business'][
        'legalType'] = new_legal_type
    payment_id = str(random.SystemRandom().getrandbits(0x58))
    filing_submission = create_filing(payment_id,
                                      alteration_filing,
                                      business_id=business.id)

    filing_meta = FilingMeta()

    # test
    alteration.process(business=business,
                       filing_submission=filing_submission,
                       filing=alteration_filing['filing'],
                       filing_meta=filing_meta)

    # validate
    assert business.legal_type == new_legal_type
Beispiel #2
0
def test_alteration_process(app, session, orig_legal_type, new_legal_type):
    """Assert that the business legal type is altered."""
    # setup
    identifier = 'BC1234567'
    business = create_business(identifier)
    business.legal_type = orig_legal_type

    alteration_filing = copy.deepcopy(ALTERATION_FILING_TEMPLATE)
    alteration_filing['filing']['alteration']['nameTranslations'] = [{'name': 'A5 Ltd.'}]
    alteration_filing['filing']['business']['legalType'] = orig_legal_type
    alteration_filing['filing']['alteration']['business']['legalType'] = new_legal_type
    payment_id = str(random.SystemRandom().getrandbits(0x58))
    filing_submission = create_filing(payment_id, alteration_filing, business_id=business.id)

    # test
    alteration.process(business=business,
                       filing_submission=filing_submission,
                       filing=alteration_filing['filing'])

    # validate
    assert business.legal_type == new_legal_type
def test_alteration_process(app, session, orig_legal_type, new_legal_type):
    """Assert that the business legal type is altered."""
    # setup
    identifier = 'BC1234567'
    business = create_business(identifier)
    business.legal_type = orig_legal_type

    alteration_filing = copy.deepcopy(ALTERATION_FILING_TEMPLATE)
    alteration_filing['filing']['alteration']['nameTranslations'] = [{
        'name':
        'A5 Ltd.'
    }]
    alteration_filing['filing']['business']['legalType'] = orig_legal_type
    alteration_filing['filing']['alteration']['business'][
        'legalType'] = new_legal_type

    # test
    alteration.process(business, alteration_filing['filing'])

    # validate
    assert business.legal_type == new_legal_type
Beispiel #4
0
async def process_filing(filing_msg: Dict, flask_app: Flask):  # pylint: disable=too-many-branches,too-many-statements
    """Render the filings contained in the submission."""
    if not flask_app:
        raise QueueException('Flask App not available.')

    with flask_app.app_context():
        filing_submission = Filing.find_by_id(filing_msg['filing']['id'])

        if not filing_submission:
            raise QueueException

        if filing_submission.status == Filing.Status.COMPLETED.value:
            logger.warning(
                'QueueFiler: Attempting to reprocess business.id=%s, filing.id=%s filing=%s',
                filing_submission.business_id, filing_submission.id,
                filing_msg)
            return None, None

        if legal_filings := filing_submission.legal_filings():
            uow = versioning_manager.unit_of_work(db.session)
            transaction = uow.create_transaction(db.session)

            business = Business.find_by_internal_id(
                filing_submission.business_id)

            for filing in legal_filings:
                if filing.get('alteration'):
                    alteration.process(business, filing_submission, filing)

                if filing.get('annualReport'):
                    annual_report.process(business, filing)

                elif filing.get('changeOfAddress'):
                    change_of_address.process(business, filing)

                elif filing.get('changeOfDirectors'):
                    filing['colinIds'] = filing_submission.colin_event_ids
                    change_of_directors.process(business, filing)

                elif filing.get('changeOfName'):
                    change_of_name.process(business, filing)

                elif filing.get('voluntaryDissolution'):
                    voluntary_dissolution.process(business, filing)

                elif filing.get('incorporationApplication'):
                    business, filing_submission = incorporation_filing.process(
                        business, filing, filing_submission)

                if filing.get('correction'):
                    filing_submission = correction.process(
                        filing_submission, filing)

                if filing.get('transition'):
                    filing_submission = transition.process(
                        business, filing_submission, filing)

            filing_submission.transaction_id = transaction.id
            filing_submission.set_processed()

            db.session.add(business)
            db.session.add(filing_submission)
            db.session.commit()

            # post filing changes to other services
            if any('alteration' in x for x in legal_filings):
                if name_request.has_new_nr_for_alteration(
                        business, filing_submission.filing_json):
                    name_request.consume_nr(
                        business, filing_submission,
                        '/filing/alteration/nameRequest/nrNumber')
                alteration.post_process(business, filing_submission)
                db.session.add(business)
                db.session.commit()
                AccountService.update_entity(
                    business_registration=business.identifier,
                    business_name=business.legal_name,
                    corp_type_code=business.legal_type)

            if any('incorporationApplication' in x for x in legal_filings):
                if any('correction' in x for x in legal_filings):
                    if name_request.has_new_nr_for_correction(
                            filing_submission.filing_json):
                        name_request.consume_nr(business, filing_submission)
                else:
                    filing_submission.business_id = business.id
                    db.session.add(filing_submission)
                    db.session.commit()
                    incorporation_filing.update_affiliation(
                        business, filing_submission)
                    name_request.consume_nr(business, filing_submission)
                    incorporation_filing.post_process(business,
                                                      filing_submission)
                    try:
                        await publish_email_message(
                            qsm, APP_CONFIG.EMAIL_PUBLISH_OPTIONS['subject'],
                            filing_submission, 'mras')
                    except Exception as err:  # pylint: disable=broad-except, unused-variable # noqa F841;
                        # mark any failure for human review
                        capture_message(
                            f'Queue Error: Failed to place email for filing:{filing_submission.id}'
                            f'on Queue with error:{err}',
                            level='error')

            try:
                await publish_email_message(
                    qsm, APP_CONFIG.EMAIL_PUBLISH_OPTIONS['subject'],
                    filing_submission, filing_submission.status)
            except Exception as err:  # pylint: disable=broad-except, unused-variable # noqa F841;
                # mark any failure for human review
                capture_message(
                    f'Queue Error: Failed to place email for filing:{filing_submission.id}'
                    f'on Queue with error:{err}',
                    level='error')

            try:
                await publish_event(business, filing_submission)
            except Exception as err:  # pylint: disable=broad-except, unused-variable # noqa F841;
                # mark any failure for human review
                capture_message(
                    f'Queue Error: Failed to publish event for filing:{filing_submission.id}'
                    f'on Queue with error:{err}',
                    level='error')
Beispiel #5
0
async def process_filing(filing_msg: Dict, flask_app: Flask):  # pylint: disable=too-many-branches,too-many-statements
    """Render the filings contained in the submission.

    Start the migration to using core/Filing
    """
    if not flask_app:
        raise QueueException('Flask App not available.')

    with flask_app.app_context():
        # filing_submission = Filing.find_by_id(filing_msg['filing']['id'])
        filing_core_submission = FilingCore.find_by_id(
            filing_msg['filing']['id'])

        if not filing_core_submission:
            raise QueueException

        filing_submission = filing_core_submission.storage

        if filing_core_submission.status == Filing.Status.COMPLETED:
            logger.warning(
                'QueueFiler: Attempting to reprocess business.id=%s, filing.id=%s filing=%s',
                filing_submission.business_id, filing_submission.id,
                filing_msg)
            return None, None

        # convenience flag to set that the envelope is a correction
        is_correction = (filing_core_submission.filing_type ==
                         FilingCore.FilingTypes.CORRECTION)

        if legal_filings := filing_core_submission.legal_filings(
                with_diff=False):
            uow = versioning_manager.unit_of_work(db.session)
            transaction = uow.create_transaction(db.session)

            business = Business.find_by_internal_id(
                filing_submission.business_id)

            filing_meta = FilingMeta(
                application_date=filing_submission.effective_date,
                legal_filings=[
                    item
                    for sublist in [list(x.keys()) for x in legal_filings]
                    for item in sublist
                ])

            for filing in legal_filings:
                if filing.get('alteration'):
                    alteration.process(business, filing_submission, filing,
                                       filing_meta, is_correction)

                elif filing.get('annualReport'):
                    annual_report.process(business, filing, filing_meta)

                elif filing.get('changeOfAddress'):
                    change_of_address.process(business, filing, filing_meta)

                elif filing.get('changeOfDirectors'):
                    filing['colinIds'] = filing_submission.colin_event_ids
                    change_of_directors.process(business, filing, filing_meta)

                elif filing.get('changeOfName'):
                    change_of_name.process(business, filing, filing_meta)

                elif filing.get('dissolution'):
                    dissolution.process(business, filing, filing_meta)

                elif filing.get('incorporationApplication'):
                    business, filing_submission, filing_meta = incorporation_filing.process(
                        business, filing_core_submission.json,
                        filing_submission, filing_meta)

                elif filing.get('conversion'):
                    business, filing_submission = conversion.process(
                        business, filing_core_submission.json,
                        filing_submission, filing_meta)

                elif filing.get('courtOrder'):
                    court_order.process(filing_submission, filing, filing_meta)

                elif filing.get('registrarsNotation'):
                    registrars_notation.process(filing_submission, filing,
                                                filing_meta)

                elif filing.get('registrarsOrder'):
                    registrars_order.process(filing_submission, filing,
                                             filing_meta)

                elif filing.get('correction'):
                    filing_submission = correction.process(
                        filing_submission, filing, filing_meta)

                elif filing.get('transition'):
                    filing_submission = transition.process(
                        business, filing_submission, filing, filing_meta)

            filing_submission.transaction_id = transaction.id
            filing_submission.set_processed()
            filing_submission._meta_data = json.loads(  # pylint: disable=W0212
                json.dumps(filing_meta.asjson, default=json_serial))

            db.session.add(business)
            db.session.add(filing_submission)
            db.session.commit()

            # post filing changes to other services
            if any('alteration' in x for x in legal_filings):

                alteration.post_process(business, filing_submission,
                                        correction)
                db.session.add(business)
                db.session.commit()
                AccountService.update_entity(
                    business_registration=business.identifier,
                    business_name=business.legal_name,
                    corp_type_code=business.legal_type)

            if any('incorporationApplication' in x for x in legal_filings):
                if any('correction' in x for x in legal_filings):
                    if name_request.has_new_nr_for_correction(
                            filing_submission.filing_json):
                        name_request.consume_nr(business, filing_submission)
                else:
                    filing_submission.business_id = business.id
                    db.session.add(filing_submission)
                    db.session.commit()
                    incorporation_filing.update_affiliation(
                        business, filing_submission)
                    name_request.consume_nr(business, filing_submission)
                    incorporation_filing.post_process(business,
                                                      filing_submission)
                    try:
                        await publish_email_message(
                            qsm, APP_CONFIG.EMAIL_PUBLISH_OPTIONS['subject'],
                            filing_submission, 'mras')
                    except Exception as err:  # pylint: disable=broad-except, unused-variable # noqa F841;
                        # mark any failure for human review
                        capture_message(
                            f'Queue Error: Failed to place email for filing:{filing_submission.id}'
                            f'on Queue with error:{err}',
                            level='error')

            if any('conversion' in x for x in legal_filings):
                filing_submission.business_id = business.id
                db.session.add(filing_submission)
                db.session.commit()
                conversion.post_process(business, filing_submission)

            try:
                await publish_email_message(
                    qsm, APP_CONFIG.EMAIL_PUBLISH_OPTIONS['subject'],
                    filing_submission, filing_submission.status)
            except Exception as err:  # pylint: disable=broad-except, unused-variable # noqa F841;
                # mark any failure for human review
                capture_message(
                    f'Queue Error: Failed to place email for filing:{filing_submission.id}'
                    f'on Queue with error:{err}',
                    level='error')

            try:
                await publish_event(business, filing_submission)
            except Exception as err:  # pylint: disable=broad-except, unused-variable # noqa F841;
                # mark any failure for human review
                print(err)
                capture_message(
                    f'Queue Error: Failed to publish event for filing:{filing_submission.id}'
                    f'on Queue with error:{err}',
                    level='error')