Skip to content

Commit d3abfcd

Browse files
committed
Added max download
1 parent 13f8c10 commit d3abfcd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/imio/esign/tests/test_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# -*- coding: utf-8 -*-
22
"""utils tests for this package."""
3+
from datetime import timedelta
34
from imio.esign.testing import IMIO_ESIGN_INTEGRATION_TESTING # noqa: E501
45
from imio.esign.utils import add_files_to_session
56
from imio.esign.utils import get_file_uid_url
7+
from imio.esign.utils import get_max_download_date
68
from imio.esign.utils import get_session_annotation
79
from imio.esign.utils import remove_context_from_session
810
from imio.esign.utils import remove_files_from_session
@@ -322,6 +324,12 @@ def test_get_file_uid_url(self):
322324
suid = result2[len("https://downloads.files.com/") :]
323325
self.assertEqual(shortuid_decode_id(suid, separator="-"), uid2) # correctly decoded
324326

327+
def test_get_max_download_date(self):
328+
annex = self.folders[0]
329+
mod_date = annex.modified().asdatetime().date()
330+
self.assertEqual(get_max_download_date(annex), mod_date + timedelta(days=120))
331+
self.assertEqual(get_max_download_date(annex, timedelta(days=0)), mod_date)
332+
325333

326334
# example of annotation content
327335
"""

src/imio/esign/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from datetime import datetime
3+
from datetime import timedelta
34
from imio.esign import _tr as _
45
from imio.esign import ESIGN_CREDENTIALS
56
from imio.esign import ESIGN_ROOT_URL
@@ -395,3 +396,14 @@ def get_file_uid_url(uid, separator="-", block_size=5, root_url=None):
395396
raise Exception("No root URL provided for file download url.")
396397
short_uid = shortuid_encode_id(uid, separator=separator, block_size=block_size)
397398
return "{}/{}".format(root_url.strip('/'), short_uid)
399+
400+
401+
def get_max_download_date(obj, delta=timedelta(days=120)):
402+
"""Get the maximum download date for e-sign files. Is takes the modification date and adds delta.
403+
404+
:param obj: content object
405+
:param delta: timedelta to add to modification date
406+
:return: maximum download date
407+
"""
408+
mod_date = obj.modified().asdatetime().date()
409+
return mod_date + delta

0 commit comments

Comments
 (0)