def test_get_receipt(session, client, jwt, requests_mock): """Assert that a receipt is generated.""" from legal_api.resources.v2.business.business_filings.business_documents import _get_receipt # Setup identifier = 'CP7654321' business = factory_business(identifier) filing_name = 'incorporationApplication' payment_id = '12345' filing_json = copy.deepcopy(FILING_HEADER) filing_json['filing']['header']['name'] = filing_name filing_json['filing'][filing_name] = INCORPORATION filing_json['filing'].pop('business') filing_date = datetime.utcnow() filing = factory_filing(business, filing_json, filing_date=filing_date) filing.skip_status_listener = True filing._status = 'PAID' filing._payment_token = payment_id filing.save() filing_core = Filing() filing_core._storage = filing requests_mock.post(f"{current_app.config.get('PAYMENT_SVC_URL')}/{payment_id}/receipts", json={'foo': 'bar'}, status_code=HTTPStatus.CREATED) token = helper_create_jwt(jwt, roles=[STAFF_ROLE], username='******') content, status_code = _get_receipt(business, filing_core, token) assert status_code == HTTPStatus.CREATED assert requests_mock.called_once
def test_payment_staff_search_mock(client, jwt, pay_trans_type, routing_slip, bcol_number, dat_number, waive_fees): """Assert that a pay-api staff search payment request works as expected with the mock service endpoint.""" # setup token = helper_create_jwt(jwt, [PPR_ROLE]) payment = Payment(jwt=token, account_id='PS12345', details=PAY_DETAILS_SEARCH) payment.api_url = MOCK_URL_NO_KEY transaction_info = {'transactionType': pay_trans_type} if pay_trans_type in (TransactionTypes.SEARCH_STAFF_CERTIFIED_NO_FEE.value, TransactionTypes.SEARCH_STAFF_NO_FEE.value): transaction_info['certified'] = True if routing_slip: transaction_info['routingSlipNumber'] = routing_slip if bcol_number: transaction_info['bcolAccountNumber'] = bcol_number if dat_number: transaction_info['datNumber'] = dat_number # test pay_data = payment.create_payment_staff_search(transaction_info, 'UT-PAY-SEARCH-01') # print(pay_data) # check assert pay_data assert pay_data['invoiceId'] assert pay_data['receipt']
def test_payment_staff_registration_mock(client, jwt, pay_trans_type, routing_slip, bcol_number, dat_number, waive_fees): """Assert that a pay-api staff registration payment request works as expected with the mock service endpoint.""" # setup token = helper_create_jwt(jwt, [PPR_ROLE]) payment = Payment(jwt=token, account_id=None, details=PAY_DETAILS_REGISTRATION) payment.api_url = MOCK_URL_NO_KEY transaction_info = {'transactionType': pay_trans_type, 'feeQuantity': 1} if waive_fees: transaction_info['waiveFees'] = True if routing_slip: transaction_info['routingSlipNumber'] = routing_slip if bcol_number: transaction_info['bcolAccountNumber'] = bcol_number if dat_number: transaction_info['datNumber'] = dat_number # test pay_data = payment.create_payment_staff_registration( transaction_info, 'UT-PAY-SEARCH-01') # print(pay_data) # check assert pay_data assert pay_data['invoiceId'] assert pay_data['receipt']
def test_sa_get_token(client, jwt): """Assert that an OIDC get token request with valid SA credentials works as expected.""" # setup token = helper_create_jwt(jwt, [PPR_ROLE]) pay_client = SBCPaymentClient(jwt=token, account_id='PS12345') # test jwt = pay_client.get_sa_token() # check assert jwt assert len(jwt) > 0
def test_client_exception(client, jwt): """Assert that the pay-api client works as expected with an unuathorized exception.""" # setup token = helper_create_jwt(jwt, [PPR_ROLE]) pay_client = SBCPaymentClient(jwt=token, account_id='PS12345') pay_client.api_url = MOCK_URL # test with pytest.raises(ApiRequestError) as request_err: pay_client.create_payment(TransactionTypes.SEARCH.value, 1, '200000001', 'UT-PAY-SEARCH-01') assert request_err
def test_payment_exception(client, jwt): """Assert that a pay-api payment request works as expected with a 500 exception.""" # setup token = helper_create_jwt(jwt, [PPR_ROLE]) payment = Payment(jwt=token, account_id='PS12345') payment.api_url = MOCK_URL # test with pytest.raises(SBCPaymentException) as request_err: payment.create_payment(TransactionTypes.SEARCH.value, 1, '200000001', 'UT-PAY-SEARCH-01') assert request_err assert request_err.value.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
def test_get_account_name(session, client, jwt, desc, account_id, has_name): """Assert that a get user profile returns the expected response code and data.""" # setup current_app.config.update(AUTH_SVC_URL=MOCK_URL_NO_KEY) token = helper_create_jwt(jwt, [PPR_ROLE]) if has_name else None # test name = resource_utils.get_account_name(token, account_id) # check if has_name: assert name else: assert not name
def test_payment_search_mock(client, jwt): """Assert that a pay-api search payment request works as expected with the mock service endpoint.""" # setup token = helper_create_jwt(jwt, [PPR_ROLE]) payment = Payment(jwt=token, account_id='PS12345') payment.api_url = MOCK_URL_NO_KEY # test pay_data = payment.create_payment(TransactionTypes.SEARCH.value, 1, '200000001', 'UT-PAY-SEARCH-01') print(pay_data) # check assert pay_data assert pay_data['invoiceId'] assert pay_data['receipt']
def test_payment_apikey(client, jwt): """Assert that a gateway pay-api payment request works as expected.""" # setup apikey = os.getenv('PAYMENT_GATEWAY_APIKEY_TEST') if apikey: token = helper_create_jwt(jwt, [PPR_ROLE]) payment = Payment(jwt=token, account_id='PS12345', api_key=apikey) payment.api_url = MOCK_URL # test pay_data = payment.create_payment(TransactionTypes.SEARCH.value, 1, '200000001', 'UT-PAY-SEARCH-01') print(pay_data) # check assert pay_data assert pay_data['invoiceId'] assert pay_data['receipt']
def test_user_orgs_mock(client, jwt): """Assert that a auth-api user orgs request works as expected with the mock service endpoint.""" # setup current_app.config.update(AUTH_SVC_URL=MOCK_URL_NO_KEY) # print('env auth-api url=' + current_app.config.get('AUTH_SVC_URL')) token = helper_create_jwt(jwt, [authz.PPR_ROLE]) # test org_data = authz.user_orgs(token) print(org_data) # check assert org_data assert 'orgs' in org_data assert len(org_data['orgs']) == 1 org = org_data['orgs'][0] assert org['orgStatus'] == 'ACTIVE' assert org['statusCode'] == 'ACTIVE' assert org['orgType'] == 'PREMIUM' assert org['id'] assert org['name']