def create_report(identifier, entity_type, report_type, template): """Create an instance of the Report class.""" if template.get('filing'): filing_json = copy.deepcopy(template) else: filing_json = copy.deepcopy(FILING_HEADER) filing_json['filing'][f'{report_type}'] = copy.deepcopy(template) filing_json['filing']['business']['identifier'] = identifier filing_json['filing']['business']['legalType'] = entity_type filing_json['filing']['header']['name'] = report_type business = factory_business(identifier=identifier, entity_type=entity_type) if report_type == 'correction': original_filing_json = copy.deepcopy(filing_json) original_filing_json['filing']['header']['name'] = filing_json['filing']['correction']['correctedFilingType'] del original_filing_json['filing']['correction'] original_filing = factory_completed_filing(business, original_filing_json) filing_json['filing']['correction']['correctedFilingId'] = original_filing.id filing = factory_completed_filing(business, filing_json) report = Report(filing) report._business = business report._report_key = report_type if report._report_key == 'correction': report._report_key = report._filing.filing_json['filing']['correction']['correctedFilingType'] return report
def test_diff_of_stored_completed_filings(session): """Assert that the filing diff works correctly.""" identifier = 'CP1234567' business = factory_business(identifier, founding_date=(datetime.utcnow() - datedelta.YEAR)) factory_business_mailing_address(business) json1 = copy.deepcopy(MINIMAL_FILING_JSON) original_filing = factory_completed_filing(business, json1) json2 = copy.deepcopy(CORRECTION_FILING_JSON) json2['filing']['correction']['correctedFilingId'] = str( original_filing.id) correction_filing = factory_completed_filing(business, json2) filing = Filing.find_by_id(correction_filing.id) filing_json = filing.json assert filing_json assert filing_json['filing']['correction']['diff'] == [{ 'newValue': 'Be it resolved, and now it is.', 'oldValue': 'Be it resolved, that it is resolved to be resolved.', 'path': RESOLUTION_PATH }]
def test_effective_date_sanity_check(session): """Assert that a COD with a valid effective date passes validation.""" # setup identifier = 'CP1234567' now = datetime(2001, 8, 5, 0, 0, 0, 0, tzinfo=timezone.utc) filing_json = copy.deepcopy(FILING_HEADER) filing_json['filing']['header']['effectiveDate'] = ( now - datedelta.MONTH).isoformat() filing_json['filing']['changeOfDirectors'] = copy.deepcopy( CHANGE_OF_DIRECTORS) business = Business(identifier=identifier, founding_date=now - datedelta.datedelta(years=4)) business.save() # create a COD factory_completed_filing(business=business, data_dict=filing_json, filing_date=(now - datedelta.MONTH)) # move the COD to now filing_json['filing']['header']['effectiveDate'] = now.isoformat() with freeze_time(now): err = validate_effective_date(business, filing_json) assert not err
def test_validate_effective_date_not_before_other_AR_with_COD( session): # noqa: N802; COD is an acronym """Assert that the filing ordering rules are correct. Rules: - The effective date of change cannot be a date that is farther in the past as a previous COD filing(Standalone or AR). """ # setup identifier = 'CP1234567' now = datetime(2001, 8, 5, 0, 0, 0, 0, tzinfo=timezone.utc) filing_ar = copy.deepcopy(ANNUAL_REPORT) filing_ar['filing']['changeOfDirectors'] = copy.deepcopy( CHANGE_OF_DIRECTORS) business = Business(identifier=identifier, founding_date=now - datedelta.datedelta(years=4)) business.save() # create a COD factory_completed_filing(business=business, data_dict=filing_ar, filing_date=now) # move the COD BACK a MONTH filing_ar['filing']['header']['effectiveDate'] = ( now - datedelta.MONTH).isoformat() # The effective date of change cannot be before the previous COD with freeze_time(now): err = validate_effective_date(business, filing_ar) assert err
def test_get_internal_filings(session, client, jwt): """Assert that the internal filings get endpoint returns all completed filings without colin ids.""" from legal_api.models import Filing from tests.unit.models import factory_error_filing, factory_pending_filing # setup identifier = 'CP7654321' b = factory_business(identifier) factory_business_mailing_address(b) filing1 = factory_completed_filing(b, ANNUAL_REPORT) filing2 = factory_completed_filing(b, ANNUAL_REPORT) filing3 = factory_pending_filing(b, ANNUAL_REPORT) filing4 = factory_filing(b, ANNUAL_REPORT) filing5 = factory_error_filing(b, ANNUAL_REPORT) assert filing1.status == Filing.Status.COMPLETED.value # completed with colin_event_id filing2.colin_event_id = 1234 filing2.save() assert filing2.status == Filing.Status.COMPLETED.value assert filing2.colin_event_id is not None # pending with no colin_event_id assert filing3.status == Filing.Status.PENDING.value # draft with no colin_event_id assert filing4.status == Filing.Status.DRAFT.value # error with no colin_event_id assert filing5.status == Filing.Status.ERROR.value # test endpoint returned filing1 only (completed with no colin id set) rv = client.get(f'/api/v1/businesses/internal/filings') assert rv.status_code == HTTPStatus.OK assert len(rv.json) == 1 assert rv.json[0]['filing']['header']['filingId'] == filing1.id
def test_filing_type(session): """Assert that filing_type is empty on a new filing.""" identifier = 'CP7654321' business = factory_business(identifier) factory_completed_filing(business, ANNUAL_REPORT) filings = Filing.get_filings_by_status(business.id, [Filing.Status.DRAFT.value, Filing.Status.COMPLETED.value]) assert filings[0].filing_type == 'annualReport'
def test_filing_json_completed(session): """Assert that the json field gets the completed filing correctly.""" identifier = 'CP7654321' business = factory_business(identifier) factory_completed_filing(business, ANNUAL_REPORT) filings = Filing.get_filings_by_status(business.id, [Filing.Status.COMPLETED.value]) filing = filings[0] assert filing.json assert filing.json['filing']['header']['status'] == Filing.Status.COMPLETED.value assert filing.json['filing']['annualReport'] assert 'directors' in filing.json['filing']['annualReport'] assert 'offices' in filing.json['filing']['annualReport']
def filing_named_company(business, template, legal_name): """Create a filing for a name change with for named company.""" filing_json = copy.deepcopy(template) filing_json['filing']['alteration']['nameRequest'][ 'legalName'] = legal_name filing = factory_completed_filing(business, filing_json) return filing
def test_update_ar_with_a_missing_business_id_fails(session, client, jwt): """Assert that updating to a non-existant business fails.""" import copy identifier = 'CP7654321' business = factory_business(identifier, founding_date=(datetime.utcnow() - datedelta.YEAR)) factory_business_mailing_address(business) ar = copy.deepcopy(ANNUAL_REPORT) ar['filing']['annualReport']['annualReportDate'] = datetime.utcnow().date( ).isoformat() ar['filing']['annualReport']['annualGeneralMeetingDate'] = datetime.utcnow( ).date().isoformat() filings = factory_completed_filing(business, ar) identifier = 'CP0000001' rv = client.put(f'/api/v1/businesses/{identifier}/filings/{filings.id+1}', json=ar, headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.BAD_REQUEST assert rv.json['errors'][0] == { 'error': 'A valid business and filing are required.' }
def test_is_pending_correction_filing(session): """Assert that a filing has the isPendingCorrection flag set if the correction is pending approval. Assert linkage is set from parent to child and otherway. """ from legal_api.models import Filing # setup filing1 = Filing() filing1.filing_json = ANNUAL_REPORT filing1.save() b = factory_business('CP1234567') filing2 = factory_completed_filing(b, CORRECTION_AR) filing2._status = 'PENDING_CORRECTION' setattr(filing2, 'skip_status_listener', True) filing2.save() filing1.parent_filing = filing2 filing1.save() # test assert filing1.json['filing']['header']['isCorrected'] is False assert filing1.json['filing']['header']['isCorrectionPending'] is True assert filing2.json['filing']['header']['affectedFilings'] is not None assert filing2.json['filing']['header']['affectedFilings'][0] == filing1.id
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_get_internal_filings(session, client, jwt): """Assert that the get_completed_filings_for_colin returns completed filings with no colin ids set.""" from legal_api.models import Filing from tests.unit.models import factory_completed_filing # setup identifier = 'CP7654321' b = factory_business(identifier) filing = factory_completed_filing(b, ANNUAL_REPORT) assert filing.status == Filing.Status.COMPLETED.value filing.colin_event_id = 1234 filing.save() filings = Filing.get_completed_filings_for_colin() # test method # assert doesn't return completed filing with colin_event_ids set assert len(filings) == 0 # assert returns completed filings with colin_event_id not set filing.colin_event_id = None filing.save() filings = Filing.get_completed_filings_for_colin() assert len(filings) == 1 assert filing.id == filings[0].json['filing']['header']['filingId'] assert filings[0].json['filing']['header']['colinId'] is None # assert doesn't return non completed filings filing.transaction_id = None filing.save() assert filing.status != Filing.Status.COMPLETED.value filings = Filing.get_completed_filings_for_colin() assert len(filings) == 0
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_update_block_ar_update_to_a_paid_filing(session, client, jwt): """Assert that a valid filing can NOT be updated once it has been paid.""" import copy identifier = 'CP7654321' business = factory_business( identifier, founding_date=(datetime.utcnow() - datedelta.datedelta(years=2)), last_ar_date=datetime(datetime.utcnow().year - 1, 4, 20).date()) factory_business_mailing_address(business) ar = copy.deepcopy(ANNUAL_REPORT) ar['filing']['annualReport']['annualReportDate'] = datetime( datetime.utcnow().year, 2, 20).date().isoformat() ar['filing']['annualReport']['annualGeneralMeetingDate'] = datetime.utcnow( ).date().isoformat() filings = factory_completed_filing(business, ar) rv = client.put(f'/api/v1/businesses/{identifier}/filings/{filings.id}', json=ar, headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.FORBIDDEN assert rv.json['errors'][0] == { 'error': 'Filings cannot be changed after the invoice is created.' }
def test_get_a_businesses_most_recent_filing_of_a_type(session): """Assert that the most recent completed filing of a specified type is returned.""" from legal_api.models import Filing from tests.unit.models import factory_completed_filing # setup identifier = 'CP7654321' b = factory_business(identifier) ar = copy.deepcopy(ANNUAL_REPORT) base_ar_date = datetime.datetime(2001, 8, 5, 7, 7, 58, 272362, tzinfo=datetime.timezone.utc) filings = [] for i in range(0, 5): filing_date = base_ar_date + datedelta.datedelta(years=i) ar['filing']['annualReport']['annualGeneralMeetingDate'] = \ filing_date.date().isoformat() filing = factory_completed_filing(b, ar, filing_date) filings.append(filing) # test filing = Filing.get_a_businesses_most_recent_filing_of_a_type( b.id, Filing.FILINGS['annualReport']['name']) # assert that we get the last filing assert filings[4] == filing
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_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 test_validate_effective_date_not_before_other_COD( session): # noqa: N802; COD is an acronym """Assert that the effective date of change cannot be before a previous COD filing.""" # setup identifier = 'CP1234567' founding_date = datetime(2000, 8, 5, 12, 0, 0, 0, tzinfo=timezone.utc) business = Business(identifier=identifier, founding_date=founding_date) business.save() now = datetime(2020, 7, 30, 12, 0, 0, 0, tzinfo=timezone.utc) # create the previous COD filing filing_cod = copy.deepcopy(FILING_HEADER) filing_cod['filing']['header']['name'] = 'changeOfDirectors' filing_cod['filing']['changeOfDirectors'] = copy.deepcopy( CHANGE_OF_DIRECTORS) filing_date = datetime(2010, 8, 5, 12, 0, 0, 0, tzinfo=timezone.utc) factory_completed_filing(business=business, data_dict=filing_cod, filing_date=filing_date) # The effective date _cannot_ be before the previous COD. before = datetime(2010, 8, 4, 12, 0, 0, 0, tzinfo=timezone.utc) effective_date = as_effective_date(before) filing_cod['filing']['header']['effectiveDate'] = effective_date.isoformat( ) with freeze_time(now): err = validate_effective_date(business, filing_cod) assert err # The effective date _can_ be on the same date as the previous COD. on = datetime(2010, 8, 5, 12, 0, 0, 0, tzinfo=timezone.utc) effective_date = as_effective_date(on) filing_cod['filing']['header']['effectiveDate'] = effective_date.isoformat( ) with freeze_time(now): err = validate_effective_date(business, filing_cod) assert not err # The effective date _can_ be after the previous COD. after = datetime(2010, 8, 6, 12, 0, 0, 0, tzinfo=timezone.utc) effective_date = as_effective_date(after) filing_cod['filing']['header']['effectiveDate'] = effective_date.isoformat( ) with freeze_time(now): err = validate_effective_date(business, filing_cod) assert not err
def test_get_bcomp_corrections(session, client, jwt, identifier, base_filing, corrected_filing, colin_id): """Assert that the internal filings get endpoint returns corrections for bcomps.""" # setup b = factory_business(identifier=identifier, entity_type=Business.LegalTypes.BCOMP.value) factory_business_mailing_address(b) incorp_filing = factory_completed_filing(business=b, data_dict=corrected_filing, colin_id=colin_id) correction_filing = copy.deepcopy(base_filing) correction_filing['filing']['correction']['correctedFilingId'] = incorp_filing.id filing = factory_completed_filing(b, correction_filing) # test endpoint returns filing rv = client.get('/api/v1/businesses/internal/filings') assert rv.status_code == HTTPStatus.OK assert len(rv.json) == 1 if colin_id: assert rv.json[0]['filingId'] == filing.id else: assert rv.json[0]['filingId'] == incorp_filing.id
def basic_test_helper(): identifier = 'CP7654321' business = factory_business(identifier) filing_json = FILING_HEADER filing_json['specialResolution'] = SPECIAL_RESOLUTION filing_date = datetime.utcnow() filing = factory_completed_filing(business, filing_json, filing_date=filing_date) return business, filing
def test_get_internal_filings(session, client, jwt): """Assert that the internal filings get endpoint returns all completed filings without colin ids.""" from legal_api.models import Filing from legal_api.models.colin_event_id import ColinEventId from tests.unit.models import factory_error_filing, factory_pending_filing # setup identifier = 'CP7654321' b = factory_business(identifier) factory_business_mailing_address(b) filing1 = factory_completed_filing(b, ANNUAL_REPORT) filing2 = factory_completed_filing(b, ANNUAL_REPORT) filing3 = factory_pending_filing(b, ANNUAL_REPORT) filing4 = factory_filing(b, ANNUAL_REPORT) filing5 = factory_error_filing(b, ANNUAL_REPORT) filing6 = factory_completed_filing(b, CORRECTION_AR) assert filing1.status == Filing.Status.COMPLETED.value # completed with colin_event_id print(filing2.colin_event_ids) assert len(filing2.colin_event_ids) == 0 colin_event_id = ColinEventId() colin_event_id.colin_event_id = 12345 filing2.colin_event_ids.append(colin_event_id) filing2.save() assert filing2.status == Filing.Status.COMPLETED.value assert filing2.colin_event_ids # pending with no colin_event_ids assert filing3.status == Filing.Status.PENDING.value # draft with no colin_event_ids assert filing4.status == Filing.Status.DRAFT.value # error with no colin_event_ids assert filing5.status == Filing.Status.PAID.value # completed correction with no colin_event_ids assert filing6.status == Filing.Status.COMPLETED.value # test endpoint returned filing1 only (completed, no corrections, with no colin id set) rv = client.get(f'/api/v1/businesses/internal/filings') assert rv.status_code == HTTPStatus.OK assert len(rv.json) == 1 assert rv.json[0]['filingId'] == filing1.id
def test_business_filing_ia_parties(session, client, jwt): """Assert that the ia parties can be received in a valid JSONSchema format.""" identifier = 'BC7654321' b = factory_business(identifier) filings = factory_completed_filing(b, INCORPORATION_FILING_TEMPLATE) director_address = Address(city='Test Mailing City', address_type=Address.DELIVERY, postal_code='H0H0H0') officer = { 'firstName': 'Michael', 'lastName': 'Crane', 'middleInitial': 'Joe', 'partyType': 'person', 'organizationName': '' } party_role = factory_party_role(director_address, None, officer, datetime(2017, 5, 17), None, PartyRole.RoleTypes.DIRECTOR) b.party_roles.append(party_role) officer = { 'firstName': '', 'lastName': '', 'middleInitial': '', 'partyType': 'organization', 'organizationName': 'Test Inc.' } party_role = factory_party_role(director_address, None, officer, datetime(2017, 5, 17), None, PartyRole.RoleTypes.DIRECTOR) b.party_roles.append(party_role) rv = client.get(f'/api/v1/businesses/{identifier}/filings/{filings.id}', headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.OK party_1 = rv.json['filing']['incorporationApplication']['parties'][0][ 'officer'] assert party_1 assert party_1['partyType'] == 'person' assert party_1['firstName'] == 'Michael' assert party_1['lastName'] == 'Crane' assert party_1['middleName'] == 'Joe' assert 'organizationName' not in party_1 party_2 = rv.json['filing']['incorporationApplication']['parties'][1][ 'officer'] assert party_2 assert party_2['partyType'] == 'organization' assert 'firstName' not in party_2 assert 'lastName' not in party_2 assert 'middleName' not in party_2 assert party_2['organizationName'] == 'Test Inc.'
def test_ledger_redaction(session, client, jwt, test_name, submitter_role, jwt_role, username, firstname, lastname, expected): """Assert that the core filing is saved to the backing store.""" from legal_api.core.filing import Filing as CoreFiling try: identifier = 'BC1234567' founding_date = datetime.utcnow() business_name = 'The Truffle House' entity_type = Business.LegalTypes.BCOMP.value business = factory_business(identifier=identifier, founding_date=founding_date, last_ar_date=None, entity_type=entity_type) business.legal_name = business_name business.save() filing_name = 'specialResolution' filing_date = founding_date filing_submission = { 'filing': { 'header': { 'name': filing_name, 'date': '2019-04-08' }, filing_name: { 'resolution': 'Year challenge is hitting oppo for the win.' } } } user = factory_user(username, firstname, lastname) new_filing = factory_completed_filing(business, filing_submission, filing_date=filing_date) new_filing.submitter_id = user.id new_filing.submitter_roles = submitter_role setattr(new_filing, 'skip_status_listener', True) # skip status listener new_filing.save() rv = client.get(f'/api/v2/businesses/{identifier}/filings', headers=create_header(jwt, [jwt_role], identifier)) except Exception as err: print(err) assert rv.status_code == HTTPStatus.OK assert rv.json['filings'][0]['submitter'] == expected
def test_ledger_display_incorporation(session, client, jwt): """Assert that the ledger returns the correct number of comments.""" # setup identifier = 'BC1234567' nr_number = 'NR000001' founding_date = datetime.utcnow() filing_date = founding_date filing_name = 'incorporationApplication' business_name = 'The Truffle House' entity_type = Business.LegalTypes.BCOMP.value business = factory_business(identifier=identifier, founding_date=founding_date, last_ar_date=None, entity_type=entity_type) business.legal_name = business_name business.save() filing = copy.deepcopy(FILING_HEADER) filing['filing'].pop('business') filing['filing']['header']['name'] = filing_name filing['filing'][filing_name] = INCORPORATION filing['filing'][filing_name]['nameRequest'] = 'NR0000001' filing['filing'][filing_name]['legalName'] = business_name f = factory_completed_filing(business, filing, filing_date=filing_date) today = filing_date.isoformat() ia_meta = { 'legalFilings': [ filing_name, ], filing_name: { 'nrNumber': nr_number, 'legalName': business_name } } f._meta_data = {**{'applicationDate': today}, **ia_meta} # test rv = client.get(f'/api/v2/businesses/{identifier}/filings', headers=create_header(jwt, [UserRoles.SYSTEM.value], identifier)) # validate assert rv.json['filings'] assert rv.json['filings'][0][ 'displayName'] == f'BC Benefit Company Incorporation Application'
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 load_ledger(business, founding_date): """Create a ledger of all filing types.""" i = 0 for k, filing_meta in Filing.FILINGS.items(): filing = copy.deepcopy(FILING_TEMPLATE) filing['filing']['header']['name'] = filing_meta['name'] f = factory_completed_filing(business, filing, filing_date=founding_date + datedelta.datedelta(months=i)) for c in range(i): comment = Comment() comment.comment = f'this comment {c}' f.comments.append(comment) f.save() i += 1 return i
def test_get_colin_id(session, client, jwt): """Assert the internal/filings/colin_id get endpoint returns properly.""" # setup identifier = 'CP7654321' b = factory_business(identifier) factory_business_mailing_address(b) filing = factory_completed_filing(b, ANNUAL_REPORT) colin_event_id = 1234 filing.colin_event_id = colin_event_id filing.save() rv = client.get(f'/api/v1/businesses/internal/filings/colin_id/{colin_event_id}') assert rv.status_code == HTTPStatus.OK assert rv.json == {'colinId': colin_event_id} rv = client.get(f'/api/v1/businesses/internal/filings/colin_id/{1}') assert rv.status_code == HTTPStatus.NOT_FOUND
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_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_delete_filing_block_completed(session, client, jwt): """Assert that a completed filing cannot be deleted.""" import copy identifier = 'CP7654321' business = factory_business(identifier, founding_date=(datetime.utcnow() - datedelta.YEAR) ) factory_business_mailing_address(business) ar = copy.deepcopy(ANNUAL_REPORT) ar['filing']['annualReport']['annualReportDate'] = datetime.utcnow().date().isoformat() ar['filing']['annualReport']['annualGeneralMeetingDate'] = datetime.utcnow().date().isoformat() filings = factory_completed_filing(business, ar) rv = client.delete(f'/api/v1/businesses/{identifier}/filings/{filings.id}', headers=create_header(jwt, [STAFF_ROLE], identifier) ) assert rv.status_code == HTTPStatus.FORBIDDEN