From 5032207da0adbb5fac16cba89f502884ce059bae Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 30 Oct 2024 14:00:06 +0100 Subject: [PATCH] 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. --- tests/common.TestCase | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/common.TestCase b/tests/common.TestCase index 385033cf..e4a144ac 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -22,6 +22,7 @@ import textwrap import yaml import gzip from argparse import ArgumentParser +from datetime import datetime, timezone from zipfile import BadZipFile, ZipFile from unittest import mock from pathlib import Path @@ -2935,6 +2936,37 @@ class CommonTest(unittest.TestCase): [{'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 = ( (