diff --git a/example-config.json b/example-config.json index f9ce49691a1ec4788794cbfcfc0c44000ab14451..6ea81f6f7b866e382e9cf962b58642770f48bf06 100644 --- a/example-config.json +++ b/example-config.json @@ -6,6 +6,7 @@ "transaction_url": "/transaction/", "voucher_url": "/voucher/", "multi_url": "/addtrans/", + "batch_complete_url": "/batch_complete/", "headers": { "X-Gravitee-Api-Key": "..." }, diff --git a/setra_client/client.py b/setra_client/client.py index 2d4c915fe0357043373b7f684682547ff2b5e920..f9f984ccae0bf52aa368e1c30484d3d2dda8e22a 100644 --- a/setra_client/client.py +++ b/setra_client/client.py @@ -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): """ diff --git a/setra_client/models.py b/setra_client/models.py index a121b2c9d54998287315c9b33df3ec7ce1ac3114..c710bafc0a0399df3f8325f7aabda17bd9a1de76 100644 --- a/setra_client/models.py +++ b/setra_client/models.py @@ -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] diff --git a/tests/conftest.py b/tests/conftest.py index 8a225c0bf802019aaefe5ffabc03a4385766dd79..6added869f0f3e68b0254f3dfac204914d912c23 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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') diff --git a/tests/fixtures/batch_complete_fixture.json b/tests/fixtures/batch_complete_fixture.json new file mode 100644 index 0000000000000000000000000000000000000000..e49a6f7c75fdea2b6f68db92aeb2e65032949d12 --- /dev/null +++ b/tests/fixtures/batch_complete_fixture.json @@ -0,0 +1,79 @@ +{ + "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 diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index 349cee77545364804b066b2bfa95156f77ab1965..8923c22e539852da62ae6037704974038f564a65 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -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/" + diff --git a/tests/test_models.py b/tests/test_models.py index aa0e46ec04e0b10d09e453a2e25f0f1a560e51ba..8f9997c902894237d967c2c8e2b1c5c93e9581e3 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -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)