def test_get_by_id_with_include_optional_metadata(): client = create_client() response = client.Institutions.get_by_id( SANDBOX_INSTITUTION, [SANDBOX_INSTITUTION_COUNTRY_CODE], _options={ 'include_optional_metadata': True, }) assert response['institution']['institution_id'] == SANDBOX_INSTITUTION
def test_get(): client = create_client() response = client.Identity.get(access_token) assert response['accounts'] is not None for account in response['accounts']: assert account['owners'] is not None assert len(account['owners']) > 0
def test_dwolla_processor_token(): client = create_client() # Just test the failure case - behavior here depends on the API keys used with pytest.raises(InvalidRequestError) as e: client.Processor.dwollaBankAccountTokenCreate('fakeAccessToken', 'fakeAccountId') assert e.code == 'INVALID_INPUT'
def test_all_payment_routes_with_bacs(): client = create_client() bacs = { 'account': '12345678', 'sort_code': '01-02-03', } # create recipient response = client.PaymentInitiation.create_recipient( 'John Doe', None, { 'street': ['street name 999'], 'city': 'city', 'postal_code': '99999', 'country': 'GB', }, bacs, ) recipient_id = response['recipient_id'] assert recipient_id is not None # get recipient response = client.PaymentInitiation.get_recipient(recipient_id) assert response['recipient_id'] is not None assert response['name'] is not None assert response['bacs'] is not None assert response['address'] is not None payments_after_recipient_creation(client, recipient_id)
def test_full_flow(): client = create_client() # get account id account_id_response = client.Accounts.get(access_token) assert len(account_id_response['accounts']) != 0 target_account_id = account_id_response['accounts'][0]['account_id'] # create deposit switch create_response = client.DepositSwitch.create(target_account_id, access_token) assert create_response['deposit_switch_id'] is not None deposit_switch_id = create_response['deposit_switch_id'] # get deposit switch get_response = client.DepositSwitch.get(deposit_switch_id) assert get_response['deposit_switch_id'] is not None assert get_response['target_item_id'] is not None assert get_response['target_account_id'] is not None assert get_response['date_created'] is not None assert get_response['state'] is not None # create deposit switch token token_response = client.DepositSwitch.create_token(deposit_switch_id) assert token_response['deposit_switch_token'] is not None assert token_response['deposit_switch_token_expiration_time'] is not None
def test_all_payment_routes_with_iban(): client = create_client() # create recipient response = client.PaymentInitiation.create_recipient( 'John Doe', 'GB33BUKB20201555555555', { 'street': ['street name 999'], 'city': 'city', 'postal_code': '99999', 'country': 'GB', }, None ) recipient_id = response['recipient_id'] assert recipient_id is not None # get recipient response = client.PaymentInitiation.get_recipient(recipient_id) assert response['recipient_id'] is not None assert response['name'] is not None assert response['iban'] is not None assert response['address'] is not None payments_after_recipient_creation(client, recipient_id)
def test_get(): client = create_client() response = client.Identity.get(access_token) assert response['accounts'] is not None for account in response['accounts']: assert account['owners'] is not None assert len(account['owners']) > 0
def test_search_with_include_optional_metadata(): client = create_client() response = client.Institutions.search( SANDBOX_INSTITUTION_NAME, _options={ 'include_optional_metadata': True, }) assert len(response['institutions']) >= 1
def test_link_token_create_optional(): client = create_client() # build the configs configs = { 'user': { 'client_user_id': str(time.time()), }, 'products': ["auth", "transactions"], 'client_name': "Plaid Test", 'country_codes': ['GB'], 'language': 'en', 'webhook': 'https://sample-webhook-uri.com', 'link_customization_name': 'default', 'account_filters': { 'depository': { 'account_subtypes': ['checking', 'savings'], }, }, } # create link token response = client.LinkToken.create(configs) # assert on response assert response['link_token'] is not None assert response['expiration'] is not None
def test_get(): client = create_client() response = client.Holdings.get(access_token) assert response['item'] is not None assert response['accounts'] is not None assert response['securities'] is not None assert response['holdings'] is not None
def test_delete(): client = create_client() create_response = client.Item.create(CREDENTIALS, SANDBOX_INSTITUTION, ['transactions']) delete_response = client.Item.delete(create_response['access_token']) assert delete_response['deleted']
def test_remove(): client = create_client() create_response = client.Item.create(CREDENTIALS, SANDBOX_INSTITUTION, ['transactions']) remove_response = client.Item.remove(create_response['access_token']) assert remove_response['removed']
def test_import(): client = create_client() at_response = client.Item.import_item(['identity', 'auth'], { 'user_id': 'user_good', 'auth_token': 'pass_good' }, None) assert at_response['access_token'] is not None
def test_dwolla_processor_token(): client = create_client() # Just test the failure case - behavior here depends on the API keys used with pytest.raises(InvalidRequestError) as e: client.Processor.dwollaBankAccountTokenCreate( 'fakeAccessToken', 'fakeAccountId') assert e.code == 'INVALID_INPUT'
def test_search_with_products(): client = create_client() response = client.Institutions.search( SANDBOX_INSTITUTION_NAME, [SANDBOX_INSTITUTION_COUNTRY_CODE], products=['transactions']) assert len(response['institutions']) >= 1
def setup_module(module): client = create_client() pt_response = client.Sandbox.public_token.create(BALANCE_INSTITUTION, ['transactions']) exchange_response = client.Item.public_token.exchange( pt_response['public_token']) global access_token access_token = exchange_response['access_token']
def test_get_with_options(): client = create_client() response = client.Transactions.get(access_token, '2016-01-01', '2017-01-01', count=2, offset=1) assert len(response['transactions']) == 2
def test_get(): client = create_client() create_response = client.Item.create(CREDENTIALS, SANDBOX_INSTITUTION, ['transactions']) with ensure_item_deleted(create_response['access_token']): get_response = client.Item.get(create_response['access_token']) assert get_response['item'] is not None
def setup_module(module): client = create_client() pt_response = client.Sandbox.public_token.create( SANDBOX_INSTITUTION, ['liabilities']) exchange_response = client.Item.public_token.exchange( pt_response['public_token']) global access_token access_token = exchange_response['access_token']
def test_add_token(): client = create_client() create_response = client.Item.add_token.create({ 'client_user_id': str(time.time()), }) assert create_response['add_token'] is not None assert create_response['expiration'] is not None
def setup_module(module): client = create_client() pt_response = client.Sandbox.public_token.create( SANDBOX_INSTITUTION, ['auth']) exchange_response = client.Item.public_token.exchange( pt_response['public_token']) global access_token access_token = exchange_response['access_token']
def test_remove(): client = create_client() pt_response = client.Sandbox.public_token.create(SANDBOX_INSTITUTION, ['transactions']) exchange_response = client.Item.public_token.exchange( pt_response['public_token']) client.Item.remove(exchange_response['access_token'])
async def test_search_with_include_optional_metadata(): client = create_client() response = await client.Institutions.search( SANDBOX_INSTITUTION_NAME, _options={ 'include_optional_metadata': True, }) assert len(response['institutions']) >= 1
def test_public_token(): client = create_client() pt_response = client.Sandbox.public_token.create( SANDBOX_INSTITUTION, ['transactions']) exchange_response = client.Item.public_token.exchange( pt_response['public_token']) with ensure_item_removed(exchange_response['access_token']): assert pt_response['public_token'] is not None assert exchange_response['access_token'] is not None
def test_get_with_options(): client = create_client() response = get_transactions_with_retries(client, access_token, '2018-01-01', '2019-01-01', count=2, offset=1) assert len(response['transactions']) == 2
def test_get_with_options(): client = create_client() response = get_transactions_with_retries(client, access_token, START_DATE, END_DATE, count=2, offset=1) assert len(response['transactions']) == 2
def test_remove(): client = create_client() pt_response = client.Sandbox.public_token.create( SANDBOX_INSTITUTION, ['transactions']) exchange_response = client.Item.public_token.exchange( pt_response['public_token']) remove_response = client.Item.remove(exchange_response['access_token']) assert remove_response['removed']
def test_public_token(): client = create_client() pt_response = client.Sandbox.public_token.create(SANDBOX_INSTITUTION, ['transactions']) exchange_response = client.Item.public_token.exchange( pt_response['public_token']) with ensure_item_removed(exchange_response['access_token']): assert pt_response['public_token'] is not None assert exchange_response['access_token'] is not None
def test_add_token_with_user(): client = create_client() user = { 'phone_number': '+1 415 555 0123', 'email_address': '*****@*****.**', 'phone_number_verified_time': '2020-01-01T00:00:00Z', } create_response = client.Item.add_token.create(user=user) assert create_response['add_token'] is not None assert create_response['expiration'] is not None
def test_webhook_update(): client = create_client() create_response = client.Item.create(CREDENTIALS, SANDBOX_INSTITUTION, ['transactions']) with ensure_item_deleted(create_response['access_token']): webhook_response = client.Item.webhook.update( create_response['access_token'], 'https://plaid.com/webhook-test') assert (webhook_response['item']['webhook'] == 'https://plaid.com/webhook-test')
def setup_module(module): client = create_client() # import an item at_response = client.Item.import_item(['identity', 'auth'], { 'user_id': 'user_good', 'auth_token': 'pass_good' }, None) assert at_response['access_token'] is not None global access_token access_token = at_response['access_token']
def test_create(): client = create_client() response = client.Item.create(CREDENTIALS, SANDBOX_INSTITUTION, ['transactions']) with ensure_item_deleted(response['access_token']): assert response['access_token'] is not None assert response['item']['billed_products'] == ['transactions'] assert response['item']['institution_id'] == SANDBOX_INSTITUTION assert response.get('mfa_type') is None
def test_sandbox_public_token(): client = create_client() create_response = client.Sandbox.public_token.create( SANDBOX_INSTITUTION, ['transactions']) assert create_response['public_token'] is not None # public token -> access token exchange_response = client.Item.public_token.exchange( create_response['public_token']) assert exchange_response['access_token'] is not None
def test_sandbox_public_token(): client = create_client() create_response = client.Sandbox.public_token.create( SANDBOX_INSTITUTION, ['transactions']) assert create_response['public_token'] is not None # public token -> access token exchange_response = client.Item.public_token.exchange( create_response['public_token']) assert exchange_response['access_token'] is not None
def setup_module(_module): client = create_client() pt_response = client.Sandbox.public_token.create( SANDBOX_INSTITUTION, ['investments'], transactions__start_date='2018-01-01', transactions__end_date='2019-01-01', ) exchange_response = client.Item.public_token.exchange( pt_response['public_token']) global access_token access_token = exchange_response['access_token']
def test_get(): client = create_client() # get all accounts response = client.Accounts.get(access_token) assert response['accounts'] is not None # get selected accounts account_id = response['accounts'][0]['account_id'] response = client.Accounts.get(access_token, account_ids=[account_id]) assert len(response['accounts']) == 1
def test_mfa_questions(): client = create_client() item_response = client.Item.create(MFA_QUESTIONS_CREDENTIALS, SANDBOX_INSTITUTION, ['transactions']) with ensure_item_deleted(item_response['access_token']): assert item_response['mfa_type'] == 'questions' mfa_response = client.Item.mfa(item_response['access_token'], 'questions', ['answer_0_0']) assert mfa_response['item'] is not None
def test_get(): client = create_client() # get all accounts response = client.Accounts.get(access_token) assert response['accounts'] is not None # get selected accounts account_id = response['accounts'][0]['account_id'] response = client.Accounts.get(access_token, account_ids=[account_id]) assert len(response['accounts']) == 1
def test_webhook_update(): client = create_client() pt_response = client.Sandbox.public_token.create( SANDBOX_INSTITUTION, ['transactions']) exchange_response = client.Item.public_token.exchange( pt_response['public_token']) with ensure_item_removed(exchange_response['access_token']): webhook_response = client.Item.webhook.update( exchange_response['access_token'], 'https://plaid.com/webhook-test') assert (webhook_response['item']['webhook'] == 'https://plaid.com/webhook-test')
def test_access_token_invalidate(): client = create_client() pt_response = client.Sandbox.public_token.create( SANDBOX_INSTITUTION, ['transactions']) exchange_response = client.Item.public_token.exchange( pt_response['public_token']) try: invalidate_response = client.Item.access_token.invalidate( exchange_response['access_token']) with ensure_item_removed(invalidate_response['new_access_token']): assert invalidate_response['new_access_token'] is not None except Exception: with ensure_item_removed(exchange_response['access_token']): raise
def test_get_with_include_optional_metadata(): client = create_client() response = client.Institutions.get(3, offset=1, _options={ 'include_optional_metadata': True, }) assert len(response['institutions']) == 3 assert len(response['institutions'][0]['url']) > 0 assert len(response['institutions'][0]['logo']) > 0 assert len(response['institutions'][0]['primary_color']) > 0 assert len(response['institutions'][1]['url']) > 0 assert len(response['institutions'][1]['logo']) > 0 assert len(response['institutions'][1]['primary_color']) > 0 assert len(response['institutions'][2]['url']) > 0 assert len(response['institutions'][2]['logo']) > 0 assert len(response['institutions'][2]['primary_color']) > 0
def test_sandbox_fire_webhook(): client = create_client() create_response = client.Sandbox.public_token.create( SANDBOX_INSTITUTION, ['transactions'], webhook='https://plaid.com/foo/bar/hook') assert create_response['public_token'] is not None # public token -> access token exchange_response = client.Item.public_token.exchange( create_response['public_token']) assert exchange_response['access_token'] is not None # fire webhook fire_webhook_response = client.Sandbox.item.fire_webhook( exchange_response['access_token'], 'DEFAULT_UPDATE' ) assert fire_webhook_response['webhook_fired'] is True
def test_get(): client = create_client() # get auth for all accounts response = client.Auth.get(access_token) assert response['accounts'] is not None assert response['numbers'] is not None # get auth for selected accounts account_id = response['accounts'][0]['account_id'] response = client.Auth.get(access_token, account_ids=[account_id]) for key in [ 'eft', 'ach', 'international', 'bacs', ]: assert key in response['numbers']
def test_get_by_id_with_include_optional_metadata(): client = create_client() response = client.Institutions.get_by_id(SANDBOX_INSTITUTION, _options={ 'include_optional_metadata': True, }) assert response['institution']['institution_id'] == SANDBOX_INSTITUTION
def ensure_item_removed(access_token): try: yield finally: create_client().Item.remove(access_token)
def test_full_flow(): client = create_client() # create an asset report for one item options = { 'client_report_id': '123', 'webhook': 'https://www.example.com', 'user': { 'client_user_id': '789', 'first_name': 'Jane', 'middle_name': 'Leah', 'last_name': 'Doe', 'ssn': '123-45-6789', 'phone_number': '(555) 123-4567', 'email': '*****@*****.**', } } response = client.AssetReport.create( [access_token], days_requested=60, options=options) asset_report_token = response['asset_report_token'] asset_report_id = response['asset_report_id'] assert asset_report_token is not None assert asset_report_id is not None # retrieve the asset report response = poll_for_asset_report(client, asset_report_token) report = response['report'] assert report is not None # retrieve the asset report as an Asset Report with Insights response = client.AssetReport.get(asset_report_token, True) report = response['report'] assert report is not None # The transactions in an Asset Report with Insights should have a non-null # `name` (when available). assert ( name_exists_for_some_transaction(report)) # retrieve the asset report as a PDF pdf = client.AssetReport.get_pdf(asset_report_token) assert pdf is not None # create a filtered copy of the asset report account_ids_to_exclude = [report['items'][0]['accounts'][0]['account_id']] response = client.AssetReport.filter( asset_report_token, account_ids_to_exclude) assert response['asset_report_token'] is not None # create a refreshed copy of the asset report response = client.AssetReport.refresh(asset_report_token, 10) assert response['asset_report_token'] is not None # create an audit copy response = client.AssetReport.audit_copy.create( asset_report_token, client.client_id) audit_copy_token = response['audit_copy_token'] assert audit_copy_token is not None # get the audit copy response = client.AssetReport.audit_copy.get(audit_copy_token) audit_copy = response['report'] assert audit_copy is not None # remove the audit copy token response = client.AssetReport.audit_copy.remove(audit_copy_token) removed = response['removed'] assert removed # remove the asset report response = client.AssetReport.remove(asset_report_token) removed = response['removed'] assert removed
def test_get(): client = create_client() try: client.Income.get(access_token) except ItemError as ie: assert ie.code == u'PRODUCT_NOT_READY'
def test_get(): client = create_client() response = client.CreditDetails.get(access_token) assert response['accounts'] is not None assert response['credit_details'] is not None
def test_get(): client = create_client() response = client.Institutions.get(3, offset=1) assert len(response['institutions']) == 3
def teardown_module(module): client = create_client() client.Item.remove(access_token)
def test_search(): client = create_client() response = client.Institutions.search(SANDBOX_INSTITUTION_NAME) assert len(response['institutions']) >= 1
def test_search_with_products(): client = create_client() response = client.Institutions.search( SANDBOX_INSTITUTION_NAME, products=['transactions']) assert len(response['institutions']) >= 1
def test_get_by_id(): client = create_client() response = client.Institutions.get_by_id(SANDBOX_INSTITUTION) assert response['institution']['institution_id'] == SANDBOX_INSTITUTION
def test_get(): client = create_client() response = client.Categories.get() assert response['categories'] is not None