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_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(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'
def test_change_of_name_process(app, session): """Assert that the legal name is changed.""" # setup new_name = 'new legal_name' identifier = 'CP1234567' con = {'changeOfName': {'legalName': new_name}} business = create_business(identifier) business.legal_name = 'original name' filing_meta = FilingMeta() # test change_of_name.process(business, con, filing_meta) # validate assert business.legal_name == new_name
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
async def test_worker_alteration(app, session, 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 filing['filing']['alteration']['nameTranslations'] = [{'name': 'A5 Ltd.'}] 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 business = Business.find_by_internal_id(business.id) assert business.legal_type == new_legal_type
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_change_of_name_process(app, session): """Assert that the voluntary dissolution date is set.""" # setup dissolution_date = '2020-07-01' has_liabilities = False identifier = 'CP1234567' con = { 'voluntaryDissolution': { 'dissolutionDate': dissolution_date, 'hasLiabilities': has_liabilities } } business = create_business(identifier) business.dissolution_date = None # test voluntary_dissolution.process(business, con) # validate assert business.dissolution_date == date.fromisoformat(dissolution_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(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
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_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
async def test_worker_court_order(app, session): """Assert that the court order object is correctly populated to model objects.""" identifier = 'BC1234567' business = create_business(identifier, legal_type='BC') filing = copy.deepcopy(COURT_ORDER_FILING_TEMPLATE) filing['filing']['business']['identifier'] = identifier 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 filing['filing']['courtOrder']['fileNumber'] == final_filing.court_order_file_number assert filing['filing']['courtOrder']['effectOfOrder'] == final_filing.court_order_effect_of_order assert filing['filing']['courtOrder']['orderDetails'] == final_filing.order_details
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 legal_api.models import Business, Filing from registry_schemas.example_data import ANNUAL_REPORT from tests.unit import create_filing, create_business # vars identifier = 'CP1234567' # setup business = create_business(identifier) business_id = business.id filing = create_filing('test_pay_id', ANNUAL_REPORT, business.id) filing_id = filing.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_filing_to_queue(entity_stan, entity_subject, filing_id=filing_id) try: await asyncio.sleep(1) # await asyncio.wait_for(cb_future, 2, loop=event_loop) except Exception as err: print(err) # Get modified data business = Business.find_by_internal_id(business_id) filing = Filing.find_by_id(filing_id) # check it out assert filing.transaction_id assert filing.business_id == business_id
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 legal_api.models import Business, Filing # 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 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)
def test_voluntary_dissolution(app, session): """Assert that the dissolution is processed. Not a very deep set of tests yet.""" # setup filing_json = copy.deepcopy(FILING_HEADER) dissolution_date = '2021-05-06T07:01:01.000000+00:00' # this will be 1 min after midnight dissolution_type = 'voluntary' # dissolution_date = '2019-04-15T20:05:49.068272+00:00' # this will be 1 min after midnight has_liabilities = False identifier = 'BC1234567' legal_type = 'BEN' filing_json['filing']['business']['identifier'] = identifier filing_json['filing']['business']['legalType'] = legal_type filing_json['filing']['dissolution'] = DISSOLUTION filing_json['filing']['dissolution']['dissolutionDate'] = dissolution_date filing_json['filing']['dissolution']['dissolutionType'] = dissolution_type filing_json['filing']['dissolution']['hasLiabilities'] = has_liabilities business = create_business(identifier, legal_type=legal_type) business.dissolution_date = None business_id = business.id filing_meta = FilingMeta() # test dissolution.process(business, filing_json['filing'], filing_meta) business.save() # validate assert business.dissolution_date == datetime.fromisoformat( dissolution_date) custodial_office = session.query(Business, Office). \ filter(Business.id == Office.business_id). \ filter(Business.id == business_id). \ filter(Office.office_type == OfficeType.CUSTODIAL). \ one_or_none() assert custodial_office
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' coa_filing = copy.deepcopy(FILING_HEADER) coa_filing['filing']['changeOfAddress'] = copy.deepcopy(CHANGE_OF_ADDRESS) 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_technical_correction_ar(app, session): """Assert we can create a business based on transition filing.""" filing_data = copy.deepcopy(ANNUAL_REPORT) business = create_business(filing_data['filing']['business']['identifier']) business_identifier = business.identifier payment_id = str(random.SystemRandom().getrandbits(0x58)) filing = (create_filing(payment_id, filing_data, business.id)) filing_id = filing.id filing_msg = {'filing': {'id': filing.id}} # sanity check # that it is an AR, and it is based on the ANNUAL_REPORT template assert filing.json['filing']['annualReport'] assert filing.json['filing']['annualReport']['annualGeneralMeetingDate'] \ == ANNUAL_REPORT['filing']['annualReport']['annualGeneralMeetingDate'] # and the businesses last AR date is null assert not business.last_ar_date # subvert the filing technical_correction_filing = copy.deepcopy(FILING_HEADER) technical_correction_filing['specialResolution'] = copy.deepcopy( SPECIAL_RESOLUTION) filing.tech_correction_json = technical_correction_filing # over ride the state and skip state setting listeners for this test filing.skip_status_listener = True filing._status = 'PENDING' filing.save() # Test await process_filing(filing_msg, app) # Check outcome business = Business.find_by_identifier(business_identifier) filing = FilingCore.find_by_id(filing_id) assert not business.last_ar_date assert filing.filing_type == 'annualReport'
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 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 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() # TEST with freeze_time(now): filing = create_filing(payment_id, ar, business.id) filing_id = filing.id filing_msg = {'filing': {'id': filing_id}} 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 datetime.datetime.date(business.last_agm_date) == agm_date assert datetime.datetime.date(business.last_ar_date) == agm_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 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_voluntary_dissolution(app, session): """Assert that the voluntary dissolution date is set.""" # setup filing_json = copy.deepcopy(FILING_JSON) dissolution_date = '2021-05-06T07:01:01.000000+00:00' # this will be 1 min after midnight # dissolution_date = '2019-04-15T20:05:49.068272+00:00' # this will be 1 min after midnight # '2019-04-15T20:05:49.068272+00:00' has_liabilities = False identifier = 'BC1234567' legal_type = 'BEN' filing_json['filing']['business']['identifier'] = identifier filing_json['filing']['business']['legalType'] = legal_type filing_json['filing']['voluntaryDissolution']['dissolutionDate'] = dissolution_date filing_json['filing']['voluntaryDissolution']['hasLiabilities'] = has_liabilities business = create_business(identifier, legal_type=legal_type) business.dissolution_date = None # test voluntary_dissolution.process(business, filing_json) # validate assert business.dissolution_date == date.fromisoformat(dissolution_date)
def test_cease_aliases(app, session): """Assert that aliases are removed.""" # setup identifier = 'BC1234567' alias_1 = 'A1 LTD.' alias_2 = 'A2 LTD.' alias_3 = 'A3 LTD.' business = create_business(identifier) business.aliases.append(Alias(alias=alias_1, type=Alias.AliasType.TRANSLATION.value)) business.aliases.append(Alias(alias=alias_2, type=Alias.AliasType.TRANSLATION.value)) business.save() assert len(business.aliases.all()) == 2 component = {'nameTranslations': [ {'name': alias_3} ]} # test aliases.update_aliases(business, component.get('nameTranslations')) # validate business_aliases = business.aliases.all() assert 1 == len(business_aliases) assert business_aliases[0].alias == alias_3.upper()
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
async def test_process_combined_filing(app, session, mocker): """Assert that an AR filling can be applied to the model correctly.""" # 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) # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' business = create_business(identifier, legal_type='CP') agm_date = datetime.date.fromisoformat( COMBINED_FILING['filing']['annualReport'].get( 'annualGeneralMeetingDate')) ar_date = datetime.date.fromisoformat( COMBINED_FILING['filing']['annualReport'].get('annualReportDate')) new_delivery_address = COMBINED_FILING['filing']['changeOfAddress'][ 'offices']['registeredOffice'][ 'deliveryAddress'] # noqa: E501; line too long by 1 char new_mailing_address = COMBINED_FILING['filing']['changeOfAddress'][ 'offices']['registeredOffice']['mailingAddress'] end_date = datetime.datetime.utcnow().date() # prep director for no change filing_data = copy.deepcopy(COMBINED_FILING) directors = filing_data['filing']['changeOfDirectors']['directors'] director_party1 = create_party(business.id, directors[0]) role1 = { 'roleType': 'director', 'appointmentDate': directors[0].get('appointmentDate'), 'cessationDate': directors[0].get('cessationDate') } director1 = create_role(party=director_party1, role_info=role1) # prep director for name change director_party2_dict = directors[1] director_party2_dict['officer']['firstName'] = director_party2_dict[ 'officer']['prevFirstName'] director_party2_dict['officer']['middleInitial'] = director_party2_dict[ 'officer']['prevMiddleInitial'] director_party2_dict['officer']['lastName'] = director_party2_dict[ 'officer']['prevLastName'] director_party2 = create_party(business.id, director_party2_dict) role2 = { 'roleType': 'Director', 'appointmentDate': director_party2_dict.get('appointmentDate'), 'cessationDate': director_party2_dict.get('cessationDate') } director2 = create_role(party=director_party2, role_info=role2) # prep director for cease director_party3 = create_party(business.id, directors[2]) role3 = { 'roleType': 'director', 'appointmentDate': directors[3].get('appointmentDate'), 'cessationDate': directors[3].get('cessationDate') } director3 = create_role(party=director_party3, role_info=role3) # prep director for address change director_party4_dict = directors[3] director_party4_dict['deliveryAddress'][ 'streetAddress'] = 'should get changed' director_party4 = create_party(business.id, director_party4_dict) role4 = { 'roleType': 'director', 'appointmentDate': director_party4_dict.get('appointmentDate'), 'cessationDate': director_party4_dict.get('cessationDate') } director4 = create_role(party=director_party4, role_info=role4) # list of active/ceased directors in test filing ceased_directors, active_directors = active_ceased_lists(COMBINED_FILING) # setup business.party_roles.append(director1) business.party_roles.append(director2) business.party_roles.append(director3) business.party_roles.append(director4) business.save() director_ceased_id = director3.id # check that adding the directors during setup was successful directors = PartyRole.get_parties_by_role( business.id, PartyRole.RoleTypes.DIRECTOR.value) assert len(directors) == 4 business_id = business.id filing_id = (create_filing(payment_id, COMBINED_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 assert datetime.datetime.date(business.last_agm_date) == agm_date assert datetime.datetime.date(business.last_ar_date) == ar_date # check address filing 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) # check director filing directors = PartyRole.get_active_directors(business.id, end_date) check_directors(business, directors, director_ceased_id, ceased_directors, active_directors)
async def test_process_cod_mailing_address(app, session): """Assert that a COD address change 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_TWO_ADDRESSES) # setup business = create_business(identifier) business.save() directors = PartyRole.get_active_directors(business.id, end_date) assert len(directors) == 0 # create filing business_id = business.id filing_data['filing']['changeOfDirectors']['directors'][0]['actions'] = [ 'appointed' ] filing_data['filing']['changeOfDirectors']['directors'][1]['actions'] = [ 'appointed' ] filing_id = (create_filing(payment_id, filing_data, business_id)).id filing_msg = {'filing': {'id': filing_id}} # TEST await process_filing(filing_msg, app) business = Business.find_by_internal_id(business_id) directors = PartyRole.get_active_directors(business.id, end_date) has_mailing = list( filter(lambda x: x.party.mailing_address is not None, directors)) no_mailing = list( filter(lambda x: x.party.mailing_address is None, directors)) assert len(has_mailing) == 1 assert has_mailing[0].party.mailing_address.street == 'test mailing 1' assert no_mailing[0].party.mailing_address is None # Add/update mailing address to a director del filing_data['filing']['changeOfDirectors']['directors'][0] filing_data['filing']['changeOfDirectors']['directors'][0]['actions'] = [ 'addressChanged' ] mailing_address = { 'streetAddress': 'test mailing 2', 'streetAddressAdditional': 'test line 1', 'addressCity': 'testcity', 'addressCountry': 'Canada', 'addressRegion': 'BC', 'postalCode': 'T3S T3R', 'deliveryInstructions': 'director1' } filing_data['filing']['changeOfDirectors']['directors'][0][ 'mailingAddress'] = mailing_address payment_id = str(random.SystemRandom().getrandbits(0x58)) filing_id = (create_filing(payment_id, filing_data, business_id)).id filing_msg = {'filing': {'id': filing_id}} await process_filing(filing_msg, app) business = Business.find_by_internal_id(business_id) directors = PartyRole.get_active_directors(business.id, end_date) # Get modified data filing = Filing.find_by_id(filing_id) # check it out assert len( list(filter(lambda x: x.party.mailing_address is not None, directors))) == 2 assert filing.business_id == business_id assert filing.status == Filing.Status.COMPLETED.value
async 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' business = create_business(identifier) end_date = datetime.datetime.utcnow().date() # prep director for no change filing_data = copy.deepcopy(COD_FILING) directors = filing_data['filing']['changeOfDirectors']['directors'] director_party1 = create_party(business.id, directors[0]) role1 = { 'roleType': 'director', 'appointmentDate': directors[0].get('appointmentDate'), 'cessationDate': directors[0].get('cessationDate') } director1 = create_role(party=director_party1, role_info=role1) # prep director for name change director_party2_dict = directors[1] director_party2_dict['officer']['firstName'] = director_party2_dict[ 'officer']['prevFirstName'] director_party2_dict['officer']['middleInitial'] = director_party2_dict[ 'officer']['prevMiddleInitial'] director_party2_dict['officer']['lastName'] = director_party2_dict[ 'officer']['prevLastName'] director_party2 = create_party(business.id, director_party2_dict) role2 = { 'roleType': 'director', 'appointmentDate': director_party2_dict.get('appointmentDate'), 'cessationDate': director_party2_dict.get('cessationDate') } director2 = create_role(party=director_party2, role_info=role2) # prep director for cease director_party3 = create_party(business.id, directors[2]) role3 = { 'roleType': 'director', 'appointmentDate': directors[3].get('appointmentDate'), 'cessationDate': directors[3].get('cessationDate') } director3 = create_role(party=director_party3, role_info=role3) # prep director for address change director_party4_dict = directors[3] director_party4_dict['deliveryAddress'][ 'streetAddress'] = 'should get changed' director_party4 = create_party(business.id, director_party4_dict) role4 = { 'roleType': 'director', 'appointmentDate': director_party4_dict.get('appointmentDate'), 'cessationDate': director_party4_dict.get('cessationDate') } director4 = create_role(party=director_party4, role_info=role4) # list of active/ceased directors in test filing ceased_directors, active_directors = active_ceased_lists(COD_FILING) # setup business.party_roles.append(director1) business.party_roles.append(director2) business.party_roles.append(director3) business.party_roles.append(director4) business.save() director_ceased_id = director3.id # check that adding the director during setup was successful directors = PartyRole.get_parties_by_role( business.id, PartyRole.RoleTypes.DIRECTOR.value) 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 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 directors = PartyRole.get_active_directors(business.id, end_date) check_directors(business, directors, director_ceased_id, ceased_directors, active_directors)
def test_process_cod_mailing_address(app, session): """Assert that an AR filling can be applied to the model correctly.""" import copy from legal_api.models import Business, Director, Filing from entity_filer.worker import process_filing from entity_filer.worker import get_filing_by_payment_id # 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_TWO_ADDRESSES) # setup business = create_business(identifier) business.save() directors = Director.get_active_directors(business.id, end_date) assert len(directors) == 0 # create filing business_id = business.id filing_data['filing']['changeOfDirectors']['directors'][0]['actions'] = ['appointed'] filing_data['filing']['changeOfDirectors']['directors'][1]['actions'] = ['appointed'] create_filing(payment_id, filing_data, business.id) payment_token = {'paymentToken': {'id': payment_id, 'statusCode': Filing.Status.COMPLETED.value}} # TEST process_filing(payment_token, app) filing = get_filing_by_payment_id(payment_id) business = Business.find_by_internal_id(business_id) directors = Director.get_active_directors(business.id, end_date) has_mailing = list(filter(lambda x: x.mailing_address is not None, directors)) no_mailing = list(filter(lambda x: x.mailing_address is None, directors)) assert len(has_mailing) == 1 assert has_mailing[0].mailing_address.street == 'test mailing 1' assert no_mailing[0].mailing_address is None # Add/update mailing address to a director del filing_data['filing']['changeOfDirectors']['directors'][0] filing_data['filing']['changeOfDirectors']['directors'][0]['actions'] = ['addressChanged'] mailing_address = { 'streetAddress': 'test mailing 2', 'streetAddressAdditional': 'test line 1', 'addressCity': 'testcity', 'addressCountry': 'Canada', 'addressRegion': 'BC', 'postalCode': 'T3S T3R', 'deliveryInstructions': 'director1' } filing_data['filing']['changeOfDirectors']['directors'][0]['mailingAddress'] = mailing_address payment_id = str(random.SystemRandom().getrandbits(0x58)) create_filing(payment_id, filing_data, business.id) payment_token = {'paymentToken': {'id': payment_id, 'statusCode': Filing.Status.COMPLETED.value}} process_filing(payment_token, app) filing = get_filing_by_payment_id(payment_id) business = Business.find_by_internal_id(business_id) directors = Director.get_active_directors(business.id, end_date) # Get modified data filing = get_filing_by_payment_id(payment_id) business = Business.find_by_internal_id(business_id) # check it out assert len(list(filter(lambda x: x.mailing_address is not None, directors))) == 2 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)
def test_process_cod_filing(app, session): """Assert that an AR filling can be applied to the model correctly.""" from legal_api.models import Business, Director, Filing from entity_filer.worker import process_filing # 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_combined_filing(app, session): """Assert that an AR filling can be applied to the model correctly.""" from legal_api.models import Business, Director, Filing from entity_filer.worker import process_filing # vars payment_id = str(random.SystemRandom().getrandbits(0x58)) identifier = 'CP1234567' agm_date = datetime.date.fromisoformat( COMBINED_FILING['filing']['annualReport'].get( 'annualGeneralMeetingDate')) ar_date = datetime.date.fromisoformat( COMBINED_FILING['filing']['annualReport'].get('annualReportDate')) new_delivery_address = COMBINED_FILING['filing']['changeOfAddress'][ 'offices']['registeredOffice'][ 'deliveryAddress'] # noqa: E501; line too long by 1 char new_mailing_address = COMBINED_FILING['filing']['changeOfAddress'][ 'offices']['registeredOffice']['mailingAddress'] end_date = datetime.datetime.utcnow().date() # prep director for no change filing_data = copy.deepcopy(COMBINED_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(COMBINED_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 business_id = business.id filing_id = (create_filing(payment_id, COMBINED_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 assert datetime.datetime.date(business.last_agm_date) == agm_date assert datetime.datetime.date(business.last_ar_date) == agm_date # check address filing 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) # check director filing directors = Director.get_active_directors(business.id, end_date) check_directors(business, directors, director_ceased_id, ceased_directors, active_directors)