mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-14 15:02:51 +03:00
🍲 add unit test for update.scan_repo_for_ipas
This commit is contained in:
parent
995118bcd2
commit
7211e9f9b4
2 changed files with 54 additions and 5 deletions
|
@ -49,10 +49,10 @@ from binascii import hexlify
|
||||||
|
|
||||||
from . import _
|
from . import _
|
||||||
from . import common
|
from . import common
|
||||||
from . import index
|
|
||||||
from . import metadata
|
from . import metadata
|
||||||
from .common import DEFAULT_LOCALE
|
from .common import DEFAULT_LOCALE
|
||||||
from .exception import BuildException, FDroidException, VerificationException
|
from .exception import BuildException, FDroidException, VerificationException
|
||||||
|
import fdroidserver.index
|
||||||
|
|
||||||
from PIL import Image, PngImagePlugin
|
from PIL import Image, PngImagePlugin
|
||||||
|
|
||||||
|
@ -599,7 +599,7 @@ def scan_repo_for_ipas(apkcache, repodir, knownapks):
|
||||||
ipa = apkcache.get(ipa_name, {})
|
ipa = apkcache.get(ipa_name, {})
|
||||||
|
|
||||||
if ipa.get('hash') != sha256:
|
if ipa.get('hash') != sha256:
|
||||||
ipa = parse_ipa(ipa_path, file_size, sha256)
|
ipa = fdroidserver.update.parse_ipa(ipa_path, file_size, sha256)
|
||||||
apkcache[ipa_name] = ipa
|
apkcache[ipa_name] = ipa
|
||||||
cachechanged = True
|
cachechanged = True
|
||||||
|
|
||||||
|
@ -2433,7 +2433,7 @@ def main():
|
||||||
if len(repodirs) > 1:
|
if len(repodirs) > 1:
|
||||||
archive_old_apks(apps, apks, archapks, repodirs[0], repodirs[1], config['archive_older'])
|
archive_old_apks(apps, apks, archapks, repodirs[0], repodirs[1], config['archive_older'])
|
||||||
archived_apps = prepare_apps(apps, archapks, repodirs[1])
|
archived_apps = prepare_apps(apps, archapks, repodirs[1])
|
||||||
index.make(archived_apps, archapks, repodirs[1], True)
|
fdroidserver.index.make(archived_apps, archapks, repodirs[1], True)
|
||||||
|
|
||||||
repoapps = prepare_apps(apps, apks, repodirs[0])
|
repoapps = prepare_apps(apps, apks, repodirs[0])
|
||||||
|
|
||||||
|
@ -2446,13 +2446,13 @@ def main():
|
||||||
app_dict = dict()
|
app_dict = dict()
|
||||||
app_dict[appid] = app
|
app_dict[appid] = app
|
||||||
if os.path.isdir(repodir):
|
if os.path.isdir(repodir):
|
||||||
index.make(app_dict, apks, repodir, False)
|
fdroidserver.index.make(app_dict, apks, repodir, False)
|
||||||
else:
|
else:
|
||||||
logging.info(_('Skipping index generation for {appid}').format(appid=appid))
|
logging.info(_('Skipping index generation for {appid}').format(appid=appid))
|
||||||
return
|
return
|
||||||
|
|
||||||
# Make the index for the main repo...
|
# Make the index for the main repo...
|
||||||
index.make(repoapps, apks, repodirs[0], False)
|
fdroidserver.index.make(repoapps, apks, repodirs[0], False)
|
||||||
|
|
||||||
git_remote = config.get('binary_transparency_remote')
|
git_remote = config.get('binary_transparency_remote')
|
||||||
if git_remote or os.path.isdir(os.path.join('binary_transparency', '.git')):
|
if git_remote or os.path.isdir(os.path.join('binary_transparency', '.git')):
|
||||||
|
|
|
@ -1958,6 +1958,54 @@ class TestUpdateVersionStringToInt(unittest.TestCase):
|
||||||
fdroidserver.update.version_string_to_int("0.0.0x3")
|
fdroidserver.update.version_string_to_int("0.0.0x3")
|
||||||
|
|
||||||
|
|
||||||
|
class TestScanRepoForIpas(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.maxDiff = None
|
||||||
|
|
||||||
|
def test_scan_repo_for_ipas_no_cache(self):
|
||||||
|
self.maxDiff = None
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
|
||||||
|
os.mkdir("repo")
|
||||||
|
with open('repo/abc.Def_123.ipa', 'w') as f:
|
||||||
|
f.write('abc')
|
||||||
|
with open('repo/xyz.XXX_123.ipa', 'w') as f:
|
||||||
|
f.write('xyz')
|
||||||
|
|
||||||
|
apkcache = mock.MagicMock()
|
||||||
|
# apkcache['a'] = 1
|
||||||
|
repodir = "repo"
|
||||||
|
knownapks = mock.MagicMock()
|
||||||
|
|
||||||
|
def mocked_parse(p, s, c):
|
||||||
|
return {
|
||||||
|
'packageName': 'abc' if 'abc' in p else 'xyz'
|
||||||
|
}
|
||||||
|
|
||||||
|
with mock.patch('fdroidserver.update.parse_ipa', mocked_parse):
|
||||||
|
ipas, checkchanged = fdroidserver.update.scan_repo_for_ipas(apkcache, repodir, knownapks)
|
||||||
|
|
||||||
|
self.assertEqual(checkchanged, True)
|
||||||
|
self.assertEqual(len(ipas), 2)
|
||||||
|
self.assertEqual(ipas[0]['packageName'], 'xyz')
|
||||||
|
self.assertEqual(ipas[1]['packageName'], 'abc')
|
||||||
|
|
||||||
|
self.assertEqual(apkcache.__setitem__.mock_calls[0].args[1]['packageName'], 'xyz')
|
||||||
|
self.assertEqual(apkcache.__setitem__.mock_calls[1].args[1]['packageName'], 'abc')
|
||||||
|
self.assertEqual(apkcache.__setitem__.call_count, 2)
|
||||||
|
|
||||||
|
knownapks.recordapk.call_count = 2
|
||||||
|
self.assertEqual(
|
||||||
|
knownapks.recordapk.mock_calls[0],
|
||||||
|
unittest.mock.call('xyz.XXX_123.ipa', 'xyz'),
|
||||||
|
)
|
||||||
|
# skipping one call here, because accessing `if added:` shows up in mock_calls
|
||||||
|
self.assertEqual(
|
||||||
|
knownapks.recordapk.mock_calls[2],
|
||||||
|
unittest.mock.call('abc.Def_123.ipa', 'abc'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
os.chdir(os.path.dirname(__file__))
|
os.chdir(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
@ -1974,4 +2022,5 @@ if __name__ == "__main__":
|
||||||
newSuite = unittest.TestSuite()
|
newSuite = unittest.TestSuite()
|
||||||
newSuite.addTest(unittest.makeSuite(UpdateTest))
|
newSuite.addTest(unittest.makeSuite(UpdateTest))
|
||||||
newSuite.addTest(unittest.makeSuite(TestUpdateVersionStringToInt))
|
newSuite.addTest(unittest.makeSuite(TestUpdateVersionStringToInt))
|
||||||
|
newSuite.addTest(unittest.makeSuite(TestScanRepoForIpas))
|
||||||
unittest.main(failfast=False)
|
unittest.main(failfast=False)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue