You've already forked akaunting-py
Added exception for AccountNotFound
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from importlib.metadata import version, PackageNotFoundError
|
from importlib.metadata import version, PackageNotFoundError
|
||||||
|
from unittest.mock import seal
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
@@ -75,6 +76,14 @@ class Client(object):
|
|||||||
def get_accounts(self, **params):
|
def get_accounts(self, **params):
|
||||||
data = self.call(endpoint="accounts", **params)
|
data = self.call(endpoint="accounts", **params)
|
||||||
|
|
||||||
|
if params.get('search', False):
|
||||||
|
# Check if there is an account returned
|
||||||
|
if data['meta']['pagination'].get('count') == 0:
|
||||||
|
# No account found
|
||||||
|
raise exceptions.AccountNotFound("Sorry, account not found matching search parameters: %s".format(
|
||||||
|
params.get('search')
|
||||||
|
))
|
||||||
|
|
||||||
return data['data']
|
return data['data']
|
||||||
|
|
||||||
def create_transaction(self,
|
def create_transaction(self,
|
||||||
|
|||||||
@@ -18,3 +18,11 @@ class InvalidData(Error):
|
|||||||
Args:
|
Args:
|
||||||
Error (_type_): _description_
|
Error (_type_): _description_
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class AccountNotFound(Error):
|
||||||
|
"""
|
||||||
|
Account not found
|
||||||
|
|
||||||
|
Args:
|
||||||
|
Error (_type_): _description_
|
||||||
|
"""
|
||||||
15
data/GetAccountsSearchNotFound.json
Normal file
15
data/GetAccountsSearchNotFound.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"data":[],
|
||||||
|
"meta":{
|
||||||
|
"pagination":{
|
||||||
|
"total":0,
|
||||||
|
"count":0,
|
||||||
|
"per_page":25,
|
||||||
|
"current_page":0,
|
||||||
|
"total_pages":0,
|
||||||
|
"links":{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,6 +61,13 @@ class TestAPI:
|
|||||||
json=RetrieveJSONFromFile("data/GetAccountsSearch.json"))
|
json=RetrieveJSONFromFile("data/GetAccountsSearch.json"))
|
||||||
data = c.get_accounts(search="number:38-9011-0510023-03",params={'page': 1, 'limit': 200})
|
data = c.get_accounts(search="number:38-9011-0510023-03",params={'page': 1, 'limit': 200})
|
||||||
|
|
||||||
|
def test_get_account_search_not_found(self, setUp, requests_mock):
|
||||||
|
c = setUp
|
||||||
|
requests_mock.get(c.url + "/accounts?search=number%3Aarandomvalue&company_id=1",
|
||||||
|
json=RetrieveJSONFromFile("data/GetAccountsSearchNotFound.json"))
|
||||||
|
with pytest.raises(AccountNotFound):
|
||||||
|
data = c.get_accounts(search="number:arandomvalue")
|
||||||
|
|
||||||
def test_create_transaction_income_success(self, setUp, requests_mock,
|
def test_create_transaction_income_success(self, setUp, requests_mock,
|
||||||
type='income', # Payment method type
|
type='income', # Payment method type
|
||||||
account_id=2, # Account ID to assign
|
account_id=2, # Account ID to assign
|
||||||
|
|||||||
Reference in New Issue
Block a user