def test_conversion_process_with_nr(app, session): """Assert that the incorporation object is correctly populated to model objects.""" # setup filing = copy.deepcopy(CONVERSION_FILING_TEMPLATE) identifier = 'BC1234567' nr_num = 'NR 1234567' filing['filing']['business']['identifier'] = identifier filing['filing']['conversion']['nameRequest']['nrNumber'] = nr_num filing['filing']['conversion']['nameRequest']['legalName'] = 'Test' create_filing('123', filing) effective_date = datetime.utcnow() filing_rec = Filing(effective_date=effective_date, filing_json=filing) filing_meta = FilingMeta(application_date=effective_date) # test business, filing_rec = conversion.process(None, filing, filing_rec, filing_meta) # Assertions assert business.identifier == identifier assert business.founding_date == effective_date assert business.legal_type == filing['filing']['conversion'][ 'nameRequest']['legalType'] assert business.legal_name == filing['filing']['conversion'][ 'nameRequest']['legalName'] assert len(business.share_classes.all()) == 2 assert len(business.offices.all() ) == 2 # One office is created in create_business method.
def test_process_ar_filing(app, session): """Assert that an AR filling can be applied to the model correctly.""" from entity_filer.worker import process_filing from entity_filer.worker import get_filing_by_payment_id from legal_api.models import Business, Filing # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' agm_date = datetime.date.fromisoformat(AR_FILING['filing']['annualReport'].get('annualGeneralMeetingDate')) ar_date = datetime.date.fromisoformat(COMBINED_FILING['filing']['annualReport'].get('annualReportDate')) # setup business = create_business(identifier) business_id = business.id create_filing(payment_id, AR_FILING, business.id) payment_token = {'paymentToken': {'id': payment_id, 'statusCode': Filing.Status.COMPLETED.value}} # TEST process_filing(payment_token, app) # Get modified data filing = get_filing_by_payment_id(payment_id) business = Business.find_by_internal_id(business_id) # check it out assert filing.transaction_id assert filing.business_id == business_id assert filing.status == Filing.Status.COMPLETED.value assert datetime.datetime.date(business.last_agm_date) == agm_date assert datetime.datetime.date(business.last_ar_date) == ar_date
def test_incorporation_filing_process_no_nr(app, session): """Assert that the incorporation object is correctly populated to model objects.""" # setup next_corp_num = 'BC0001095' with patch.object(incorporation_filing, 'get_next_corp_num', return_value=next_corp_num) as mock_get_next_corp_num: filing = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) create_filing('123', filing) effective_date = datetime.utcnow() filing_rec = Filing(effective_date=effective_date, filing_json=filing) filing_meta = FilingMeta(application_date=filing_rec.effective_date) # test business, filing_rec, filing_meta = incorporation_filing.process(None, filing, filing_rec, filing_meta) # Assertions assert business.identifier == next_corp_num assert business.founding_date == effective_date assert business.legal_type == filing['filing']['incorporationApplication']['nameRequest']['legalType'] assert business.legal_name == business.identifier[2:] + ' B.C. LTD.' assert len(business.share_classes.all()) == 2 assert len(business.offices.all()) == 2 # One office is created in create_business method. # Parties parties = filing_rec.filing_json['filing']['incorporationApplication']['parties'] assert parties[0]['officer']['firstName'] == 'Joe' assert parties[0]['officer']['lastName'] == 'Swanson' assert parties[0]['officer']['middleName'] == 'P' assert parties[0]['officer']['partyType'] == 'person' assert parties[1]['officer']['partyType'] == 'organization' assert parties[1]['officer']['organizationName'] == 'Xyz Inc.' mock_get_next_corp_num.assert_called_with(filing['filing']['incorporationApplication']['nameRequest']['legalType'])
def test_process_coa_filing(app, session): """Assert that an AR filling can be applied to the model correctly.""" from entity_filer.worker import process_filing from entity_filer.worker import get_filing_by_payment_id from legal_api.models import Business, Filing # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' new_delivery_address = COA_FILING['filing']['changeOfAddress']['deliveryAddress'] new_mailing_address = COA_FILING['filing']['changeOfAddress']['mailingAddress'] # setup business = create_business(identifier) business_id = business.id create_filing(payment_id, COA_FILING, business.id) payment_token = {'paymentToken': {'id': payment_id, 'statusCode': Filing.Status.COMPLETED.value}} # TEST process_filing(payment_token, app) # Get modified data filing = get_filing_by_payment_id(payment_id) business = Business.find_by_internal_id(business_id) # check it out assert filing.transaction_id assert filing.business_id == business_id assert filing.status == Filing.Status.COMPLETED.value delivery_address = business.delivery_address.one_or_none().json compare_addresses(delivery_address, new_delivery_address) mailing_address = business.mailing_address.one_or_none().json compare_addresses(mailing_address, new_mailing_address)
def test_process_filing_failed(app, session): """Assert that an AR filling status is set to error if payment transaction failed.""" from entity_filer.worker import process_filing from entity_filer.worker import get_filing_by_payment_id from legal_api.models import Business, Filing # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' # setup business = create_business(identifier) business_id = business.id create_filing(payment_id, AR_FILING, business.id) payment_token = {'paymentToken': {'id': payment_id, 'statusCode': 'TRANSACTION_FAILED'}} # TEST process_filing(payment_token, app) # Get modified data filing = get_filing_by_payment_id(payment_id) business = Business.find_by_internal_id(business_id) # check it out assert filing.business_id == business_id assert filing.status == Filing.Status.ERROR.value assert not business.last_agm_date assert not business.last_ar_date
def test_incorporation_filing_process_no_nr(app, session): """Assert that the incorporation object is correctly populated to model objects.""" # setup next_corp_num = 'BC0001095' with patch.object(incorporation_filing, 'get_next_corp_num', return_value=next_corp_num) as mock_get_next_corp_num: filing = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) create_filing('123', filing) effective_date = datetime.utcnow() filing_rec = Filing(effective_date=effective_date, filing_json=filing) # test business, filing_rec = incorporation_filing.process( None, filing['filing'], filing_rec) # Assertions assert business.identifier == next_corp_num assert business.founding_date == effective_date assert business.legal_type == filing['filing'][ 'incorporationApplication']['nameRequest']['legalType'] assert business.legal_name == business.identifier[2:] + ' B.C. LTD.' assert len(business.share_classes.all()) == 2 assert len(business.offices.all() ) == 2 # One office is created in create_business method. mock_get_next_corp_num.assert_called_with( filing['filing']['incorporationApplication']['nameRequest'] ['legalType'])
async def test_process_empty_filing(app, session): """Assert that an AR filling can be applied to the model correctly.""" from entity_pay.worker import get_filing_by_payment_id, process_payment from legal_api.models import Filing # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' # setup business = create_business(identifier) business_id = business.id create_filing(payment_id, None, business.id) payment_token = { 'paymentToken': { 'id': payment_id, 'statusCode': Filing.Status.COMPLETED.value } } # TEST await process_payment(payment_token, app) # Get modified data filing = get_filing_by_payment_id(payment_id) # check it out assert filing.business_id == business_id assert filing.status == Filing.Status.PAID.value
async def test_correction_filing(app, session): """Assert we can process a correction filing.""" # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1111111' correction_filing_comment = 'We need to fix directors' # get a fixed datetime to use in comparisons, in "local" (Pacific) timezone local_timezone = pytz.timezone('US/Pacific') correction_filing_date = \ datetime.datetime(2019, 9, 17, 0, 0).replace(tzinfo=datetime.timezone.utc).astimezone(tz=local_timezone) # setup - create business, staff user, and original filing to be corrected business_id = create_business(identifier).id staff_user_id = create_user(username='******').id original_filing_id = create_filing(payment_id, copy.deepcopy(ANNUAL_REPORT), business_id).id # setup - create correction filing filing = copy.deepcopy(CORRECTION_AR) filing['filing']['header']['identifier'] = identifier filing['filing']['correction']['comment'] = correction_filing_comment filing['filing']['correction']['correctedFilingId'] = original_filing_id correction_filing = create_filing(payment_id, filing, business_id, filing_date=correction_filing_date) correction_filing.submitter_id = staff_user_id correction_filing.save() correction_filing_id = correction_filing.id filing_msg = {'filing': {'id': correction_filing_id}} # TEST await process_filing(filing_msg, app) # Get modified data original_filing = Filing.find_by_id(original_filing_id) correction_filing = Filing.find_by_id(correction_filing_id) staff_user = User.find_by_username('staff_user') # check that the correction filing is linked to the original filing assert original_filing.parent_filing assert original_filing.parent_filing == correction_filing # check that the correction comment has been added to the correction filing assert 0 < len(correction_filing.comments.all()) assert correction_filing_comment == correction_filing.comments.all()[-1].comment assert staff_user.id == correction_filing.comments.all()[-1].staff.id # check that the correction filing is PENDING_CORRECTION assert correction_filing.status == 'PENDING_CORRECTION' # check that the original filing is marked as corrected # assert True is original_filing.is_corrected # check that the original filing has the new comment assert 0 < len(original_filing.comments.all()) assert f'This filing was corrected on {correction_filing_date.date().isoformat()}.' == \ original_filing.comments.all()[-1].comment assert staff_user.id == original_filing.comments.all()[-1].staff.id
def test_incorporation_filing_process_with_nr(app, session, minio_server, legal_type, filing): """Assert that the incorporation object is correctly populated to model objects.""" # setup next_corp_num = 'BC0001095' with patch.object(incorporation_filing, 'get_next_corp_num', return_value=next_corp_num) as mock_get_next_corp_num: identifier = 'NR 1234567' filing['filing']['incorporationApplication']['nameRequest']['nrNumber'] = identifier filing['filing']['incorporationApplication']['nameRequest']['legalName'] = 'Test' if legal_type == 'CP': rules_file_key_uploaded_by_user = _upload_file() memorandum_file_key_uploaded_by_user = _upload_file() filing['filing']['incorporationApplication']['cooperative']['rulesFileKey'] = \ rules_file_key_uploaded_by_user filing['filing']['incorporationApplication']['cooperative']['rulesFileName'] = 'Rules_File.pdf' filing['filing']['incorporationApplication']['cooperative']['memorandumFileKey'] = \ memorandum_file_key_uploaded_by_user filing['filing']['incorporationApplication']['cooperative']['memorandumFileName'] = 'Memorandum_File.pdf' create_filing('123', filing) effective_date = datetime.utcnow() filing_rec = Filing(effective_date=effective_date, filing_json=filing) filing_meta = FilingMeta(application_date=effective_date) # test business, filing_rec, filing_meta = incorporation_filing.process(None, filing, filing_rec, filing_meta) # Assertions assert business.identifier == next_corp_num assert business.founding_date == effective_date assert business.legal_type == filing['filing']['incorporationApplication']['nameRequest']['legalType'] assert business.legal_name == filing['filing']['incorporationApplication']['nameRequest']['legalName'] if legal_type == 'BC': assert len(business.share_classes.all()) == 2 assert len(business.offices.all()) == 2 # One office is created in create_business method. elif legal_type == 'CP': assert len(business.offices.all()) == 1 documents = business.documents.all() assert len(documents) == 2 for document in documents: if document.type == DocumentType.COOP_RULES.value: original_rules_key = filing['filing']['incorporationApplication']['cooperative']['rulesFileKey'] assert document.file_key == original_rules_key assert MinioService.get_file(document.file_key) elif document.type == DocumentType.COOP_MEMORANDUM.value: original_memorandum_key = \ filing['filing']['incorporationApplication']['cooperative']['memorandumFileKey'] assert document.file_key == original_memorandum_key assert MinioService.get_file(document.file_key) rules_files_obj = MinioService.get_file(rules_file_key_uploaded_by_user) assert rules_files_obj _assert_pdf_contains_text('Filed on ', rules_files_obj.read()) memorandum_file_obj = MinioService.get_file(memorandum_file_key_uploaded_by_user) assert memorandum_file_obj _assert_pdf_contains_text('Filed on ', memorandum_file_obj.read()) mock_get_next_corp_num.assert_called_with(filing['filing']['incorporationApplication']['nameRequest']['legalType'])
def test_get_filing_by_payment_id(app, session): """Assert that a unique filling gets retrieved for a payment_id.""" from entity_filer.worker import get_filing_by_payment_id payment_id = str(random.SystemRandom().getrandbits(0x58)) create_filing(payment_id) filing = get_filing_by_payment_id(str(payment_id)) assert filing assert filing.payment_token == payment_id
async def test_process_filing_missing_app(app, session): """Assert that a filling will fail with no flask app supplied.""" # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' # setup business = create_business(identifier) create_filing(payment_id, None, business.id) filing_msg = {'filing': {'id': 'test_id'}} # TEST with pytest.raises(Exception): await process_filing(filing_msg, flask_app=None)
def test_process_filing_completed(app, session): """Assert that an AR filling status is set to completed once processed.""" from entity_filer.worker import process_filing from legal_api.models import Business, Filing # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' # setup business = create_business(identifier) business_id = business.id filing_id = (create_filing(payment_id, AR_FILING, business.id)).id filing_msg = {'filing': {'id': filing_id}} # TEST process_filing(filing_msg, app) # Get modified data filing = Filing.find_by_id(filing_id) business = Business.find_by_internal_id(business_id) # check it out assert filing.business_id == business_id assert filing.status == Filing.Status.COMPLETED.value assert filing.transaction_id assert business.last_agm_date assert business.last_ar_date
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
def test_process_incorporation_parties(app, session): """Assert we successfully add parties in incorporation filing.""" # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) filing = copy.deepcopy(INCORP_FILING) schema_incorp = copy.deepcopy(INCORPORATION) filing['filing']['incorporationApplication']['parties'] = schema_incorp['parties'] identifier = filing['filing']['incorporationApplication']['nameRequest']['nrNumber'] business = create_business(identifier) filing_id = (create_filing(payment_id, filing, business.id)).id filing_msg = {'filing': {'id': filing_id}} process_filing(filing_msg, app) filing = Filing.find_by_id(filing_id) business = Business.find_by_internal_id(filing.business_id) assert len(PartyRole.get_parties_by_role(business.id, 'director')) == 1 assert len(PartyRole.get_parties_by_role(business.id, 'incorporator')) == 1 assert len(PartyRole.get_parties_by_role(business.id, 'completing_party')) == 1 director = (PartyRole.get_parties_by_role(business.id, 'director'))[0] incorporator = (PartyRole.get_parties_by_role(business.id, 'incorporator'))[0] completing_party = (PartyRole.get_parties_by_role(business.id, 'completing_party'))[0] assert director.appointment_date assert incorporator.appointment_date assert completing_party.appointment_date
def test_has_new_nr_for_correction(app, session, test_name, nr_number, expected_result): """Assert that the incorporation object is correctly populated to model objects.""" # setup next_corp_num = 'BC0001095' with patch.object(incorporation_filing, 'get_next_corp_num', return_value=next_corp_num): filing = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) identifier = 'NR 1234567' filing['filing']['incorporationApplication']['nameRequest']['nrNumber'] = identifier filing['filing']['incorporationApplication']['nameRequest']['legalName'] = 'Test' original_filing = create_filing('123', filing) effective_date = datetime.utcnow() filing_rec = Filing(effective_date=effective_date, filing_json=filing) # test business, filing_rec = incorporation_filing.process(None, filing['filing'], filing_rec) # Assertions assert business.identifier == next_corp_num assert business.founding_date == effective_date assert business.legal_type == filing['filing']['incorporationApplication']['nameRequest']['legalType'] assert business.legal_name == filing['filing']['incorporationApplication']['nameRequest']['legalName'] correction_filing = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) correction_filing['filing']['incorporationApplication']['nameRequest']['nrNumber'] = nr_number correction_filing['filing']['correction'] = {} correction_filing['filing']['correction']['correctedFilingId'] = original_filing.id assert name_request.has_new_nr_for_correction(correction_filing) is expected_result
async def test_transition_filing(app, session): """Assert we can create a business based on transition filing.""" filing_data = copy.deepcopy(TRANSITION_FILING_TEMPLATE) business = create_business(filing_data['filing']['business']['identifier']) payment_id = str(random.SystemRandom().getrandbits(0x58)) filing = (create_filing(payment_id, filing_data, business.id)) filing_msg = {'filing': {'id': filing.id}} # Test await process_filing(filing_msg, app) # Check outcome filing = Filing.find_by_id(filing.id) business = Business.find_by_internal_id(filing.business_id) filing_json = filing.filing_json assert business assert filing assert filing.status == Filing.Status.COMPLETED.value assert business.restriction_ind is False assert len(business.share_classes.all()) == len( filing_json['filing']['transition']['shareStructure']['shareClasses']) assert len(business.offices.all()) == len( filing_json['filing']['transition']['offices']) assert len(business.aliases.all()) == len( filing_json['filing']['transition']['nameTranslations']) assert len(business.resolutions.all()) == len( filing_json['filing']['transition']['shareStructure'] ['resolutionDates']) assert len(PartyRole.get_parties_by_role(business.id, 'director')) == 2
async def test_process_ar_filing_no_agm(app, session): """Assert that a no agm AR filling can be applied to the model correctly.""" # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' # setup business = create_business(identifier) business_id = business.id now = datetime.date(2020, 9, 17) ar_date = datetime.date(2020, 8, 5) agm_date = None ar = copy.deepcopy(ANNUAL_REPORT) ar['filing']['business']['identifier'] = identifier ar['filing']['annualReport']['annualReportDate'] = ar_date.isoformat() ar['filing']['annualReport']['annualGeneralMeetingDate'] = None # TEST with freeze_time(now): filing = create_filing(payment_id, ar, business.id) filing_id = filing.id filing_msg = {'filing': {'id': filing_id}} await process_filing(filing_msg, app) # Get modified data filing = Filing.find_by_id(filing_id) business = Business.find_by_internal_id(business_id) # check it out assert filing.transaction_id assert filing.business_id == business_id assert filing.status == Filing.Status.COMPLETED.value assert business.last_agm_date == agm_date assert datetime.datetime.date(business.last_ar_date) == ar_date
async def test_worker_alteration_court_order(app, session): """Assert the worker process calls the alteration correctly.""" identifier = 'BC1234567' business = create_business(identifier, legal_type='BC') file_number: Final = '#1234-5678/90' order_date: Final = '2021-01-30T09:56:01+08:00' effect_of_order: Final = 'hasPlan' filing = copy.deepcopy(FILING_HEADER) filing['filing']['alteration'] = {'courtOrder': { 'fileNumber': file_number, 'orderDate': order_date, 'effectOfOrder': effect_of_order } } payment_id = str(random.SystemRandom().getrandbits(0x58)) filing_id = (create_filing(payment_id, filing, business_id=business.id)).id filing_msg = {'filing': {'id': filing_id}} # Test await process_filing(filing_msg, app) # Check outcome final_filing = Filing.find_by_id(filing_id) assert file_number == final_filing.court_order_file_number assert datetime.fromisoformat(order_date) == final_filing.court_order_date assert effect_of_order == final_filing.court_order_effect_of_order
async def test_process_filing_completed(app, session, mocker): """Assert that an AR filling status is set to completed once processed.""" from entity_filer.worker import publish_email_message # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' # mock out the email sender and event publishing mocker.patch('entity_filer.worker.publish_email_message', return_value=None) mocker.patch('entity_filer.worker.publish_event', return_value=None) # setup business = create_business(identifier, legal_type='CP') business_id = business.id filing_id = (create_filing(payment_id, AR_FILING, business.id)).id filing_msg = {'filing': {'id': filing_id}} # TEST await process_filing(filing_msg, app) # Get modified data filing = Filing.find_by_id(filing_id) business = Business.find_by_internal_id(business_id) # check it out assert filing.business_id == business_id assert filing.status == Filing.Status.COMPLETED.value assert filing.transaction_id assert business.last_agm_date assert business.last_ar_date
def test_process_ar_filing(app, session): """Assert that an AR filling can be applied to the model correctly.""" from entity_filer.worker import APP_CONFIG from entity_filer.filing_processors import annual_report # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' # setup business = create_business(identifier, 'CP') business_id = business.id now = datetime.date(2020, 9, 17) ar_date = datetime.date(2020, 8, 5) agm_date = datetime.date(2020, 7, 1) ar = copy.deepcopy(ANNUAL_REPORT) ar['filing']['business']['identifier'] = identifier ar['filing']['annualReport']['annualReportDate'] = ar_date.isoformat() ar['filing']['annualReport'][ 'annualGeneralMeetingDate'] = agm_date.isoformat() filing_meta = FilingMeta() # TEST with freeze_time(now): filing = create_filing(payment_id, ar, business.id) filing_id = filing.id filing_msg = {'filing': {'id': filing_id}} annual_report.process(business, filing.filing_json['filing'], filing_meta=filing_meta) # check it out # NOTE: until we save or convert the dates, they are FakeDate objects, so casting to str() assert str(business.last_agm_date) == str(agm_date) assert str(business.last_ar_date) == str(agm_date)
async def test_process_coa_filing(app, session): """Assert that a COD filling can be applied to the model correctly.""" # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' new_delivery_address = COA_FILING['filing']['changeOfAddress']['offices']['registeredOffice']['deliveryAddress'] new_mailing_address = COA_FILING['filing']['changeOfAddress']['offices']['registeredOffice']['mailingAddress'] # setup business = create_business(identifier) business_id = business.id filing_id = (create_filing(payment_id, COA_FILING, business.id)).id filing_msg = {'filing': {'id': filing_id}} # TEST await process_filing(filing_msg, app) # Get modified data filing = Filing.find_by_id(filing_id) business = Business.find_by_internal_id(business_id) # check it out assert filing.transaction_id assert filing.business_id == business_id assert filing.status == Filing.Status.COMPLETED.value register_office = business.offices.filter_by(office_type='registeredOffice').one_or_none() delivery_address = register_office.addresses.filter_by(address_type='delivery').one_or_none().json compare_addresses(delivery_address, new_delivery_address) mailing_address = register_office.addresses.filter_by(address_type='mailing').one_or_none().json compare_addresses(mailing_address, new_mailing_address)
async def test_worker_alteration(app, session, mocker, orig_legal_type, new_legal_type): """Assert the worker process calls the alteration correctly.""" identifier = 'BC1234567' business = create_business(identifier, legal_type=orig_legal_type) filing = copy.deepcopy(ALTERATION_FILING_TEMPLATE) filing['filing']['business']['legalType'] = orig_legal_type filing['filing']['alteration']['business']['legalType'] = new_legal_type payment_id = str(random.SystemRandom().getrandbits(0x58)) filing_id = (create_filing(payment_id, filing, business_id=business.id)).id filing_msg = {'filing': {'id': filing_id}} # mock out the email sender and event publishing mocker.patch('entity_filer.worker.publish_email_message', return_value=None) mocker.patch('entity_filer.worker.publish_event', return_value=None) mocker.patch( 'entity_filer.filing_processors.filing_components.name_request.consume_nr', return_value=None) mocker.patch( 'entity_filer.filing_processors.filing_components.business_profile.update_business_profile', return_value=None) mocker.patch('legal_api.services.bootstrap.AccountService.update_entity', return_value=None) # Test await process_filing(filing_msg, app) # Check outcome business = Business.find_by_internal_id(business.id) assert business.legal_type == new_legal_type
async def test_cb_subscription_handler(app, session, stan_server, event_loop, client_id, entity_stan, future): """Assert that payment tokens can be retrieved and decoded from the Queue.""" # Call back for the subscription from entity_filer.worker import cb_subscription_handler from entity_filer.worker import get_filing_by_payment_id from legal_api.models import Business from tests.unit import create_filing, AR_FILING, create_business # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' agm_date = datetime.date.fromisoformat( AR_FILING['filing']['annualReport'].get('annualGeneralMeetingDate')) ar_date = datetime.date.fromisoformat( AR_FILING['filing']['annualReport'].get('annualReportDate')) # setup business = create_business(identifier) business_id = business.id create_filing(payment_id, AR_FILING, business.id) # register the handler to test it entity_subject = await subscribe_to_queue(entity_stan, cb_subscription_handler) # add payment tokens to queue await helper_add_payment_to_queue(entity_stan, entity_subject, payment_id=payment_id, status_code='COMPLETED') try: await asyncio.sleep(1) # await asyncio.wait_for(cb_future, 2, loop=event_loop) except Exception as err: print(err) # Get modified data filing = get_filing_by_payment_id(payment_id) business = Business.find_by_internal_id(business_id) # check it out assert filing.transaction_id assert filing.business_id == business_id assert datetime.datetime.date(business.last_agm_date) == agm_date assert datetime.datetime.date(business.last_ar_date) == ar_date
def test_process_cod_filing(app, session): """Assert that an AR filling can be applied to the model correctly.""" # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' end_date = datetime.datetime.utcnow().date() # prep director for no change filing_data = copy.deepcopy(COD_FILING) director1 = create_director( filing_data['filing']['changeOfDirectors']['directors'][0]) # prep director for name change director2 = filing_data['filing']['changeOfDirectors']['directors'][1] director2['officer']['firstName'] = director2['officer']['prevFirstName'] director2['officer']['middleInitial'] = director2['officer'][ 'prevMiddleInitial'] director2['officer']['lastName'] = director2['officer']['prevLastName'] director2 = create_director(director2) # prep director for cease director3 = create_director( filing_data['filing']['changeOfDirectors']['directors'][2]) director_ceased_id = director3.id # prep director for address change director4 = filing_data['filing']['changeOfDirectors']['directors'][3] director4['deliveryAddress']['streetAddress'] = 'should get changed' director4 = create_director(director4) # list of active/ceased directors in test filing ceased_directors, active_directors = active_ceased_lists(COD_FILING) # setup business = create_business(identifier) business.directors.append(director1) business.directors.append(director2) business.directors.append(director3) business.directors.append(director4) business.save() # check that adding the director during setup was successful directors = Director.get_active_directors(business.id, end_date) assert len(directors) == 4 # create filing business_id = business.id filing_id = (create_filing(payment_id, COD_FILING, business.id)).id filing_msg = {'filing': {'id': filing_id}} # TEST process_filing(filing_msg, app) # Get modified data filing = Filing.find_by_id(filing_id) business = Business.find_by_internal_id(business_id) # check it out assert filing.transaction_id assert filing.business_id == business_id assert filing.status == Filing.Status.COMPLETED.value directors = Director.get_active_directors(business.id, end_date) check_directors(business, directors, director_ceased_id, ceased_directors, active_directors)
def test_process_filing_missing_app(app, session): """Assert that a filling will fail with no flask app supplied.""" from entity_filer.worker import process_filing from legal_api.models import Filing # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' # setup business = create_business(identifier) create_filing(payment_id, AR_FILING, business.id) payment_token = {'paymentToken': {'id': payment_id, 'statusCode': Filing.Status.COMPLETED.value}} # TEST with pytest.raises(Exception): process_filing(payment_token, flask_app=None)
def test_incorporation_filing_process(app, session): """Assert that the incorporation object is correctly populated to model objects.""" # setup next_corp_num = 'BC0001095' with patch.object(incorporation_filing, 'get_next_corp_num', return_value=next_corp_num) as mock_get_next_corp_num: filing = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) identifier = 'NR 1234567' filing['filing']['incorporationApplication']['nameRequest']['nrNumber'] = identifier business = create_business(identifier) create_filing('123', filing, business.id) # test incorporation_filing.process(business, filing['filing']) # Assertions assert business.identifier == next_corp_num assert len(business.share_classes.all()) == 2 assert len(business.offices.all()) == 3 # One office is created in create_business method. mock_get_next_corp_num.assert_called_with(filing['filing']['incorporationApplication']['nameRequest']['legalType'], None)
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
def test_incorporation_filing_process_correction(app, session): """Assert that the incorporation correction is correctly populated to model objects.""" # setup next_corp_num = 'BC0001095' with patch.object(incorporation_filing, 'get_next_corp_num', return_value=next_corp_num) as mock_get_next_corp_num: filing = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) create_filing('123', filing) effective_date = datetime.utcnow() filing_rec = Filing(effective_date=effective_date, filing_json=filing) filing_meta = FilingMeta(application_date=filing_rec.effective_date) # test business, filing_rec, filing_meta = incorporation_filing.process(None, filing, filing_rec, filing_meta) # Assertions assert business.identifier == next_corp_num assert business.founding_date == effective_date assert business.legal_type == filing['filing']['incorporationApplication']['nameRequest']['legalType'] assert business.legal_name == business.identifier[2:] + ' B.C. LTD.' assert len(business.share_classes.all()) == 2 assert len(business.offices.all()) == 2 # One office is created in create_business method. mock_get_next_corp_num.assert_called_with(filing['filing']['incorporationApplication']['nameRequest']['legalType']) correction_filing = copy.deepcopy(CORRECTION_INCORPORATION) correction_filing['filing']['incorporationApplication']['nameTranslations'] = [{'name': 'A5 Ltd.'}] del correction_filing['filing']['incorporationApplication']['shareStructure']['shareClasses'][1] corrected_filing_rec = Filing(effective_date=effective_date, filing_json=correction_filing) corrected_filing_meta = FilingMeta(application_date=corrected_filing_rec.effective_date) corrected_business, corrected_filing_rec, corrected_filing_meta =\ incorporation_filing.process(business, correction_filing, corrected_filing_rec, corrected_filing_meta) assert corrected_business.identifier == next_corp_num assert corrected_business.legal_name == \ correction_filing['filing']['incorporationApplication']['nameRequest']['legalName'] assert len(corrected_business.share_classes.all()) == 1
def test_incorporation_filing(app, session): """Assert we can retrieve a new corp number from COLIN and incorporate a business.""" # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) filing = copy.deepcopy(INCORP_FILING) identifier = filing['filing']['incorporationApplication']['nameRequest'][ 'nrNumber'] business = create_business(identifier) filing_id = (create_filing(payment_id, filing, business.id)).id filing_msg = {'filing': {'id': filing_id}} assert business.identifier == 'NR 1234567' process_filing(filing_msg, app) filing = Filing.find_by_id(filing_id) business = Business.find_by_internal_id(filing.business_id) assert business.identifier != 'NR 1234567'
async def test_worker_alteration_court_order(app, session, mocker): """Assert the worker process calls the alteration correctly.""" identifier = 'BC1234567' business = create_business(identifier, legal_type='BC') file_number: Final = '#1234-5678/90' order_date: Final = '2021-01-30T09:56:01+08:00' effect_of_order: Final = 'hasPlan' filing = copy.deepcopy(FILING_HEADER) filing['filing']['alteration'] = {} filing['filing']['alteration']['business'] = BUSINESS filing['filing']['alteration']['contactPoint'] = CONTACT_POINT filing['filing']['alteration']['courtOrder'] = COURT_ORDER filing['filing']['alteration']['courtOrder'][ 'effectOfOrder'] = effect_of_order payment_id = str(random.SystemRandom().getrandbits(0x58)) filing_id = (create_filing(payment_id, filing, business_id=business.id)).id filing_msg = {'filing': {'id': filing_id}} # mock out the email sender and event publishing mocker.patch('entity_filer.worker.publish_email_message', return_value=None) mocker.patch('entity_filer.worker.publish_event', return_value=None) mocker.patch( 'entity_filer.filing_processors.filing_components.name_request.consume_nr', return_value=None) mocker.patch( 'entity_filer.filing_processors.filing_components.business_profile.update_business_profile', return_value=None) mocker.patch('legal_api.services.bootstrap.AccountService.update_entity', return_value=None) # Test await process_filing(filing_msg, app) # Check outcome final_filing = Filing.find_by_id(filing_id) assert file_number == final_filing.court_order_file_number assert datetime.fromisoformat(order_date) == final_filing.court_order_date assert effect_of_order == final_filing.court_order_effect_of_order