You've already forked akaunting-py
Added Expense Transaction Test
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import requests
|
import requests
|
||||||
|
import json
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
from akauntingpy import exceptions
|
from akauntingpy import exceptions
|
||||||
from akauntingpy.helpers import *
|
from akauntingpy.helpers import *
|
||||||
@@ -40,7 +41,9 @@ class Client(object):
|
|||||||
params=MergeDict(self.default_params, params)
|
params=MergeDict(self.default_params, params)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(response)
|
||||||
response_ = response.json()
|
response_ = response.json()
|
||||||
|
print(response_)
|
||||||
|
|
||||||
if response.status_code == 401:
|
if response.status_code == 401:
|
||||||
raise exceptions.MissingPermission(response_['message'])
|
raise exceptions.MissingPermission(response_['message'])
|
||||||
|
|||||||
94
data/CreateTransactionExpenseSuccess.json
Normal file
94
data/CreateTransactionExpenseSuccess.json
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
{
|
||||||
|
"data":{
|
||||||
|
"id":10,
|
||||||
|
"company_id":1,
|
||||||
|
"type":"expense",
|
||||||
|
"account_id":"3",
|
||||||
|
"paid_at":"2022-05-16T11:57:51+12:00",
|
||||||
|
"amount":100,
|
||||||
|
"amount_formatted":"$100.00",
|
||||||
|
"currency_code":"NZD",
|
||||||
|
"currency_rate":1,
|
||||||
|
"document_id":"None",
|
||||||
|
"contact_id":"None",
|
||||||
|
"description":"Some expenditures",
|
||||||
|
"category_id":"4",
|
||||||
|
"payment_method":"Bank Transfer",
|
||||||
|
"reference":"None",
|
||||||
|
"attachment":false,
|
||||||
|
"created_by":1,
|
||||||
|
"created_at":"2022-05-16T11:57:51+12:00",
|
||||||
|
"updated_at":"2022-05-16T11:57:51+12:00",
|
||||||
|
"account":{
|
||||||
|
"data":{
|
||||||
|
"id":3,
|
||||||
|
"company_id":1,
|
||||||
|
"name":"Kiwibank Visa",
|
||||||
|
"number":"4446-89**-****-5385",
|
||||||
|
"currency_code":"NZD",
|
||||||
|
"opening_balance":-250,
|
||||||
|
"opening_balance_formatted":"-$250.00",
|
||||||
|
"current_balance":-350,
|
||||||
|
"current_balance_formatted":"-$350.00",
|
||||||
|
"bank_name":"None",
|
||||||
|
"bank_phone":"None",
|
||||||
|
"bank_address":"None",
|
||||||
|
"enabled":true,
|
||||||
|
"created_by":1,
|
||||||
|
"created_at":"2022-05-13T16:19:26+12:00",
|
||||||
|
"updated_at":"2022-05-13T16:19:26+12:00"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"category":{
|
||||||
|
"data":{
|
||||||
|
"id":4,
|
||||||
|
"company_id":1,
|
||||||
|
"name":"Other",
|
||||||
|
"type":"expense",
|
||||||
|
"color":"#e5e5e5",
|
||||||
|
"enabled":true,
|
||||||
|
"created_by":"None",
|
||||||
|
"created_at":"2022-05-13T03:14:40+12:00",
|
||||||
|
"updated_at":"2022-05-13T03:14:40+12:00"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"contact":{
|
||||||
|
"data":{
|
||||||
|
"id":"None",
|
||||||
|
"company_id":"None",
|
||||||
|
"user_id":"None",
|
||||||
|
"type":"None",
|
||||||
|
"name":"N/A",
|
||||||
|
"email":"None",
|
||||||
|
"tax_number":"None",
|
||||||
|
"phone":"None",
|
||||||
|
"address":"None",
|
||||||
|
"website":"None",
|
||||||
|
"currency_code":"None",
|
||||||
|
"enabled":"None",
|
||||||
|
"reference":"None",
|
||||||
|
"created_by":"None",
|
||||||
|
"created_at":"",
|
||||||
|
"updated_at":""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"currency":{
|
||||||
|
"data":{
|
||||||
|
"id":5,
|
||||||
|
"company_id":1,
|
||||||
|
"name":"NZ Dollar",
|
||||||
|
"code":"NZD",
|
||||||
|
"rate":1,
|
||||||
|
"enabled":true,
|
||||||
|
"precision":2,
|
||||||
|
"symbol":"$",
|
||||||
|
"symbol_first":1,
|
||||||
|
"decimal_mark":".",
|
||||||
|
"thousands_separator":",",
|
||||||
|
"created_by":1,
|
||||||
|
"created_at":"2022-05-13T03:21:17+12:00",
|
||||||
|
"updated_at":"2022-05-13T03:21:17+12:00"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,7 +55,7 @@ class TestAPI:
|
|||||||
json=RetrieveJSONFromFile("data/GetAccountsList.json"))
|
json=RetrieveJSONFromFile("data/GetAccountsList.json"))
|
||||||
data = c.get_accounts(params={'page': 1, 'limit': 200})
|
data = c.get_accounts(params={'page': 1, 'limit': 200})
|
||||||
|
|
||||||
def test_create_transaction_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
|
||||||
category_id=3, # Category ID to assign
|
category_id=3, # Category ID to assign
|
||||||
@@ -84,7 +84,7 @@ class TestAPI:
|
|||||||
description="Some description of the transaction"
|
description="Some description of the transaction"
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_create_transaction_failed(self, setUp, requests_mock,
|
def test_create_transaction_income_failed(self, setUp, requests_mock,
|
||||||
contact_id=None, # Contact ID/Client to assign
|
contact_id=None, # Contact ID/Client to assign
|
||||||
reference=None, # Reference for the payment
|
reference=None, # Reference for the payment
|
||||||
currency_code="NZD", # Currency code
|
currency_code="NZD", # Currency code
|
||||||
@@ -104,3 +104,19 @@ class TestAPI:
|
|||||||
description="Some description of the transaction"
|
description="Some description of the transaction"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_create_transaction_expense_success(self, setUp, requests_mock):
|
||||||
|
c = setUp
|
||||||
|
requests_mock.post(c.url + "/transactions",
|
||||||
|
json=RetrieveJSONFromFile("data/CreateTransactionExpenseSuccess.json"),
|
||||||
|
status_code=201)
|
||||||
|
data = c.create_transaction(type="expense",
|
||||||
|
amount=100.00,
|
||||||
|
account_id=3,
|
||||||
|
paid_at="2022-05-16",
|
||||||
|
currency_rate=1,
|
||||||
|
currency_code="NZD",
|
||||||
|
payment_method="Bank Transfer",
|
||||||
|
category_id="4",
|
||||||
|
description="Some expenditures"
|
||||||
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user