From ce2a1dc5abd3ddf8f48478d169b4ffa1f58d4e44 Mon Sep 17 00:00:00 2001 From: Petr Kalashnikov <pka065@it6100016.klientdrift.uib.no> Date: Thu, 11 Mar 2021 13:36:29 +0100 Subject: [PATCH] FSHO10: support filtering of batches in list from setra --- setra_client/client.py | 15 +++++++++++++-- tests/test_client.py | 9 +++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/setra_client/client.py b/setra_client/client.py index 9e9f030..5f2c427 100644 --- a/setra_client/client.py +++ b/setra_client/client.py @@ -181,16 +181,27 @@ class SetraClient(object): return data return cls.from_dict(data) - def get_batch(self, batch_id: int = None): + def get_batch(self, + batch_id: int = None, + min_created_date: str = None, + max_created_date: str = None, + batch_progress: str = None, + interface: str = None): """ GETs one or all batches from SETRA """ + params = None if batch_id is not None: batch_id = str(batch_id) + else: + params = {'min_created_date': min_created_date, + 'max_created_date': max_created_date, + 'batch_progress': batch_progress, + 'interface': interface} url = self.urls.batch(batch_id) - response = self.get(url) + response = self.get(url, params=params) return response.json() def get_voucher(self, vouch_id: int = None): diff --git a/tests/test_client.py b/tests/test_client.py index 74a66d6..4988351 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -190,6 +190,15 @@ def test_successful_get_all_batches(client, requests_mock, baseurl): assert response == {'foo': 'bar'} +def test_successful_get_batches_foltered_by_status(client, requests_mock, baseurl): + """A working GET call should return HTTP 200, with json content""" + url = SetraEndpoints(baseurl).batch() + requests_mock.get(url, json={'foo': 'bar'}, status_code=200) + + response = client.get_batch(batch_progress="ubw_import_ok") + assert response == {'foo': 'bar'} + + def test_successfully_getting_single_batch(client, requests_mock, baseurl): """A working GET call should return HTTP 200, with json content""" url = SetraEndpoints(baseurl).batch(batch_id='3') -- GitLab