1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-15 03:20:10 +01:00

add basic tests of KnownApks mechanism

The tests in tests/run-tests do provide coverage for these cases, but it is
not explicit, but just comes from testing that the index file has not
changed.  These tests make it explicit what is being tested.
This commit is contained in:
Hans-Christoph Steiner 2024-10-30 14:00:06 +01:00
parent 81c0c9d4aa
commit 5032207da0

View File

@ -22,6 +22,7 @@ import textwrap
import yaml import yaml
import gzip import gzip
from argparse import ArgumentParser from argparse import ArgumentParser
from datetime import datetime, timezone
from zipfile import BadZipFile, ZipFile from zipfile import BadZipFile, ZipFile
from unittest import mock from unittest import mock
from pathlib import Path from pathlib import Path
@ -2935,6 +2936,37 @@ class CommonTest(unittest.TestCase):
[{'url': s}], fdroidserver.common.parse_mirrors_config(mirrors) [{'url': s}], fdroidserver.common.parse_mirrors_config(mirrors)
) )
def test_KnownApks_recordapk(self):
"""Test that added dates are being fetched from the index.
There are more related tests in tests/run-tests.
"""
now = datetime.now(timezone.utc)
knownapks = fdroidserver.common.KnownApks()
for apkName in knownapks.apks:
knownapks.recordapk(apkName, 'ignored', default_date=now)
for appid, added in knownapks.apks.values():
self.assertNotEqual(added, now)
def test_KnownApks_recordapk_new(self):
"""Test that new added dates work, and are not replaced later.
There are more related tests in tests/run-tests.
"""
now = datetime.now(timezone.utc)
knownapks = fdroidserver.common.KnownApks()
fake_apk = 'fake.apk'
knownapks.recordapk(fake_apk, 'ignored', default_date=now)
for apk, (appid, added) in knownapks.apks.items():
if apk == fake_apk:
self.assertEqual(added, now)
else:
self.assertNotEqual(added, now)
knownapks.recordapk(fake_apk, 'ignored', default_date=datetime.now(timezone.utc))
self.assertEqual(knownapks.apks[fake_apk][1], now)
APKS_WITH_JAR_SIGNATURES = ( APKS_WITH_JAR_SIGNATURES = (
( (