diff --git a/setra_client/client.py b/setra_client/client.py index 02b37881f41e2ab3eb0acece7eb168a35c31c9a5..f63c9138e1fc6d144671b06cca76a66193078485 100644 --- a/setra_client/client.py +++ b/setra_client/client.py @@ -190,7 +190,8 @@ class SetraClient(object): min_created_date: Optional[date] = None, max_created_date: Optional[date] = None, batch_progress: Optional[BatchProgressEnum] = None, - interface: Optional[str] = None): + interface: Optional[str] = None, + return_list_of_obj: Optional[bool] = False): """ GETs one or all batches from SETRA. @@ -210,9 +211,12 @@ class SetraClient(object): 'interface': interface} url = self.urls.batch(batch_id) - response = self.get(url, params=params) - return response.json() + data = response.json() + if return_list_of_obj: + return [Batch(**item) for item in data] + else: + return data def get_voucher(self, vouch_id: int = None): """ diff --git a/setra_client/models.py b/setra_client/models.py index 71043f20f9844e3842cdc5e2166049674b431bdf..61341822a946ccc95420377241d14b0273c72898 100644 --- a/setra_client/models.py +++ b/setra_client/models.py @@ -2,7 +2,7 @@ import datetime import json import typing -from typing import Optional, TypeVar +from typing import Optional, TypeVar, List from enum import Enum import pydantic @@ -84,7 +84,7 @@ class Batch(BaseModel): period: typing.Optional[str] interface: str vouchertype: typing.Optional[str] - vouchers: typing.List[Voucher] + vouchers: typing.Optional[typing.List[Voucher]] class ErrorTransaction(BaseModel): diff --git a/tests/conftest.py b/tests/conftest.py index 749c2d158a15eca84aad994b6a949d837b1567b2..44c4e39b55005a192d85dd8de0ecbbcab03c121c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -82,6 +82,11 @@ def batch_with_voucher_fixture(): return load_json_file('batch_with_voucher_fixture.json') +@pytest.fixture +def batch_without_voucher_field(): + return load_json_file('batch_without_voucher_field.json') + + @pytest.fixture def batch_fail_fixture(): return load_json_file('batch_fail_fixture.json') diff --git a/tests/fixtures/batch_without_voucher_field.json b/tests/fixtures/batch_without_voucher_field.json new file mode 100644 index 0000000000000000000000000000000000000000..ade4913149f57964f426e35e4ff336133b7a9d73 --- /dev/null +++ b/tests/fixtures/batch_without_voucher_field.json @@ -0,0 +1,7 @@ +{ + "client": 10, + "batchid": 20, + "period": 30, + "interface": 40, + "vouchertype": 50 +} diff --git a/tests/test_models.py b/tests/test_models.py index a663bc4bf6e13914fd4ce8d530fc51d13f92ca80..deb7d7cf88fc3617a8baf5dd88f2ce16f7b85011 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -17,6 +17,10 @@ def test_batch(batch_fixture): assert Batch(**batch_fixture) +def test_batch(batch_without_voucher_field): + assert Batch(**batch_without_voucher_field) + + def test_voucher(voucher_fixture): assert Voucher(**voucher_fixture)