From 01ec92b234022a0403eff41add6bf8727b3e6e61 Mon Sep 17 00:00:00 2001 From: Wim De Clercq Date: Tue, 9 Jun 2020 11:16:26 +0200 Subject: [PATCH 1/3] Add translations parameter to get_container_data. The translations can control the filenames in the returned zip. By default they will be object_keys, but a dict of {object_key: filename} can be passed to use different names. Closes-Issue: #21 --- .travis.yml | 9 ++------- requirements-dev-tci.txt | 9 --------- requirements-dev.txt | 30 ++++++++++++++++++++++-------- requirements-tci.txt | 2 -- requirements.txt | 4 ++-- storageprovider/client.py | 17 +++++++++++------ tests/test_client.py | 24 ++++++++++++++++++++---- 7 files changed, 57 insertions(+), 38 deletions(-) delete mode 100644 requirements-dev-tci.txt delete mode 100644 requirements-tci.txt diff --git a/.travis.yml b/.travis.yml index 74e2364..93aec61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,14 +2,9 @@ language: python sudo: false python: - "2.7" - - "3.3" - - "3.4" -notifications: - email: - - bart.saelen@gesolutions.be - - klaas.millet@rwo.vlaanderen.be + - "3.6" install: - - pip install -r requirements-dev-tci.txt + - pip install -r requirements-dev.txt - python setup.py develop script: py.test --cov storageprovider --cov-report term-missing tests diff --git a/requirements-dev-tci.txt b/requirements-dev-tci.txt deleted file mode 100644 index dcbb46d..0000000 --- a/requirements-dev-tci.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Runtime requirements ---requirement requirements-tci.txt - -# Testing -pytest==2.5.2 -pytest-cov==1.6 -py==1.4.20 -coveralls==0.4.4 -mock==1.0.1 \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt index 25019c4..bbcf3d2 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,12 +1,26 @@ # Runtime requirements --requirement requirements.txt +# pyramid +pyramid-debugtoolbar==4.6.1 + # Testing -pytest==2.5.2 -pytest-cov==1.6 -py==1.4.20 -coveralls==0.4.4 -mock==1.0.1 - -#Sphinx -sphinx==1.3.1 +pytest==5.4.3; python_version > '3.0' +pytest==4.6.11; python_version < '3.0' +pytest-cov==2.9.0 +mock==3.0.5; python_version < '3.0' +tempdir==0.7.1 +webtest==2.0.35 +coveralls==1.0 + +# Documentation +Sphinx==3.1.0; python_version > '3.0' +Sphinx==1.8.5; python_version < '3.0' +sphinxcontrib-httpdomain==1.7.0 +sphinx_rtd_theme==0.4.3 + +# waitress +waitress==1.4.4 + +# Linting +flake8==3.8.3 diff --git a/requirements-tci.txt b/requirements-tci.txt deleted file mode 100644 index 78a00c0..0000000 --- a/requirements-tci.txt +++ /dev/null @@ -1,2 +0,0 @@ -requests==2.3.0 -six==1.6.1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 78a00c0..2e0ea57 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -requests==2.3.0 -six==1.6.1 \ No newline at end of file +requests==2.23.0 +six==1.15.0 \ No newline at end of file diff --git a/storageprovider/client.py b/storageprovider/client.py index b62065a..2ea5f39 100644 --- a/storageprovider/client.py +++ b/storageprovider/client.py @@ -202,20 +202,25 @@ def list_object_keys_for_container(self, container_key, system_token=None): raise InvalidStateException(res.status_code, res.text) return res.content - def get_container_data(self, container_key, system_token=None): - ''' - list all object keys for a container in the data store + def get_container_data(self, container_key, system_token=None, translations=None): + """ + Retrieve a zip of a container in the data store. :param container_key: key of the container in the data store :param system_token: oauth system token + :param translations: Dict of object IDs and file names to use for them. :return list of object keys found in the container :raises InvalidStateException: if the response is in an invalid state - ''' + """ + translations = translations or {} headers = {'Accept': 'application/zip'} if system_token: headers.update({self.system_token_header: system_token}) - res = requests.get(self.base_url + '/containers/' + container_key, - headers=headers) + res = requests.get( + self.base_url + '/containers/' + container_key, + params=translations, + headers=headers + ) if res.status_code != 200: raise InvalidStateException(res.status_code, res.text) return res.content diff --git a/tests/test_client.py b/tests/test_client.py index ca9cb0f..1c604ef 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -264,9 +264,23 @@ def test_list_object_keys_for_container_KO(self, mock_requests): def test_get_container_data(self, mock_requests): mock_requests.get.return_value.status_code = 200 self.storageproviderclient.get_container_data(test_container_key) - mock_requests.get.assert_called_with(test_check_url + '/containers/' - + test_container_key, headers={ - 'Accept': 'application/zip'}) + mock_requests.get.assert_called_with( + test_check_url + '/containers/' + test_container_key, + headers={'Accept': 'application/zip'}, + params={} + ) + + @patch('storageprovider.client.requests') + def test_get_container_data_translations(self, mock_requests): + mock_requests.get.return_value.status_code = 200 + self.storageproviderclient.get_container_data( + test_container_key, translations={'001': 'filename.pdf'} + ) + mock_requests.get.assert_called_with( + test_check_url + '/containers/' + test_container_key, + headers={'Accept': 'application/zip'}, + params={'001': 'filename.pdf'} + ) @patch('storageprovider.client.requests') def test_get_container_system_token(self, mock_requests): @@ -275,7 +289,9 @@ def test_get_container_system_token(self, mock_requests): "x123-test") mock_requests.get.assert_called_with( test_check_url + '/containers/' + test_container_key, - headers={'Accept': 'application/zip', "OpenAmSSOID": "x123-test"}) + headers={'Accept': 'application/zip', "OpenAmSSOID": "x123-test"}, + params={} + ) @patch('storageprovider.client.requests') def test_get_container_KO(self, mock_requests): From 1d3c864db3baf0fa753896cd5f2243ce75bab7b1 Mon Sep 17 00:00:00 2001 From: Wouter Claeys Date: Wed, 10 Jun 2020 10:25:59 +0200 Subject: [PATCH 2/3] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 51ee0a4..f05849a 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ ] setup(name='storageprovider-client', - version='2.4.0', + version='2.5.0', description='storageprovider client', long_description=README + '\n\n' + CHANGES, classifiers=[ From 227e7493b80a3ea382e35a7e5ddba1eabf3e1066 Mon Sep 17 00:00:00 2001 From: Wouter Claeys Date: Wed, 10 Jun 2020 10:26:40 +0200 Subject: [PATCH 3/3] Update CHANGES.txt --- CHANGES.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index ddb963a..bd04a7b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,9 @@ + +2.5.0 (10/06/2020) +================== + +* Lijst met vertaling van id naar bestandsnaam meesturen download zip (#21) + 2.4.0 (21/01/2019) ==================