From cb0774cc43977b32d1de44b84a42ec32790fd9a3 Mon Sep 17 00:00:00 2001 From: Petr Kalashnikov <pka065@it6100016.klientdrift.uib.no> Date: Mon, 29 Mar 2021 15:14:37 +0200 Subject: [PATCH] =?UTF-8?q?FSHO12,=20del=201:=20mulighet=20=C3=A5=20return?= =?UTF-8?q?ere=20en=20liste=20av=20batcher=20uten=20vouchere?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setra_client/client.py | 10 +++++++--- setra_client/models.py | 4 ++-- tests/conftest.py | 5 +++++ tests/fixtures/batch_without_voucher_field.json | 7 +++++++ tests/test_models.py | 4 ++++ 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 tests/fixtures/batch_without_voucher_field.json diff --git a/setra_client/client.py b/setra_client/client.py index 02b3788..f63c913 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 71043f2..6134182 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 749c2d1..44c4e39 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 0000000..ade4913 --- /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 a663bc4..deb7d7c 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) -- GitLab