From 2274def0e84e9be92cc403c1c6e4875f4118bacc Mon Sep 17 00:00:00 2001 From: Sergey Motornyuk Date: Fri, 3 Sep 2021 11:37:22 +0300 Subject: [PATCH] Update last_modified --- ckanext/cloudstorage/storage.py | 2 ++ ckanext/cloudstorage/tests/test_utils.py | 8 +++----- dev-requirements.txt | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 dev-requirements.txt diff --git a/ckanext/cloudstorage/storage.py b/ckanext/cloudstorage/storage.py index d8695e6..da4ebbd 100644 --- a/ckanext/cloudstorage/storage.py +++ b/ckanext/cloudstorage/storage.py @@ -218,12 +218,14 @@ def __init__(self, resource): self.file_upload = _get_underlying_file(upload_field_storage) resource['url'] = self.filename resource['url_type'] = 'upload' + resource['last_modified'] = datetime.utcnow() elif multipart_name and self.can_use_advanced_aws: # This means that file was successfully uploaded and stored # at cloud. # Currently implemented just AWS version resource['url'] = munge.munge_filename(multipart_name) resource['url_type'] = 'upload' + resource['last_modified'] = datetime.utcnow() elif self._clear and resource.get('id'): # Apparently, this is a created-but-not-commited resource whose # file upload has been canceled. We're copying the behaviour of diff --git a/ckanext/cloudstorage/tests/test_utils.py b/ckanext/cloudstorage/tests/test_utils.py index c6fd155..b990b5d 100644 --- a/ckanext/cloudstorage/tests/test_utils.py +++ b/ckanext/cloudstorage/tests/test_utils.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import pytest -import mock import ckan.plugins.toolkit as tk @@ -11,12 +10,11 @@ @pytest.mark.ckan_config('ckan.plugins', 'cloudstorage') @pytest.mark.usefixtures('with_driver_options', 'with_plugins') class TestResourceDownload(object): - def test_utils_used_by_download_route(self, app, monkeypatch): + def test_utils_used_by_download_route(self, app, mocker): url = tk.url_for('resource.download', id='a', resource_id='b') - func = mock.Mock(return_value='') - monkeypatch.setattr(utils, 'resource_download', func) + mocker.patch('ckanext.cloudstorage.utils.resource_download') app.get(url) - func.assert_called_once_with('a', 'b', None) + utils.resource_doewnload.assert_called_once_with('a', 'b', None) @pytest.mark.usefixtures('clean_db') def test_status_codes(self, app): diff --git a/dev-requirements.txt b/dev-requirements.txt new file mode 100644 index 0000000..4ba02b4 --- /dev/null +++ b/dev-requirements.txt @@ -0,0 +1 @@ +pytest-mock==3.6.1