def test_ResourceNotFound_categories_with_suppressed_error(): Client.config({'suppress_http_errors': True}) client = Client('test_id', 'test_secret') response = client.category('pnc') assert response.status_code == 404 assert ( json.loads(response.content)['message'] == 'unable to find category' )
def http_request(url, method=None, data=None, suppress_errors=False): response = _base_http_request(url, method, data or {}) ERROR = PLAID_ERROR_MAP.get(response.status_code) if not suppress_errors and ERROR is not None: json_data = json.loads(response.content) raise ERROR(json_data['resolve'], json_data['code']) else: return response
def inner_func(self, *args, **kwargs): response = func(self, *args, **kwargs) if response.ok: json_data = json.loads(response.content.decode('utf-8'))#my chang self.access_token = json_data.get( 'access_token', self.access_token ) return response
from collections import defaultdict import pytest from mock import patch, Mock from plaid import Client from plaid.utils import json from plaid.errors import ( ResourceNotFoundError, UnauthorizedError ) to_json = lambda response: json.loads(response.content) no_mfa_credentials = { 'username': '******', 'password': '******', } def test_auth_no_mfa(): client = Client('test_id', 'test_secret') response = client.auth('wells', no_mfa_credentials) assert to_json(response)['access_token'] == 'test_wells' def test_auth_mfa(): client = Client('test_id', 'test_secret') response = client.auth('pnc', no_mfa_credentials) assert response.status_code == 201 assert to_json(response)['type'] == 'questions'
def check_plaid_event( self, username): #checks the database ids and plaid ids for differences plaid_list = self.get_list_of_restraunt_transactions(username) obj = SQLConnection() user_id = obj.find_id_of_user(username) database_list = obj.get_users_transactions(username) test = list(set(plaid_list) - set(database_list)) if test != []: #if there is a difference aka update data = self.plaid_results data = json.loads(data) for items in test: for things in data['transactions']: if things['_id'] == items: fast_food = False for classifications in things["category"]: if classifications == "Fast Food": fast_food = True if fast_food == True: obj.add_event_list(user_id, "1") obj.add_plaid_transactions_in_db( user_id, things['_id']) obj.change_xp(username, -500) else: obj.add_event_list(user_id, "2") obj.add_plaid_transactions_in_db( user_id, things['_id']) obj.change_xp(username, -250) return "done" # plaid().check_plaid_event("rwr21") #plaid().check_plaid_event("rwr21") # print type(response) # print type (response.content) # d = json.loads(response.content) # #print d # print type(d) # # print response.content # for items in d['transactions']: # #TODO SQL DATABSE TO KEEP TRACK OF LVL FAST FOOD -200 restraunt -100 # # print items['date'] # try: # for things in items['category']: # fast_food=False # if things=="Fast Food": #finds if user bought fast food # fast_food=True # #print items['name'] # if fast_food==False: # for things in items['category']: # if things=="Restaurants": # print things # print items['name']#finds name of restraunt that is not fast food # except: # pass # #print items # #print type (response.content.) # # User connected # data = response.json() # #rint SQLConnection().get_users_transactions("rwr21") #plaid().first_time_plaid_transactions("rwr21") #print plaid().use_token("rwr21") #plaid().create_user("rwr21","chase","rratcliffe57",p) #plaid().check_plaid_event("rwr21")