def test_alteration(session, use_nr, new_name, legal_type, nr_type, should_pass, num_errors): """Test that a valid Alteration without NR correction passes validation.""" # setup identifier = 'BC1234567' business = factory_business(identifier) f = copy.deepcopy(ALTERATION_FILING_TEMPLATE) f['filing']['header']['identifier'] = identifier f['filing']['alteration']['business']['legalType'] = legal_type if use_nr: f['filing']['business']['identifier'] = identifier f['filing']['business']['legalName'] = 'legal_name-BC1234567' f['filing']['alteration']['nameRequest']['nrNumber'] = identifier f['filing']['alteration']['nameRequest']['legalName'] = new_name f['filing']['alteration']['nameRequest']['legalType'] = legal_type nr_json = { "state": "APPROVED", "expirationDate": "", "requestTypeCd": nr_type, "names": [{ "name": new_name, "state": "APPROVED", "consumptionDate": "" }] } nr_response = MockResponse(nr_json, 200) with patch.object(NameXService, 'query_nr_number', return_value=nr_response): err = validate(business, f) else: del f['filing']['alteration']['nameRequest'] err = validate(business, f) if err: print(err.msg) if should_pass: # check that validation passed assert None is err else: # check that validation failed assert err assert HTTPStatus.BAD_REQUEST == err.code assert len(err.msg) == num_errors
def test_validate_coa_basic(session, test_name, now, delivery_region, delivery_country, mailing_region, mailing_country, expected_code, expected_msg): # pylint: disable=too-many-arguments """Assert that a basic COA can be validated.""" # setup identifier = 'CP1234567' founding_date = now - datedelta.YEAR business = Business(identifier=identifier, last_ledger_timestamp=founding_date) business.founding_date = founding_date f = copy.deepcopy(FILING_HEADER) f['filing']['header']['date'] = now.isoformat() f['filing']['header']['name'] = 'changeOfDirectors' f['filing']['business']['identifier'] = identifier f['filing']['changeOfAddress'] = CHANGE_OF_ADDRESS office = f['filing']['changeOfAddress']['offices']['registeredOffice'] office['deliveryAddress']['addressRegion'] = delivery_region office['deliveryAddress']['addressCountry'] = delivery_country office['mailingAddress']['addressRegion'] = mailing_region office['mailingAddress']['addressCountry'] = mailing_country # perform test with freeze_time(now): err = validate(business, f) # validate outcomes if expected_code: assert err.code == expected_code assert lists_are_equal(err.msg, expected_msg) else: assert err is None
def test_valid_coa_correction(session): """Test that a valid COA correction passes validation.""" # setup identifier = 'CP1234567' name = 'changeOfAddress' business = factory_business(identifier) coa = copy.deepcopy(FILING_TEMPLATE) coa['filing']['header']['name'] = name coa['filing'][name] = CHANGE_OF_ADDRESS corrected_filing = factory_completed_filing(business, coa) f = copy.deepcopy(CORRECTION_COA) f['filing']['header']['identifier'] = identifier f['filing']['correction']['correctedFilingId'] = corrected_filing.id f['filing'][name]['offices']['registeredOffice']['deliveryAddress'][ 'addressCountry'] = 'CA' f['filing'][name]['offices']['registeredOffice']['mailingAddress'][ 'addressCountry'] = 'CA' err = validate(business, f) if err: print(err.msg) # check that validation passed assert None is err
def test_validate_incorporation_effective_date(session, test_name, effective_date, expected_code, expected_msg): """Assert that validator validates share class correctly.""" f = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) f['filing']['header'] = { 'name': 'incorporationApplication', 'date': '2019-04-08', 'certifiedBy': 'full name', 'email': '*****@*****.**', 'filingId': 1 } if effective_date is not None: f['filing']['header']['effectiveDate'] = effective_date f['filing']['incorporationApplication'] = copy.deepcopy(INCORPORATION) # perform test with freeze_time(now): err = validate(business, f) # validate outcomes if expected_code: assert err.code == expected_code assert lists_are_equal(err.msg, expected_msg) else: assert err is None
def test_valid_nr_correction(session): """Test that a valid NR correction passes validation.""" # setup identifier = 'BC1234567' business = factory_business(identifier) INCORPORATION_APPLICATION['filing']['incorporationApplication']['nameRequest']['nrNumber'] = identifier INCORPORATION_APPLICATION['filing']['incorporationApplication']['nameRequest']['legalName'] = 'legal_name-BC1234567' corrected_filing = factory_completed_filing(business, INCORPORATION_APPLICATION) f = copy.deepcopy(CORRECTION_INCORPORATION) f['filing']['header']['identifier'] = identifier f['filing']['correction']['correctedFilingId'] = corrected_filing.id f['filing']['incorporationApplication']['nameRequest']['nrNumber'] = identifier f['filing']['incorporationApplication']['nameRequest']['legalName'] = 'legal_name-BC1234567_Changed' nr_response = { 'state': 'APPROVED', 'expirationDate': '', 'names': [{ 'name': 'legal_name-BC1234567', 'state': 'APPROVED', 'consumptionDate': '' }] } with patch.object(NameXService, 'query_nr_number', return_value=nr_response): err = validate(business, f) if err: print(err.msg) # check that validation passed assert None is err
def test_fail_coa_correction(session): """Test that an invalid COA correction passes validation.""" # setup identifier = 'CP1234567' name = 'changeOfAddress' business = factory_business(identifier) coa = copy.deepcopy(FILING_TEMPLATE) coa['filing']['header']['name'] = name coa['filing'][name] = CHANGE_OF_ADDRESS corrected_filing = factory_completed_filing(business, coa) f = copy.deepcopy(CORRECTION_COA) f['filing']['header']['identifier'] = identifier f['filing']['correction']['correctedFilingId'] = corrected_filing.id f['filing'][name]['offices']['registeredOffice']['deliveryAddress'][ 'addressCountry'] = 'DANG' f['filing'][name]['offices']['registeredOffice']['mailingAddress'][ 'addressCountry'] = 'NABBIT' err = validate(business, f) if err: print(err.msg) # check that validation failed assert err assert HTTPStatus.BAD_REQUEST == err.code assert len(err.msg) == 2 for msg in err.msg: assert "Address Country must be 'CA'." == msg['error']
def test_validate_cod_basic(session, test_name, now, delivery_country_1, delivery_country_2, expected_code, expected_msg): # pylint: disable=too-many-arguments """Assert that a basic COD can be validated.""" # setup identifier = 'CP1234567' founding_date = now - datedelta.YEAR business = Business(identifier=identifier, last_ledger_timestamp=founding_date) business.founding_date = founding_date f = copy.deepcopy(FILING_HEADER) f['filing']['header']['date'] = now.isoformat() f['filing']['header']['name'] = 'changeOfDirectors' f['filing']['business']['identifier'] = identifier cod = copy.deepcopy(CHANGE_OF_DIRECTORS) cod['directors'][0]['deliveryAddress'][ 'addressCountry'] = delivery_country_1 cod['directors'][1]['deliveryAddress'][ 'addressCountry'] = delivery_country_2 f['filing']['changeOfDirectors'] = cod # perform test with freeze_time(now): err = validate(business, f) # validate outcomes if expected_code: assert err.code == expected_code assert lists_are_equal(err.msg, expected_msg) else: assert err is None
def test_invalid_nr_correction(session): """Test that an invalid NR correction fails validation.""" # setup identifier = 'BC1234567' business = factory_business(identifier) INCORPORATION_APPLICATION['filing']['incorporationApplication'][ 'nameRequest']['nrNumber'] = identifier INCORPORATION_APPLICATION['filing']['incorporationApplication'][ 'nameRequest']['legalName'] = 'legal_name-BC1234567' corrected_filing = factory_completed_filing(business, INCORPORATION_APPLICATION) f = copy.deepcopy(CORRECTION_INCORPORATION) f['filing']['header']['identifier'] = identifier f['filing']['correction']['correctedFilingId'] = corrected_filing.id f['filing']['incorporationApplication']['nameRequest'][ 'nrNumber'] = 'BC1234568' f['filing']['incorporationApplication']['nameRequest']['legalType'] = 'CP' f['filing']['incorporationApplication']['nameRequest'][ 'legalName'] = 'legal_name-BC1234568' nr_response = { 'state': 'INPROGRESS', 'expirationDate': '', 'names': [{ 'name': 'legal_name-BC1234567', 'state': 'APPROVED', 'consumptionDate': '' }, { 'name': 'legal_name-BC1234567_Changed', 'state': 'INPROGRESS', 'consumptionDate': '' }] } class MockResponse: def __init__(self, json_data): self.json_data = json_data def json(self): return self.json_data with patch.object(NameXService, 'query_nr_number', return_value=MockResponse(nr_response)): err = validate(business, f) if err: print(err.msg) # check that validation failed assert err assert HTTPStatus.BAD_REQUEST == err.code assert len(err.msg) == 3
def put(identifier, filing_id): # pylint: disable=too-many-return-statements """Modify an incomplete filing for the business.""" # basic checks err_msg, err_code = ListFilingResource._put_basic_checks(identifier, filing_id, request) if err_msg: return jsonify({'errors': [err_msg, ]}), err_code json_input = request.get_json() # check authorization if not authorized(identifier, jwt, action=['edit']): return jsonify({'message': f'You are not authorized to submit a filing for {identifier}.'}), \ HTTPStatus.UNAUTHORIZED draft = (request.args.get('draft', None).lower() == 'true') \ if request.args.get('draft', None) else False only_validate = (request.args.get('only_validate', None).lower() == 'true') \ if request.args.get('only_validate', None) else False # validate filing if not draft: business = Business.find_by_identifier(identifier) err = validate(business, json_input) # err_msg, err_code = ListFilingResource._validate_filing_json(request) if err or only_validate: if err: json_input['errors'] = err.msg return jsonify(json_input), err.code return jsonify(json_input), HTTPStatus.OK # save filing, if it's draft only then bail user = User.get_or_create_user_by_jwt(g.jwt_oidc_token_info) business, filing, err_msg, err_code = ListFilingResource._save_filing(request, identifier, user, filing_id) if err_msg or draft: reply = filing.json if filing else json_input reply['errors'] = [err_msg, ] return jsonify(reply), err_code or \ (HTTPStatus.CREATED if (request.method == 'POST') else HTTPStatus.ACCEPTED) # if filing is from COLIN, place on queue and return if jwt.validate_roles([COLIN_SVC_ROLE]): err_msg, err_code = ListFilingResource._process_colin_filing(identifier, json_input) return jsonify(err_msg), err_code # create invoice ?? if not draft: filing_types = ListFilingResource._get_filing_types(filing.filing_json) err_msg, err_code = ListFilingResource._create_invoice(business, filing, filing_types, jwt) if err_code: reply = filing.json reply['errors'] = [err_msg, ] return jsonify(reply), err_code # all done return jsonify(filing.json),\ (HTTPStatus.CREATED if (request.method == 'POST') else HTTPStatus.ACCEPTED)
def _save_incorporation_filing(incorporation_body, client_request, business_id=None): """Create or update an incorporation filing.""" # Check that there is a JSON filing if not incorporation_body: return None, {'message': f'No filing json data in body of post for incorporation'}, \ HTTPStatus.BAD_REQUEST temp_corp_num = incorporation_body['filing'][ 'incorporationApplication']['nameRequest']['nrNumber'] # temp_corp_num = business_id # If this is an update to an incorporation filing, a temporary business identifier is passed in if business_id: business = Business.find_by_identifier(business_id) if not business: return None, {'message': f'No incorporation filing exists for id {business_id}'}, \ HTTPStatus.BAD_REQUEST else: # Ensure there are no current businesses with the NR/random identifier business = Business.find_by_identifier(temp_corp_num) if business: return None, {'message': f'Incorporation filing for {temp_corp_num} already exists'}, \ HTTPStatus.BAD_REQUEST # Create an empty business record, to be updated by the filer business = Business() business.identifier = temp_corp_num business.save() # Ensure the business identifier matches the NR in the filing err = validate(business, incorporation_body) if err: return None, err.msg, err.code filing = Filing.get_filings_by_type(business.id, 'incorporationApplication') # There can only be zero or one incorporation filings, if there are none, this is an # initial request for incorporation. Create and insert a filing. if not filing: filing = Filing() filing.business_id = business.id elif len(filing) > 1: return None, { 'message': 'more than one incorporation filing found for corp' }, HTTPStatus.BAD_REQUEST else: filing = filing[0] filing.filing_json = incorporation_body filing.save() return filing, None, (HTTPStatus.CREATED if (client_request.method == 'POST') else HTTPStatus.ACCEPTED)
def test_validate_incorporation_share_classes( session, test_name, class_name_1, class_has_max_shares, class_max_shares, has_par_value, par_value, currency, series_name_1, series_has_max_shares, series_max_shares, class_name_2, series_name_2, expected_code, expected_msg): """Assert that validator validates share class correctly.""" f = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) f['filing']['header'] = { 'name': 'incorporationApplication', 'date': '2019-04-08', 'certifiedBy': 'full name', 'email': '*****@*****.**', 'filingId': 1, 'effectiveDate': effective_date } f['filing']['incorporationApplication'] = copy.deepcopy(INCORPORATION) f['filing']['incorporationApplication']['nameRequest'][ 'nrNumber'] = 'NR 1234567' share_structure = f['filing']['incorporationApplication']['shareStructure'] share_structure['shareClasses'][0]['name'] = class_name_1 share_structure['shareClasses'][0][ 'hasMaximumShares'] = class_has_max_shares share_structure['shareClasses'][0]['maxNumberOfShares'] = class_max_shares share_structure['shareClasses'][0]['hasParValue'] = has_par_value share_structure['shareClasses'][0]['parValue'] = par_value share_structure['shareClasses'][0]['currency'] = currency share_structure['shareClasses'][0]['series'][0]['name'] = series_name_1 share_structure['shareClasses'][0]['series'][0][ 'hasMaximumShares'] = series_has_max_shares share_structure['shareClasses'][0]['series'][0][ 'maxNumberOfShares'] = series_max_shares if class_name_2: # set second shareClass name share_structure['shareClasses'][1]['name'] = class_name_2 if series_name_2: # set 1st shareClass, 2nd series name share_structure['shareClasses'][0]['series'][1]['name'] = series_name_2 # perform test with freeze_time(now): err = validate(business, f) # validate outcomes if expected_code: assert err.code == expected_code assert lists_are_equal(err.msg, expected_msg) else: assert err is None
def test_validate_incorporation_addresses_basic( session, test_name, delivery_region, delivery_country, mailing_region, mailing_country, expected_code, expected_msg): """Assert that incorporation offices can be validated.""" f = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) f['filing']['header'] = { 'name': 'incorporationApplication', 'date': '2019-04-08', 'certifiedBy': 'full name', 'email': '*****@*****.**', 'filingId': 1, 'effectiveDate': effective_date } f['filing']['incorporationApplication'] = copy.deepcopy(INCORPORATION) f['filing']['incorporationApplication']['nameRequest'][ 'nrNumber'] = identifier f['filing']['incorporationApplication']['nameRequest'][ 'legalType'] = Business.LegalTypes.BCOMP.value f['filing']['incorporationApplication']['contactPoint'][ 'email'] = '*****@*****.**' f['filing']['incorporationApplication']['contactPoint'][ 'phone'] = '123-456-7890' regoffice = f['filing']['incorporationApplication']['offices'][ 'registeredOffice'] regoffice['deliveryAddress']['addressRegion'] = delivery_region regoffice['deliveryAddress']['addressCountry'] = delivery_country regoffice['mailingAddress']['addressRegion'] = mailing_region regoffice['mailingAddress']['addressCountry'] = mailing_country recoffice = f['filing']['incorporationApplication']['offices'][ 'recordsOffice'] recoffice['deliveryAddress']['addressRegion'] = delivery_region recoffice['deliveryAddress']['addressCountry'] = delivery_country recoffice['mailingAddress']['addressRegion'] = mailing_region recoffice['mailingAddress']['addressCountry'] = mailing_country # perform test with freeze_time(now): err = validate(business, f) # validate outcomes if expected_code: assert err.code == expected_code assert lists_are_equal(err.msg, expected_msg) else: assert err is None
def test_valid_correction(session): """Test that a valid correction passes validation.""" # setup identifier = 'CP1234567' business = factory_business(identifier) corrected_filing = factory_completed_filing(business, ANNUAL_REPORT) f = copy.deepcopy(CORRECTION_AR) f['filing']['header']['identifier'] = identifier f['filing']['correction']['correctedFilingId'] = corrected_filing.id err = validate(business, f) if err: print(err.msg) # check that validation passed assert None is err
def test_validate_cod_basic(session, test_name, now, delivery_region_1, delivery_country_1, delivery_region_2, delivery_country_2, expected_code, expected_msg): # pylint: disable=too-many-arguments """Assert that a basic COD can be validated.""" # setup identifier = 'CP1234567' founding_date = now - datedelta.YEAR business = Business(identifier=identifier, last_ledger_timestamp=founding_date, founding_date=founding_date) # convert 'now' to an effective date with 0 time in the legislation timezone, same as the UI does effective_date = LegislationDatetime.as_legislation_timezone(now) effective_date = effective_date.replace(hour=0, minute=0, second=0, microsecond=0) effective_date = LegislationDatetime.as_utc_timezone(effective_date) f = copy.deepcopy(FILING_HEADER) f['filing']['header']['date'] = now.date().isoformat() f['filing']['header']['effectiveDate'] = effective_date.isoformat() f['filing']['header']['name'] = 'changeOfDirectors' f['filing']['business']['identifier'] = identifier cod = copy.deepcopy(CHANGE_OF_DIRECTORS) cod['directors'][0]['deliveryAddress'][ 'addressCountry'] = delivery_country_1 cod['directors'][0]['deliveryAddress']['addressRegion'] = delivery_region_1 cod['directors'][1]['deliveryAddress'][ 'addressCountry'] = delivery_country_2 cod['directors'][1]['deliveryAddress']['addressRegion'] = delivery_region_2 f['filing']['changeOfDirectors'] = cod # perform test with freeze_time(now): err = validate(business, f) if err: print(err.msg) # validate outcomes if expected_code: assert err.code == expected_code assert lists_are_equal(err.msg, expected_msg) else: assert err is None
def test_correction__corrected_filing_does_not_exist(session): """Check that a correction fails on a filing that does not exist.""" # setup identifier = 'CP1234567' business = factory_business(identifier) f = copy.deepcopy(CORRECTION_AR) f['filing']['header']['identifier'] = identifier f['filing']['correction']['correctedFilingId'] = 1 err = validate(business, f) if err: print(err.msg) # check that validation failed as expected assert HTTPStatus.BAD_REQUEST == err.code assert 'Corrected filing is not a valid filing.' == err.msg[0]['error']
def test_validate_incorporation_parties_mailing_address( session, test_name, mock_street, mock_city, mock_country, mock_postal_code, mock_region, expected_code, expected_msg): """Assert that incorporation parties mailing address is not empty.""" f = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) f['filing']['header'] = { 'name': 'incorporationApplication', 'date': '2019-04-08', 'certifiedBy': 'full name', 'email': '*****@*****.**', 'filingId': 1, 'effectiveDate': effective_date } f['filing']['incorporationApplication'] = copy.deepcopy(INCORPORATION) f['filing']['incorporationApplication']['nameRequest'][ 'nrNumber'] = identifier f['filing']['incorporationApplication']['nameRequest'][ 'legalType'] = Business.LegalTypes.BCOMP.value f['filing']['incorporationApplication']['contactPoint'][ 'email'] = '*****@*****.**' f['filing']['incorporationApplication']['contactPoint'][ 'phone'] = '123-456-7890' f['filing']['incorporationApplication']['parties'][0]['mailingAddress'][ 'streetAddress'] = mock_street f['filing']['incorporationApplication']['parties'][0]['mailingAddress'][ 'addressCity'] = mock_city f['filing']['incorporationApplication']['parties'][0]['mailingAddress'][ 'addressCountry'] = mock_country f['filing']['incorporationApplication']['parties'][0]['mailingAddress'][ 'postalCode'] = mock_postal_code f['filing']['incorporationApplication']['parties'][0]['mailingAddress'][ 'addressRegion'] = mock_region # perform test with freeze_time(now): err = validate(business, f) # validate outcomes if expected_code: assert err.code == expected_code assert lists_are_equal(err.msg, expected_msg) else: assert err is None
def test_validate_cooperative_documents(session, minio_server, test_name, key, scenario, expected_code, expected_msg): """Assert that validator validates cooperative documents correctly.""" filing_json = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) filing_json['filing']['header'] = {'name': incorporation_application_name, 'date': '2019-04-08', 'certifiedBy': 'full name', 'email': '*****@*****.**', 'filingId': 1} filing_json['filing']['business']['legalType'] = 'CP' filing_json['filing'][incorporation_application_name] = copy.deepcopy(COOP_INCORPORATION) # Add minimum director requirements director = filing_json['filing'][incorporation_application_name]['parties'][0]['roles'][1] filing_json['filing'][incorporation_application_name]['parties'][0]['roles'].append(director) filing_json['filing'][incorporation_application_name]['parties'][0]['roles'].append(director) # Mock upload file for test scenarios if scenario: if scenario == 'success': filing_json['filing'][incorporation_application_name]['cooperative']['rulesFileKey'] = _upload_file(letter) filing_json['filing'][incorporation_application_name]['cooperative']['memorandumFileKey'] = _upload_file(letter) if scenario == 'failRules': filing_json['filing'][incorporation_application_name]['cooperative']['rulesFileKey'] = scenario filing_json['filing'][incorporation_application_name]['cooperative']['memorandumFileKey'] = _upload_file(letter) if scenario == 'failMemorandum': filing_json['filing'][incorporation_application_name]['cooperative']['rulesFileKey'] = _upload_file(letter) filing_json['filing'][incorporation_application_name]['cooperative']['memorandumFileKey'] = scenario if scenario == 'invalidRulesSize': filing_json['filing'][incorporation_application_name]['cooperative']['rulesFileKey'] = _upload_file(legal) filing_json['filing'][incorporation_application_name]['cooperative']['memorandumFileKey'] = _upload_file(letter) if scenario == 'invalidMemorandumSize': filing_json['filing'][incorporation_application_name]['cooperative']['rulesFileKey'] = _upload_file(letter) filing_json['filing'][incorporation_application_name]['cooperative']['memorandumFileKey'] = _upload_file(legal) else: # Assign key and value to test empty variables for failures key_value = '' filing_json['filing'][incorporation_application_name]['cooperative'][key] = key_value # perform test err = validate(business, filing_json) # validate outcomes if expected_code: assert err.code == expected_code assert lists_are_equal(err.msg, expected_msg) else: assert err is None
def test_valid_ia_correction(session): """Test that a valid IA without NR correction passes validation.""" # setup identifier = 'BC1234567' business = factory_business(identifier) corrected_filing = factory_completed_filing(business, INCORPORATION_APPLICATION) f = copy.deepcopy(CORRECTION_INCORPORATION) f['filing']['header']['identifier'] = identifier f['filing']['correction']['correctedFilingId'] = corrected_filing.id err = validate(business, f) if err: print(err.msg) # check that validation passed assert None is err
def test_validate_incorporation_role(session, test_name, role_1, role_2, role_3, role_4, expected_code, expected_msg): """Assert that incorporation parties roles can be validated.""" f = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) f['filing']['header'] = { 'name': 'incorporationApplication', 'date': '2019-04-08', 'certifiedBy': 'full name', 'email': '*****@*****.**', 'filingId': 1, 'effectiveDate': effective_date } f['filing']['incorporationApplication'] = copy.deepcopy(INCORPORATION) f['filing']['incorporationApplication']['nameRequest'][ 'nrNumber'] = identifier f['filing']['incorporationApplication']['nameRequest'][ 'legalType'] = Business.LegalTypes.BCOMP.value f['filing']['incorporationApplication']['contactPoint'][ 'email'] = '*****@*****.**' f['filing']['incorporationApplication']['contactPoint'][ 'phone'] = '123-456-7890' f['filing']['incorporationApplication']['parties'][0]['roles'][0][ 'roleType'] = role_1 f['filing']['incorporationApplication']['parties'][0]['roles'][1][ 'roleType'] = role_2 f['filing']['incorporationApplication']['parties'][1]['roles'][0][ 'roleType'] = role_3 f['filing']['incorporationApplication']['parties'][1]['roles'].append( {'roleType': role_4}) # perform test with freeze_time(now): err = validate(business, f) # validate outcomes if expected_code: assert err.code == expected_code assert lists_are_equal(err.msg, expected_msg) else: assert err is None
def test_correction__does_not_own_corrected_filing(session): """Check that a business cannot correct a different business' filing.""" # setup identifier = 'CP1234567' business = factory_business(identifier) business2 = factory_business('CP1111111') corrected_filing = factory_completed_filing(business2, ANNUAL_REPORT) f = copy.deepcopy(CORRECTION_AR) f['filing']['header']['identifier'] = identifier f['filing']['correction']['correctedFilingId'] = corrected_filing.id err = validate(business, f) if err: print(err.msg) # check that validation failed as expected assert HTTPStatus.BAD_REQUEST == err.code assert 'Corrected filing is not a valid filing for this business.' == err.msg[0]['error']
def test_validate_incorporation_role(session, minio_server, test_name, legal_type, parties, expected_code, expected_msg): """Assert that incorporation parties roles can be validated.""" filing_json = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) filing_json['filing']['header'] = {'name': incorporation_application_name, 'date': '2019-04-08', 'certifiedBy': 'full name', 'email': '*****@*****.**', 'filingId': 1} filing_json['filing']['business']['legalType'] = legal_type if legal_type == 'CP': filing_json['filing'][incorporation_application_name] = copy.deepcopy(COOP_INCORPORATION) # Provide mocked valid documents filing_json['filing'][incorporation_application_name]['cooperative']['rulesFileKey'] = _upload_file(letter) filing_json['filing'][incorporation_application_name]['cooperative']['memorandumFileKey'] = _upload_file(letter) else: filing_json['filing'][incorporation_application_name] = copy.deepcopy(INCORPORATION) filing_json['filing'][incorporation_application_name]['nameRequest'] = {} filing_json['filing'][incorporation_application_name]['nameRequest']['nrNumber'] = identifier filing_json['filing'][incorporation_application_name]['nameRequest']['legalType'] = legal_type filing_json['filing'][incorporation_application_name]['contactPoint']['email'] = '*****@*****.**' filing_json['filing'][incorporation_application_name]['contactPoint']['phone'] = '123-456-7890' base_mailing_address = filing_json['filing'][incorporation_application_name]['parties'][0]['mailingAddress'] base_delivery_address = filing_json['filing'][incorporation_application_name]['parties'][0]['deliveryAddress'] filing_json['filing'][incorporation_application_name]['parties'] = [] # populate party and party role info for index, party in enumerate(parties): mailing_addr = create_party_address(base_address=base_mailing_address) delivery_addr = create_party_address(base_address=base_delivery_address) p = create_party(party['roles'], index + 1, mailing_addr, delivery_addr) filing_json['filing'][incorporation_application_name]['parties'].append(p) # perform test err = validate(business, filing_json) # validate outcomes if expected_code: assert err.code == expected_code assert lists_are_equal(err.msg, expected_msg) else: assert err is None
def test_validate_ar_basic(session, test_name, now, ar_date, agm_date, expected_code, expected_msg): # pylint: disable=too-many-arguments """Assert that a basic AR can be validated.""" # setup identifier = 'CP1234567' founding_date = ar_date - datedelta.YEAR business = Business(identifier=identifier, last_ledger_timestamp=founding_date) business.founding_date = datetime(founding_date.year, founding_date.month, founding_date.day) ar = copy.deepcopy(ANNUAL_REPORT) ar['filing']['business']['identifier'] = identifier ar['filing']['annualReport']['annualReportDate'] = ar_date.isoformat() ar['filing']['annualReport']['annualGeneralMeetingDate'] = agm_date.isoformat() # perform test with freeze_time(now): err = validate(business, ar) # validate outcomes assert not err
def post(): """Create a business from an incorporation filing, return the filing.""" draft = (request.args.get('draft', None).lower() == 'true') \ if request.args.get('draft', None) else False json_input = request.get_json() # validate filing err = validate(None, json_input) if err: json_input['errors'] = err.msg return jsonify(json_input), err.code # create business business, err_msg, err_code = BusinessResource._create_business(json_input, request) if err_msg: if isinstance(err_msg, list): json_input['errors'] = [err for err in err_msg] elif err_msg: json_input['errors'] = [err_msg, ] return jsonify(json_input), err_code # create filing user = User.get_or_create_user_by_jwt(g.jwt_oidc_token_info) business, filing, err_msg, err_code = ListFilingResource._save_filing( # pylint: disable=protected-access request, business.identifier, user, None) if err_msg or draft: reply = filing.json if filing else json_input reply['errors'] = [err_msg, ] return jsonify(reply), err_code or HTTPStatus.CREATED # complete filing response, response_code = ListFilingResource.complete_filing(business, filing, draft) if response: return response, response_code # all done return jsonify(filing.json), HTTPStatus.CREATED
def test_validate_incorporation_effective_date(session, test_name, effective_date, expected_code, expected_msg): """Assert that validator validates share class correctly.""" filing_json = copy.deepcopy(FILING_HEADER) filing_json['filing'].pop('business') filing_json['filing']['header'] = {'name': incorporation_application_name, 'date': '2019-04-08', 'certifiedBy': 'full name', 'email': '*****@*****.**', 'filingId': 1} if effective_date is not None: filing_json['filing']['header']['effectiveDate'] = effective_date filing_json['filing'][incorporation_application_name] = copy.deepcopy(INCORPORATION) # perform test with freeze_time(now): err = validate(business, filing_json) # validate outcomes if expected_code: assert err.code == expected_code assert lists_are_equal(err.msg, expected_msg) else: if err: print(err, err.code, err.msg) assert err is None
def put(identifier, filing_id): # pylint: disable=too-many-return-statements """Modify an incomplete filing for the business.""" # basic checks err_msg, err_code = ListFilingResource._put_basic_checks( identifier, filing_id, request) if err_msg: return jsonify({'errors': [ err_msg, ]}), err_code json_input = request.get_json() # check authorization if not authorized(identifier, jwt, action=['edit']): return jsonify({'message': f'You are not authorized to submit a filing for {identifier}.'}), \ HTTPStatus.UNAUTHORIZED # get query params draft = (request.args.get('draft', None).lower() == 'true') \ if request.args.get('draft', None) else False only_validate = (request.args.get('only_validate', None).lower() == 'true') \ if request.args.get('only_validate', None) else False # validate filing if not draft and not ListFilingResource._is_before_epoch_filing( json_input, Business.find_by_identifier(identifier)): if identifier.startswith('T'): business_validate = RegistrationBootstrap.find_by_identifier( identifier) else: business_validate = Business.find_by_identifier(identifier) err = validate(business_validate, json_input) # err_msg, err_code = ListFilingResource._validate_filing_json(request) if err or only_validate: if err: json_input['errors'] = err.msg return jsonify(json_input), err.code return jsonify(json_input), HTTPStatus.OK # save filing, if it's draft only then bail user = User.get_or_create_user_by_jwt(g.jwt_oidc_token_info) try: business, filing, err_msg, err_code = ListFilingResource._save_filing( request, identifier, user, filing_id) if err_msg or draft: reply = filing.json if filing else json_input reply['errors'] = [ err_msg, ] return jsonify(reply), err_code or \ (HTTPStatus.CREATED if (request.method == 'POST') else HTTPStatus.ACCEPTED) except Exception as err: print(err) # complete filing response, response_code = ListFilingResource.complete_filing( business, filing, draft) if response: return response, response_code # all done return jsonify(filing.json),\ (HTTPStatus.CREATED if (request.method == 'POST') else HTTPStatus.ACCEPTED)
def put(identifier, filing_id): # pylint: disable=too-many-return-statements,too-many-locals """Modify an incomplete filing for the business.""" # basic checks err_msg, err_code = ListFilingResource._put_basic_checks( identifier, filing_id, request) if err_msg: return jsonify({'errors': [ err_msg, ]}), err_code json_input = request.get_json() # check authorization response, response_code = ListFilingResource._check_authorization( identifier, json_input) if response: return response, response_code # get query params draft = (request.args.get('draft', None).lower() == 'true') \ if request.args.get('draft', None) else False only_validate = (request.args.get('only_validate', None).lower() == 'true') \ if request.args.get('only_validate', None) else False # get header params payment_account_id = request.headers.get('accountId', None) if not draft \ and not ListFilingResource._is_historical_colin_filing(json_input) \ and not ListFilingResource._is_before_epoch_filing(json_input, Business.find_by_identifier(identifier)): if identifier.startswith('T'): business_validate = RegistrationBootstrap.find_by_identifier( identifier) else: business_validate = Business.find_by_identifier(identifier) err = validate(business_validate, json_input) # err_msg, err_code = ListFilingResource._validate_filing_json(request) if err or only_validate: if err: json_input['errors'] = err.msg return jsonify(json_input), err.code return jsonify(json_input), HTTPStatus.OK # save filing, if it's draft only then bail user = User.get_or_create_user_by_jwt(g.jwt_oidc_token_info) try: business, filing, err_msg, err_code = ListFilingResource._save_filing( request, identifier, user, filing_id) if err_msg or draft: reply = filing.json if filing else json_input reply['errors'] = [ err_msg, ] return jsonify(reply), err_code or \ (HTTPStatus.CREATED if (request.method == 'POST') else HTTPStatus.ACCEPTED) except Exception as err: print(err) # complete filing response, response_code = ListFilingResource.complete_filing( business, filing, draft, payment_account_id) if response and (response_code != HTTPStatus.CREATED or filing.source == Filing.Source.COLIN.value): return response, response_code # all done filing_json = filing.json if response: filing_json['filing']['header'].update(response) return jsonify(filing_json),\ (HTTPStatus.CREATED if (request.method == 'POST') else HTTPStatus.ACCEPTED)