avoid running into native-date object issue

Seem I ran into this issue: https://bugs.python.org/issue47228  This
change tries to fix it by using utcnow insteas of astimezone.
This commit is contained in:
Michael Pöhn 2022-09-30 11:13:59 +02:00
parent 7933623e93
commit 9560ed955c
2 changed files with 3 additions and 3 deletions

View File

@ -114,7 +114,7 @@ def get_embedded_classes(apkfile, depth=0):
def _datetime_now():
"""Get datetime.now(), using this funciton allows mocking it for testing."""
return datetime.now().astimezone()
return datetime.utcnow()
def _scanner_cachedir():

View File

@ -508,13 +508,13 @@ class Test_SignatureDataController(unittest.TestCase):
# check_last_updated
def test_check_last_updated_ok(self):
sdc = fdroidserver.scanner.SignatureDataController('nnn', 'fff.yml', 'https://example.com/test.json')
sdc.data['last_updated'] = datetime.now().astimezone().isoformat()
sdc.data['last_updated'] = datetime.utcnow().isoformat()
sdc.check_last_updated()
def test_check_last_updated_exception_cache_outdated(self):
sdc = fdroidserver.scanner.SignatureDataController('nnn', 'fff.yml', 'https://example.com/test.json')
sdc.cache_duration = timedelta(days=7)
sdc.data['last_updated'] = (datetime.now().astimezone() - timedelta(days=30)).isoformat()
sdc.data['last_updated'] = (datetime.utcnow() - timedelta(days=30)).isoformat()
with self.assertRaises(fdroidserver.scanner.SignatureDataOutdatedException):
sdc.check_last_updated()