⛰️ make ipa related test cases more robust

This commit is contained in:
Michael Pöhn 2023-12-30 13:51:37 +01:00 committed by Hans-Christoph Steiner
parent 881943a0db
commit 8b5a61bb25
2 changed files with 12 additions and 14 deletions

View File

@ -543,6 +543,7 @@ include tests/build-tools/28.0.3/aapt-output-souch.smsbypass_9.txt
include tests/build-tools/generate.sh
include tests/check-fdroid-apk
include tests/checkupdates.TestCase
include tests/com.fake.IpaApp_1000000000001.ipa
include tests/common.TestCase
include tests/config.py
include tests/config/antiFeatures.yml

View File

@ -1923,7 +1923,8 @@ class UpdateTest(unittest.TestCase):
)
def test_parse_ipa(self):
result = fdroidserver.update.parse_ipa('./com.fake.IpaApp_1000000000001.ipa', 'fake_size', 'fake_sha')
ipa_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'com.fake.IpaApp_1000000000001.ipa')
result = fdroidserver.update.parse_ipa(ipa_path, 'fake_size', 'fake_sha')
self.maxDiff = None
self.assertDictEqual(result, {
'apkName': 'com.fake.IpaApp_1000000000001.ipa',
@ -1978,6 +1979,7 @@ class TestScanRepoForIpas(unittest.TestCase):
knownapks = mock.MagicMock()
def mocked_parse(p, s, c):
# pylint: disable=unused-argument
return {
'packageName': 'abc' if 'abc' in p else 'xyz'
}
@ -1987,23 +1989,18 @@ class TestScanRepoForIpas(unittest.TestCase):
self.assertEqual(checkchanged, True)
self.assertEqual(len(ipas), 2)
self.assertEqual(ipas[0]['packageName'], 'xyz')
self.assertEqual(ipas[1]['packageName'], 'abc')
package_names_in_ipas = [x['packageName'] for x in ipas]
self.assertTrue('abc' in package_names_in_ipas)
self.assertTrue('xyz' in package_names_in_ipas)
self.assertEqual(apkcache.__setitem__.mock_calls[0].args[1]['packageName'], 'xyz')
self.assertEqual(apkcache.__setitem__.mock_calls[1].args[1]['packageName'], 'abc')
apkcache_setter_package_name = [x.args[1]['packageName'] for x in apkcache.__setitem__.mock_calls]
self.assertTrue('abc' in apkcache_setter_package_name)
self.assertTrue('xyz' in apkcache_setter_package_name)
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'),
)
self.assertTrue(unittest.mock.call('abc.Def_123.ipa', 'abc') in knownapks.recordapk.mock_calls)
self.assertTrue(unittest.mock.call('xyz.XXX_123.ipa', 'xyz') in knownapks.recordapk.mock_calls)
if __name__ == "__main__":