def test_get_temp_business_info(session, client, jwt): """Assert that temp registration returns 200.""" identifier = 'T7654321' rv = client.get('/api/v2/businesses/' + identifier, headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.OK
def test_documents_signature_get_returns_200(client, jwt, session, minio_server): # pylint:disable=unused-argument """Assert get documents/filename/signatures endpoint returns 200.""" headers = create_header(jwt, [STAFF_ROLE]) file_name = 'test_file.jpeg' rv = client.get(f'/api/v1/documents/{file_name}/signatures', headers=headers, content_type='application/json') assert rv.status_code == HTTPStatus.OK assert 'key' in rv.json and 'preSignedUrl' in rv.json
def test_post_colin_last_update(session, client, jwt): """Assert the internal/filings/colin_id post endpoint updates the colin_last_update table.""" colin_id = 1234 rv = client.post( f'/api/v1/businesses/internal/filings/colin_id/{colin_id}', headers=create_header(jwt, [COLIN_SVC_ROLE])) assert rv.status_code == HTTPStatus.CREATED assert rv.json == {'maxId': colin_id}
def test_colin_filing_to_queue(app_ctx, session, client, jwt, stan_server): """Assert that payment tokens can be retrieved and decoded from the Queue.""" import copy # SETUP msgs = [] this_loop = asyncio.get_event_loop() # this_loop = event_loop future = asyncio.Future(loop=this_loop) queue = QueueService(app_ctx, this_loop) this_loop.run_until_complete(queue.connect()) async def cb(msg): nonlocal msgs nonlocal future msgs.append(msg) if len(msgs) == 5: future.set_result(True) this_loop.run_until_complete( queue.stan.subscribe(subject=queue.subject, queue='colin_queue', durable_name='colin_queue', cb=cb)) # TEST - add some COLIN filings to the system, check that they got placed on the Queue for i in range(0, 5): # Create business identifier = f'CP765432{i}' b = factory_business(identifier) factory_business_mailing_address(b) # Create anm AR filing for the business ar = copy.deepcopy(AR_FILING) ar['filing']['header']['colinId'] = 1230 + i ar['filing']['business']['identifier'] = identifier # POST the AR rv = client.post(f'/api/v1/businesses/{identifier}/filings', json=ar, headers=create_header(jwt, [COLIN_SVC_ROLE], 'colin_service')) # Assure that the filing was accepted assert rv.status_code == HTTPStatus.CREATED # Await all the messages were received try: this_loop.run_until_complete( asyncio.wait_for(future, 2, loop=this_loop)) except Exception as err: print(err) # CHECK the colinFilings were retrieved from the queue assert len(msgs) == 5 for i in range(0, 5): m = msgs[i] assert 'colinFiling' in m.data.decode('utf-8') assert 1230 + i == dpath.util.get(json.loads(m.data.decode('utf-8')), 'colinFiling/id')
def test_filing_court_order_validation(client, jwt, session): """Assert that a court order filing can be validated.""" identifier = 'BC1156638' b = factory_business(identifier, datetime.datetime.utcnow(), None, Business.LegalTypes.COMP.value) factory_business_mailing_address(b) filing = copy.deepcopy(COURT_ORDER_FILING_TEMPLATE) filing['filing']['business']['identifier'] = identifier filing['filing']['courtOrder']['fileNumber'] = '' rv = client.post(f'/api/v1/businesses/{identifier}/filings', json=filing, headers=create_header(jwt, [STAFF_ROLE], None)) assert rv.status_code == HTTPStatus.UNPROCESSABLE_ENTITY filing = copy.deepcopy(COURT_ORDER_FILING_TEMPLATE) filing['filing']['business']['identifier'] = identifier filing['filing']['courtOrder']['orderDetails'] = '' filing['filing']['courtOrder']['effectOfOrder'] = '' rv = client.post(f'/api/v1/businesses/{identifier}/filings', json=filing, headers=create_header(jwt, [STAFF_ROLE], None)) assert rv.status_code == HTTPStatus.BAD_REQUEST assert rv.json['errors'] == [{ 'error': 'Court Order is required.', 'path': '/filing/courtOrder/orderDetails' }] filing = copy.deepcopy(COURT_ORDER_FILING_TEMPLATE) filing['filing']['business']['identifier'] = identifier filing['filing']['courtOrder']['effectOfOrder'] = 'invalid' rv = client.post(f'/api/v1/businesses/{identifier}/filings', json=filing, headers=create_header(jwt, [STAFF_ROLE], None)) assert rv.status_code == HTTPStatus.BAD_REQUEST assert rv.json['errors'] == [{ 'error': 'Invalid effectOfOrder.', 'path': '/filing/courtOrder/effectOfOrder' }]
def test_draft_get_staff_missing_account_201(session, client, jwt): """Assert that a staff draft get request with no account ID returns a 201 status.""" # setup # test rv = client.get('/api/v1/drafts/D-T-FS01', headers=create_header(jwt, [PPR_ROLE, STAFF_ROLE])) # check assert rv.status_code == HTTPStatus.OK
def test_draft_get_nonstaff_missing_account_400(session, client, jwt): """Assert that a non-staff draft get request with no account ID returns a 400 status.""" # setup # test rv = client.get('/api/v1/drafts/TEST-FSD1', headers=create_header(jwt, [COLIN_ROLE])) # check assert rv.status_code == HTTPStatus.BAD_REQUEST
def test_draft_list_staff_missing_account_400(session, client, jwt): """Assert that a staff draft list request with no account ID returns a 400 status.""" # setup # test rv = client.get('/api/v1/drafts', headers=create_header(jwt, [PPR_ROLE, STAFF_ROLE])) # check assert rv.status_code == HTTPStatus.BAD_REQUEST
def test_delete_filing_missing_filing_id(client, jwt): """Assert that trying to delete a non-existant filing returns a 404.""" identifier = 'CP7654321' rv = client.delete( f'/api/v2/businesses/{identifier}/filings/123451234512345', headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code in (HTTPStatus.NOT_FOUND, HTTPStatus.INTERNAL_SERVER_ERROR)
def test_get_empty_filings_with_invalid_business(session, client, jwt): """Assert that a filing cannot be created against non-existent business.""" identifier = 'CP7654321' filings_id = 1 rv = client.get(f'/api/v2/businesses/{identifier}/filings/{filings_id}', headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.NOT_FOUND
def test_get_comments_invalid_filing_error(session, client, jwt): """Assert that error is returned when filing doesn't exist.""" b = factory_business('CP1111111') rv = client.get(f'/api/v1/businesses/{b.identifier}/filings/1/comments', headers=create_header(jwt, [STAFF_ROLE])) assert HTTPStatus.NOT_FOUND == rv.status_code assert 'Filing 1 not found' == rv.json.get('message')
def test_get_empty_tasks_with_invalid_business(session, client, jwt): """Assert that an empty filings array is returned when business does not exist.""" identifier = 'CP7654321' rv = client.get(f'/api/v1/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.OK print('rv json', rv.json) assert rv.json == {'tasks': []}
def test_get_comments_invalid_business_error(session, client, jwt): """Assert that error is returned when business doesn't exist.""" factory_business('CP1111111') rv = client.get('/api/v1/businesses/CP2222222/comments', headers=create_header(jwt, [STAFF_ROLE])) assert HTTPStatus.NOT_FOUND == rv.status_code assert 'CP2222222 not found' == rv.json.get('message')
def test_bcorps_get_tasks_no_filings(session, client, jwt): """Assert that to-do for the current year is returned when there are no filings.""" identifier = 'CP7654321' factory_business(identifier, datetime.now(), None, Business.LegalTypes.BCOMP.value) rv = client.get(f'/api/v1/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.OK assert len(rv.json.get('tasks')) == 0 # To-do for the current year
def test_post_not_authorized_draft_ar(session, client, jwt): """Assert that a unpaid filing can be posted.""" identifier = 'CP7654321' factory_business(identifier) rv = client.post(f'/api/v1/businesses/{identifier}/filings?draft=true', json=ANNUAL_REPORT, headers=create_header(jwt, [BASIC_USER], 'WRONGUSER')) assert rv.status_code == HTTPStatus.UNAUTHORIZED
def test_post_authorized_draft_ar(session, client, jwt): """Assert that a unpaid filing can be posted.""" identifier = 'CP7654321' factory_business(identifier) rv = client.post(f'/api/v1/businesses/{identifier}/filings?draft=true', json=ANNUAL_REPORT, headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.CREATED
def test_post_filing_no_business(session, client, jwt): """Assert that a filing cannot be created against non-existent business.""" identifier = 'CP7654321' rv = client.post(f'/api/v1/businesses/{identifier}/filings', json=AR_FILING, headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.NOT_FOUND assert rv.json['errors'][0] == {'message': f'{identifier} not found'}
def test_financing_get_staff_missing_account_200(session, client, jwt): """Assert that a get financing statement request with a staff jwt and no account ID returns a 200 status.""" # setup # test rv = client.get('/api/v1/financing-statements/TEST0001', headers=create_header(jwt, [PPR_ROLE, STAFF_ROLE])) # check assert rv.status_code == HTTPStatus.OK
def test_financing_get_nonstaff_missing_account_400(session, client, jwt): """Assert that a get financing statement request with a non-staff jwt and no account ID returns a 400 status.""" # setup # test rv = client.get('/api/v1/financing-statements/TEST0001', headers=create_header(jwt, [COLIN_ROLE])) # check assert rv.status_code == HTTPStatus.BAD_REQUEST
def test_financing_list_staff_missing_account_400(session, client, jwt): """Assert that a list financing statements request with a staff jwt and no account ID returns a 400 status.""" # setup # test rv = client.get('/api/v1/financing-statements', headers=create_header(jwt, [PPR_ROLE])) # check assert rv.status_code == HTTPStatus.BAD_REQUEST
def test_get_comment_invalid_commentid_error(session, client, jwt): """Assert that error is returned when comment ID doesn't exist.""" b = factory_business('CP1111111') f = factory_filing(b, ANNUAL_REPORT) rv = client.get(f'/api/v2/businesses/{b.identifier}/filings/{f.id}/comments/1', headers=create_header(jwt, [STAFF_ROLE])) assert HTTPStatus.NOT_FOUND == rv.status_code assert 'Comment 1 not found' == rv.json.get('message')
def test_delete_filing_not_authorized(session, client, jwt): """Assert that a users is authorized to delete a filing.""" identifier = 'CP7654321' b = factory_business(identifier) filings = factory_filing(b, ANNUAL_REPORT) headers = create_header(jwt, ['BAD ROLE'], identifier) rv = client.delete(f'/api/v1/businesses/{identifier}/filings/{filings.id}', headers=headers) assert rv.status_code == HTTPStatus.UNAUTHORIZED
def test_search_history_missing_account_400(session, client, jwt): """Assert that a search history request with no account ID returns a 400 status.""" # no setup # test rv = client.get('/api/v1/search-history', headers=create_header(jwt, [PPR_ROLE])) # check assert rv.status_code == HTTPStatus.BAD_REQUEST
def test_get_all_business_comments_no_results(session, client, jwt): """Assert that endpoint returns no-results correctly.""" identifier = 'CP7654321' factory_business(identifier) rv = client.get(f'/api/v1/businesses/{identifier}/comments', headers=create_header(jwt, [STAFF_ROLE])) assert rv.status_code == HTTPStatus.OK assert 0 == len(rv.json.get('comments'))
def test_delete_comment_error(session, client, jwt): """Assert that the DELETE endpoint isn't allowed.""" b = factory_business('CP1111111') f = factory_filing(b, ANNUAL_REPORT) c = factory_comment(b, f) rv = client.delete(f'/api/v2/businesses/{b.identifier}/filings/{f.id}/comments/{c.id}', headers=create_header(jwt, [STAFF_ROLE])) assert HTTPStatus.METHOD_NOT_ALLOWED == rv.status_code
def test_bcorp_get_tasks_prev_year_incomplete_filing_exists(session, client, jwt): """Assert that the one incomplete filing for previous year and a to-do for current year are returned.""" identifier = 'CP7654321' b = factory_business(identifier, datetime.now() - datedelta.datedelta(years=2), last_ar_date=datetime(2018, 3, 3)) filings = factory_filing(b, AR_FILING_PREVIOUS_YEAR, datetime(2018, 8, 5, 7, 7, 58, 272362)) print('test_get_all_business_filings - filing:', filings) rv = client.get(f'/api/v1/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.OK
def test_update_user_profile(session, client, jwt, desc, staff, include_account, status, role, data): """Assert that updating a user profile returns the expected response code and data.""" # setup headers = None if include_account: if staff: headers = create_header_account(jwt, [role, STAFF_ROLE]) else: headers = create_header_account(jwt, [role]) else: if staff: headers = create_header(jwt, [role, STAFF_ROLE]) else: headers = create_header(jwt, [role]) # create profile client.get('/api/v1/user-profile', headers=headers) # test rv = client.patch('/api/v1/user-profile', json=data, headers=headers, content_type='application/json') # check assert rv.status_code == status if rv.status_code == HTTPStatus.OK: response_data = rv.json assert response_data assert 'paymentConfirmationDialog' in response_data assert 'selectConfirmationDialog' in response_data assert 'defaultDropDowns' in response_data assert 'defaultTableFilters' in response_data if desc == 'Valid registration table': assert 'registrationsTable' in response_data assert response_data[ 'registrationsTable'] == TEST_UPDATE_REG_TABLE_JSON[ 'registrationsTable'] elif desc == 'Valid miscellaneous preferences': assert 'miscellaneousPreferences' in response_data assert response_data[ 'miscellaneousPreferences'] == TEST_UPDATE_MISC_JSON[ 'miscellaneousPreferences']
def test_get_tasks_next_year(session, client, jwt): """Assert that one todo item is returned in the calendar year following incorporation.""" identifier = 'CP7654321' founding_date = datetime.today() + datedelta.datedelta(days=1) - datedelta.datedelta(years=1) factory_business(identifier, founding_date=founding_date) # incorporation 1 year - 1 day ago # To-do are all years from the year after incorporation until this year rv = client.get(f'/api/v1/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.OK assert 1 == len(rv.json.get('tasks'))
def test_get_tasks_current_year_filing_exists(session, client, jwt): """Assert that only the filing for the current year is returned when only current year filing exists.""" identifier = 'CP7654321' b = factory_business(identifier=identifier, last_ar_date=datetime(2018, 8, 13)) filings = factory_filing(b, AR_FILING_CURRENT_YEAR, datetime(2019, 8, 5, 7, 7, 58, 272362), 'annualReport') print('test_get_all_business_filings - filing:', filings) rv = client.get(f'/api/v1/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.OK
def test_delete_filing_in_draft(session, client, jwt): """Assert that a draft filing can be deleted.""" identifier = 'CP7654321' b = factory_business(identifier) filings = factory_filing(b, ANNUAL_REPORT) headers = create_header(jwt, [STAFF_ROLE], identifier) rv = client.delete(f'/api/v1/businesses/{identifier}/filings/{filings.id}', headers=headers) assert rv.status_code == HTTPStatus.OK