Skip to content
Snippets Groups Projects
Commit 8e7249b9 authored by Petr Kalashnikov's avatar Petr Kalashnikov
Browse files

Support batch_complete endpoint from setra

parent a8314c10
No related branches found
No related tags found
1 merge request!7OM46, del 1: Support batch_complete endpoint from setra
Pipeline #55993 passed
......@@ -6,6 +6,7 @@
"transaction_url": "/transaction/",
"voucher_url": "/voucher/",
"multi_url": "/addtrans/",
"batch_complete_url": "/batch_complete/",
"headers": {
"X-Gravitee-Api-Key": "..."
},
......
......@@ -37,13 +37,15 @@ class SetraEndpoints:
batch_url='api/batch/',
transaction_url='api/transaction/',
voucher_url='api/voucher/',
new_batch_url='api/addtrans/'
new_batch_url='api/addtrans/',
batch_complete_url='api/batch_complete/'
):
self.baseurl = url
self.batch_url = batch_url
self.transaction_url = transaction_url
self.voucher_url = voucher_url
self.new_batch_url = new_batch_url
self.batch_complete_url = batch_complete_url
""" Get endpoints relative to the SETRA API URL. """
......@@ -86,6 +88,16 @@ class SetraEndpoints:
def post_new_batch(self):
return urllib.parse.urljoin(self.baseurl, self.new_batch_url)
def batch_complete(self, batch_id: str = None):
"""
URL for Batch endpoint
"""
if batch_id is None:
return urllib.parse.urljoin(self.baseurl, self.batch_complete_url)
else:
return urllib.parse.urljoin(self.baseurl,
'/'.join((self.batch_complete_url, batch_id)))
class SetraClient(object):
default_headers = {
......@@ -209,6 +221,18 @@ class SetraClient(object):
return_response=return_response)
return response
def get_batch_complete(self, batch_id: int = None):
"""
GETs one or all batches from SETRA
"""
if batch_id is not None:
batch_id = str(batch_id)
url = self.urls.batch_complete(batch_id)
response = self.get(url)
return response.json()
def get_client(config_dict):
"""
......
......@@ -35,7 +35,7 @@ class BaseModel(pydantic.BaseModel):
class Transaction(BaseModel):
account: str
amount: float
transdate: Optional[datetime.date]
transdate: Optional[datetime.datetime]
curamount: Optional[float]
currency: Optional[str]
description: str
......@@ -53,7 +53,7 @@ class Transaction(BaseModel):
class Voucher(BaseModel):
voucherdate: Optional[datetime.date]
voucherdate: Optional[datetime.datetime]
exref: Optional[str]
voucherno: int
transactions: typing.List[Transaction]
......
......@@ -33,7 +33,8 @@ def custom_endpoints(baseurl):
'/custom/batch/',
'/custom/transaction/',
'/custom/voucher/',
'/custom/addtrans/'
'/custom/addtrans/',
'/custom/batch_complete/'
)
......@@ -80,3 +81,8 @@ def batch_with_voucher_fixture():
@pytest.fixture
def batch_fail_fixture():
return load_json_file('batch_fail_fixture.json')
@pytest.fixture
def batch_complete_fixture():
return load_json_file('batch_complete_fixture.json')
{
"created": "2020-01-01T00:00:00Z",
"batchid": "252",
"period": 201902,
"interface": "HB",
"client": "72",
"vouchertype": "3",
"batch_validated_ok_date": null,
"batch_rejected_code": "",
"sent_date": null,
"http_response_content": "",
"http_response_code": null,
"orderno": null,
"polling_statuscode": "1",
"polling_statuscode_date": null,
"getresult_date": null,
"getresult_statuscode": "1",
"getresult_logg": "",
"getresult_report": "",
"vouchers": [
{
"id": 252,
"batch_id": 252,
"created": "2020-01-01T00:00:00Z",
"voucherdate": "2020-01-01T00:00:00Z",
"exref": "",
"voucherno": 252,
"voucherno_ubw": null,
"voucherno_ubw_wflow": null,
"vouchertype": "HB",
"transactions": [
{
"id": 3,
"voucher_id": 252,
"created": "2020-01-01T00:00:00Z",
"account": "72",
"amount": 50.0,
"transdate": "2020-01-01T00:00:00Z",
"curamount": 50.0,
"currency": "NOK",
"description": "50 NOK into 72",
"dim1": "",
"dim2": "",
"dim3": "",
"dim4": "",
"dim5": "",
"dim6": "",
"dim7": "",
"sequenceno": 1,
"taxcode": "MVA",
"transtype": "GL",
"extinvref": ""
},
{
"id": 4,
"voucher_id": 252,
"created": "2020-01-01T00:00:00Z",
"account": "72",
"amount": 50.0,
"transdate": "2020-01-01T00:00:00Z",
"curamount": 50.0,
"currency": "NOK",
"description": "50 NOK into 72",
"dim1": "",
"dim2": "",
"dim3": "",
"dim4": "",
"dim5": "",
"dim6": "",
"dim7": "",
"sequenceno": 1,
"taxcode": "MVA",
"transtype": "GL",
"extinvref": ""
}
]
}
]
}
\ No newline at end of file
......@@ -35,3 +35,8 @@ def test_init_transaction_without_value(baseurl):
endpoints = SetraEndpoints(baseurl)
assert endpoints.transaction() == baseurl + "/api/transaction/"
def test_init_batch_complete_without_value(baseurl):
endpoints = SetraEndpoints(baseurl)
assert endpoints.batch_complete() == baseurl + "/api/batch_complete/"
......@@ -8,6 +8,10 @@ def test_batch(batch_fixture):
assert Batch(**batch_fixture)
def test_batch_complete(batch_complete_fixture):
assert Batch(**batch_complete_fixture)
def test_voucher(voucher_fixture):
assert Voucher(**voucher_fixture)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment