def test_transition_filing_process(app, session): """Assert that the transition object is correctly populated to model objects.""" # setup filing = copy.deepcopy(TRANSITION_FILING_TEMPLATE) business = create_business(filing['filing']['business']['identifier']) create_filing('123', filing) effective_date = datetime.datetime.utcnow() filing_rec = Filing(effective_date=effective_date, filing_json=filing) # test transition.process(business, filing_rec, filing['filing']) # Assertions assert business.restriction_ind is False assert len(business.share_classes.all()) == len(filing['filing']['transition']['shareStructure']['shareClasses']) assert len(business.offices.all()) == len(filing['filing']['transition']['offices']) assert len(business.aliases.all()) == len(filing['filing']['transition']['nameTranslations']) assert len(business.resolutions.all()) == len(filing['filing']['transition']['shareStructure']['resolutionDates']) assert len(business.party_roles.all()) == 2
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')
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')