def get(entity_id): """Creates an entity with given entity_id and returns the instance arguments: entity_id -- the entity id string (UUID version 4) """ if not entity_id: raise ValueError("entity_id cannot be blank or None") if not type(entity_id) == str: raise ValueError("entity_id must be a string") if not is_valid_uuid4(entity_id): raise ValueError("invalid entity_id") return Entity(source='g', entity_id=entity_id)
def get_debit_recurring(self, reload=False, account_id=None): """Fetches and returns the iterator to debit recurring transactions (list of dictionary) for the given entity arguments: reload (optional) (default: False) -- do not use cached data and refetch from API account_id (optional) -- get debit recurring transactions for specific account_id """ if account_id is not None: if not is_valid_uuid4(account_id): raise ValueError( "account_id if provided must be a valid UUID4 string") if reload or not self.__is_loaded['debit_recurring']: self.__fetch_recurring() if account_id is not None: account_id_filter = make_account_id_filter(account_id) return filter(account_id_filter, self.__debit_recurring) return iter(self.__debit_recurring)
def test_none(self): self.assertEqual(is_valid_uuid4(None), False, "list detected as valid uui4")
def test_list(self): self.assertEqual(is_valid_uuid4(["sadasd", "asdasd"]), False, "list detected as valid uui4")
def test_integer(self): self.assertEqual(is_valid_uuid4(123), False, "integer detected as valid uui4")
def test_string_not_uuid4(self): self.assertEqual(is_valid_uuid4("abc"), False, "invalid uuid4 string detected as valid")
def test_uuid4_without_hyphen(self): self.assertEqual(is_valid_uuid4("c036e96dccae443c8f64b98ceeaa1578"), False, "valid uuid4 without hyphen must be invalid")
def test_valid_uuid4(self): self.assertEqual( is_valid_uuid4("c036e96d-ccae-443c-8f64-b98ceeaa1578"), True, "valid uuid4 detected as invalid")
def test_entity_creation(self): entity = fbc.Entity.create(link_id="python_link_id_test_1") entity_id = entity.entity_id self.assertEqual(is_valid_uuid4(entity_id), True, "entity_id couldn't be created against the link_id")
def get_lender_transactions(self, reload=False, account_id=None, from_date=None, to_date=None): """Fetches and returns the iterator to lender transactions (list of dictionary) for the given entity arguments: reload (optional) (default: False) -- do not use cached data and refetch from API account_id (optional) -- get lender transactions for specific account_id from_date (optional) -- get lender transactions greater than or equal to from_date (must be datetime.date) to_date (optional) -- get lender transactions less than or equal to to_date (must be datetime.date) """ if not self.__is_loaded['entity_id']: raise ValueError( "no statement uploaded yet so use upload_statement method to set the entity_id" ) if account_id is not None: if not is_valid_uuid4(account_id): raise ValueError( "account_id if provided must be a valid UUID4 string") if from_date is not None: if not type(from_date) == datetime.date: raise ValueError( "from_date if provided must be a python datetime.date object" ) if to_date is not None: if not type(to_date) == datetime.date: raise ValueError( "to_date if provided must be a python datetime.date object" ) if reload or not self.__is_loaded['lender_transactions']: timer_start = time.time() while time.time( ) < timer_start + finbox_bankconnect.poll_timeout: # keep polling till timeout happens status, accounts, fraud_info, lender_transactions = connector.get_lender_transactions( self.__entity_id) if status == "failed": raise ExtractionFailedError elif status == "not_found": raise EntityNotFoundError elif status == "completed": # save accounts self.__accounts = accounts self.__is_loaded['accounts'] = True # save fraud info self.__fraud_info = fraud_info self.__is_loaded['fraud_info'] = True # save info self.__lender_transactions = lender_transactions self.__is_loaded['lender_transactions'] = True break time.sleep(finbox_bankconnect.poll_interval ) # delay of finbox_bankconnect.poll_interval if not self.__is_loaded['lender_transactions']: # if even after polling couldn't get raise ServiceTimeOutError if account_id is not None: account_id_filter = make_account_id_filter(account_id) return filter(account_id_filter, self.__lender_transactions) if from_date is not None or to_date is not None: daterange_filter = make_daterange_filter(from_date, to_date) return filter(daterange_filter, self.__lender_transactions) return iter(self.__lender_transactions)