def test_post_coa(client): """Assert that the business info for regular (not xpro) business is correct to spec.""" headers = {'content-type': 'application/json'} fake_filing = FILING_HEADER fake_filing['filing']['header']['learEffectiveDate'] = \ f'{fake_filing["filing"]["header"]["date"]}T15:22:39.868757+00:00' fake_filing['filing']['header']['name'] = 'changeOfAddress' fake_filing['filing']['business']['identifier'] = 'CP0001965' fake_filing['filing']['changeOfAddress'] = CHANGE_OF_ADDRESS fake_filing['filing']['changeOfAddress']['offices']['registeredOffice']['deliveryAddress']['addressCountry'] = \ 'Canada' fake_filing['filing']['changeOfAddress']['offices']['registeredOffice']['mailingAddress']['addressCountry'] = \ 'Canada' rv = client.post('/api/v1/businesses/CP/CP0001965/filings/changeOfAddress', data=json.dumps(fake_filing), headers=headers) assert 201 == rv.status_code is_valid, errors = validate(rv.json, 'filing', validate_schema=True) if errors: for err in errors: print('\nERROR MESSAGE:') print(err.message) assert is_valid assert "changeOfAddress" == rv.json['filing']['header']['name'] ids.append(str(rv.json['filing']['changeOfAddress']['eventId'])) assert str(rv.json['filing']['changeOfAddress']['eventId']) in ids
def test_invalid_ar_filing(): """Assert that the schema is performing as expected.""" iar = { 'filing': { 'header': { 'name': 'annualReport', 'date': '2019-04-08' }, 'business': { 'cacheId': 1, 'foundingDate': '2007-04-08', 'identifier': 'CP1234567', 'lastLedgerTimestamp': '2019-04-15T20:05:49.068272+00:00', 'legalName': 'legal name - CP1234567' } } } is_valid, errors = validate(iar, 'filing') # if errors: # for err in errors: # print(err.message) print(errors) assert not is_valid
def test_invalid_todo_name(): """Assert that the schema rejects a todo item with an invalid name.""" todo = { 'invalid': { 'business': { 'cacheId': 1, 'foundingDate': '2007-04-08T00:00:00+00:00', 'identifier': 'CP0002098', 'lastLedgerTimestamp': '2019-04-15T20:05:49.068272+00:00', 'legalName': 'Legal Name - CP0002098' }, 'header': { 'name': 'annualReport', 'ARFilingYear': 2019, 'status': 'NEW' } } } is_valid, errors = validate(todo, 'todo') # if errors: # for err in errors: # print(err.message) print(errors) assert not is_valid
def test_valid_task_todo(): """Assert that the schema accepts a valid todo task.""" task = { 'task': { 'todo': { 'business': { 'cacheId': 1, 'foundingDate': '2007-04-08', 'identifier': 'CP0002098', 'lastLedgerTimestamp': '2019-04-15T20:05:49.068272+00:00', 'legalName': 'Legal Name - CP0002098' }, 'header': { 'name': 'annualReport', 'ARFilingYear': 2019, 'status': 'NEW' } } }, 'order': 2, 'enabled': False } is_valid, errors = validate(task, 'task') # if errors: # for err in errors: # print(err.message) print(errors) assert is_valid
def test_valid_multi_filing(): """Assert that the filing schema is performing as expected with multiple filings included.""" filing = { 'filing': { 'header': { 'name': 'annualReport', 'date': '2019-04-08', 'certifiedBy': 'full legal name', 'email': '*****@*****.**' }, 'business': { 'cacheId': 1, 'foundingDate': '2007-04-08', 'identifier': 'CP1234567', 'lastLedgerTimestamp': '2019-04-15T20:05:49.068272+00:00', 'legalName': 'legal name - CP1234567' }, 'annualReport': ANNUAL_REPORT, 'changeOfDirectors': CHANGE_OF_DIRECTORS, 'changeOfAddress': CHANGE_OF_ADDRESS } } is_valid, errors = validate(filing, 'filing') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_valid_cod_filing(): """Assert that the Change of Directors filing schema is performing as expected.""" filing = { 'filing': { 'header': { 'name': 'changeOfDirectors', 'date': '2019-04-08', 'certifiedBy': 'full legal name', 'email': '*****@*****.**' }, 'business': { 'cacheId': 1, 'foundingDate': '2007-04-08', 'identifier': 'CP1234567', 'lastLedgerTimestamp': '2019-04-15T20:05:49.068272+00:00', 'legalName': 'legal name - CP1234567' }, 'changeOfDirectors': CHANGE_OF_DIRECTORS } } is_valid, errors = validate(filing, 'filing') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_sp_registration_schema(): """Assert that the sole proprietor registration is valid.""" filing = copy.deepcopy(FILING_HEADER) filing['filing']['business']['taxId'] = '123456789' filing['filing']['business']['natureOfBusiness'] = 'A sample business' filing['filing']['business']['naics'] = {} filing['filing']['business']['naics']['naicsCode'] = '919110' filing['filing']['business']['naics']['naicsDescription'] = \ 'This Canadian industry comprises establishments of foreign governments \ in Canada primarily engaged in governmental service activities.' registration_json = copy.deepcopy(REGISTRATION) registration_json['nameRequest']['legalType'] = 'SP' registration_json['businessType'] = 'SP' registration_json['parties'][0]['roles'] = [{ 'roleType': 'Completing Party', 'appointmentDate': '2022-01-01' }, { 'roleType': 'Proprietor', 'appointmentDate': '2022-01-01' }] del registration_json['parties'][1] filing['filing']['registration'] = registration_json is_valid, errors = validate(filing, 'filing') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_post_coa(client): """Assert that the business info for regular (not xpro) business is correct to spec.""" headers = {'content-type': 'application/json'} fake_filing = { "filing": { "business": { "cacheId": 0, "corpState": "ACT", "foundingDate": "2004-04-28", "identifier": "CP0001965", "jurisdiction": "BC", "lastAgmDate": "2017-12-31", "lastArFiledDate": "2019-05-23", "lastLedgerTimestamp": "2019-05-23T22:21:12-00:00", "legalName": "CENTRAL INTERIOR COMMUNITY SERVICES CO-OP", "status": "In Good Standing", "type": "CP" }, "changeOfAddress": { "certifiedBy": "Joe Smith", "deliveryAddress": { "actions": ["addressChanged"], "addressCity": "WILLIAMS LAKE", "addressCountry": "CANADA", "addressRegion": "BC", "postalCode": "V2G 1J6", "streetAddress": "51 4TH AVENUE SOUTH test", }, "email": "*****@*****.**", "mailingAddress": { "actions": ["addressChanged"], "addressCity": "WILLIAMS LAKE", "addressCountry": "CANADA", "addressRegion": "BC", "postalCode": "V2G 1J6", "streetAddress": "51 4TH AVENUE SOUTH test", } }, "header": { "date": "2019-05-23", "name": "changeOfAddress" } } } rv = client.post('/api/v1/businesses/CP0001965/filings/changeOfAddress', data=json.dumps(fake_filing), headers=headers) assert 201 == rv.status_code is_valid, errors = validate(rv.json, 'filing', validate_schema=True) if errors: for err in errors: print('\nERROR MESSAGE:') print(err.message) assert is_valid assert "changeOfAddress" == rv.json['filing']['header']['name'] ids.append(str(rv.json['filing']['changeOfAddress']['eventId'])) assert str(rv.json['filing']['changeOfAddress']['eventId']) in ids
def test_post_ar_with_coa_cod(client): """Assert that business for regular (not xpro) business is correct to spec.""" headers = {'content-type': 'application/json'} fake_filing = ANNUAL_REPORT fake_filing['filing']['changeOfAddress'] = CHANGE_OF_ADDRESS fake_filing['filing']['changeOfAddress']['deliveryAddress'][ 'addressCountry'] = 'Canada' fake_filing['filing']['changeOfAddress']['mailingAddress'][ 'addressCountry'] = 'Canada' fake_filing['filing']['changeOfDirectors'] = CHANGE_OF_DIRECTORS for director in fake_filing['filing']['changeOfDirectors']['directors']: director['deliveryAddress']['addressCountry'] = 'Canada' fake_filing['filing']['business']['identifier'] = 'CP0001965' fake_filing['filing']['annualReport'][ 'annualGeneralMeetingDate'] = '2019-04-08' fake_filing['filing']['annualReport']['annualReportDate'] = '2019-04-08' rv = client.post('/api/v1/businesses/CP0001965/filings/annualReport', data=json.dumps(fake_filing), headers=headers) assert 201 == rv.status_code is_valid, errors = validate(rv.json, 'filing', validate_schema=True) if errors: for err in errors: print('\nERROR MESSAGE:') print(err.message) assert is_valid ar_ids.append(str(rv.json['filing']['annualReport']['eventId'])) coa_ids.append(str(rv.json['filing']['changeOfAddress']['eventId'])) cod_ids.append(str(rv.json['filing']['changeOfDirectors']['eventId']))
def test_invalid_coa_filing_bcorp(): """Assert that the Change of Address filing schema conditionals are performing as expected.""" coa_arr = CHANGE_OF_ADDRESS coa_arr['legalType'] = 'BC' iar = { 'filing': { 'header': { 'name': 'changeOfAddress', 'date': '', 'certifiedBy': 'full legal name', 'email': '*****@*****.**' }, 'business': { 'cacheId': 1, 'foundingDate': '2007-04-08T00:00:00+00:00', 'identifier': 'CP1234567', 'lastLedgerTimestamp': '2019-04-15T20:05:49.068272+00:00', 'legalName': 'legal name - CP1234567' }, 'changeOfAddress': coa_arr } } is_valid, errors = validate(iar, 'filing') if errors: for err in errors: print(err.message) print(errors) assert not is_valid
def send_filing(app: Flask = None, filing: dict = None, filing_id: str = None): """Post to colin-api with filing.""" clean_none(filing) # validate schema is_valid, errors = validate(filing, 'filing') if errors: for err in errors: app.logger.error(err.message) return None else: filing_type = filing['filing']['header']['name'] app.logger.debug( f'Filing {filing_id} in colin for {filing["filing"]["business"]["identifier"]}.' ) r = requests.post( f'{app.config["COLIN_URL"]}/{filing["filing"]["business"]["identifier"]}/filings/' f'{filing_type}', json=filing) if not r or r.status_code != 201: app.logger.error( f'Filing {filing_id} not created in colin {filing["filing"]["business"]["identifier"]}.' ) # raise Exception return None # if it's an AR containing multiple filings it will have multiple colinIds return r.json()['filing']['header']['colinIds']
def test_invalid_task_missing_enabled(): """Assert that the schema rejects a task missing the 'enabled' property.""" task = { 'task': { 'todo': { 'business': { 'cacheId': 1, 'foundingDate': '2007-04-08T00:00:00+00:00', 'identifier': 'CP0002098', 'lastLedgerTimestamp': '2019-04-15T20:05:49.068272+00:00', 'legalName': 'Legal Name - CP0002098' }, 'header': { 'name': 'annualReport', 'ARFilingYear': 2019, 'status': 'NEW' } } }, 'order': 2 } is_valid, errors = validate(task, 'task') # if errors: # for err in errors: # print(err.message) print(errors) assert not is_valid
def test_invalid_schema_offices(schema): """Assert that the business document schema is invalid when offices are invalid.""" invalid_schema = copy.deepcopy(schema) del invalid_schema['offices']['registeredOffice']['deliveryAddress'][ 'streetAddress'] is_valid, errors = validate(invalid_schema, 'business_document') assert not is_valid
def test_validate_invalid_court_order(): """Assert invalid if required fields are missing.""" order_json = copy.deepcopy(COURT_ORDER) del order_json['fileNumber'] is_valid, errors = validate(order_json, 'court_order') assert not is_valid
def test_get_business_info(session, client): """Assert that the business info can be received in a valid JSONSchema format.""" factory_business_model(legal_name='legal_name', identifier='CP7654321', founding_date=datetime.utcfromtimestamp(0), last_modified=datetime.utcfromtimestamp(0), fiscal_year_end_date=None, tax_id=None, dissolution_date=None) rv = client.get('/api/v1/businesses/CP7654321') print('business json', rv.json) assert rv.json['business']['identifier'] == 'CP7654321' print('valid schema?', registry_schemas.validate(rv.json, 'business')) assert registry_schemas.validate(rv.json, 'business')
def test_valid_vehicle_MV(): """Assert that the schema is performing as expected for MV type.""" is_valid, errors = validate(VEHICLE_COLLATERAL, 'vehicleCollateral', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_valid_ar_filing(): """Assert that the schema is performing as expected.""" is_valid, errors = validate(AR, 'filing') # if errors: # for err in errors: # print(err.message) print(errors) assert is_valid
def test_conversion_schema(): """Assert that the JSONSchema validator is working.""" is_valid, errors = validate(CONVERSION, 'conversion') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_valid_schema(schema): """Assert that the schema is performing as expected.""" is_valid, errors = validate(schema, 'business_document') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_conversion_filing_schema(): """Assert that the JSONSchema validator is working.""" is_valid, errors = validate(CONVERSION_FILING_TEMPLATE, 'filing') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_valid_person(): """Assert that the schema is performing as expected for an individual name.""" is_valid, errors = validate(PERSON_NAME, 'personName', 'common') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_incorporation_filing_schema(): """Assert that the JSONSchema validator is working.""" is_valid, errors = validate(INCORPORATION_FILING_TEMPLATE, 'filing') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_valid_comment_filing(): """Assert that the schema is performing as expected for filing comments.""" is_valid, errors = validate(COMMENT_FILING, 'comment') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_valid_no_submitter(): """Assert that submitter id is not required.""" comment = copy.deepcopy(COMMENT_FILING) del comment['comment']['submitterId'] is_valid, errors = validate(comment, 'comment') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_invalid_null_submitter(): """Assert that submitter id cannot be null.""" comment = copy.deepcopy(COMMENT_FILING) comment['comment']['submitterId'] = None is_valid, errors = validate(comment, 'comment') if errors: for err in errors: print(err.message) print(errors) assert not is_valid
def test_valid_address(): """Assert that the schema is performing as expected.""" is_valid, errors = validate(ADDRESS, 'address') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_valid_filing(filing_data): """Assert that the schema is performing as expected.""" is_valid, errors = validate(filing_data, 'filing') # print filing name for easier debugging print(filing_data['filing']['header']['name']) print(errors) assert is_valid
def test_court_order_filing_schema(): """Assert that the JSONSchema validator is working.""" is_valid, errors = validate(COURT_ORDER_FILING_TEMPLATE, 'filing') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_transition_schema(): """Assert that the JSONSchema validator is working.""" is_valid, errors = validate(TRANSITION, 'transition') if errors: for err in errors: print(err.message) print(errors) assert is_valid
def test_registrars_order_filing_schema(): """Assert that the JSONSchema validator is working.""" is_valid, errors = validate(REGISTRARS_ORDER_FILING_TEMPLATE, 'filing') if errors: for err in errors: print(err.message) print(errors) assert is_valid