From 8b5a61bb257fefeeadcc4d30141881294e656f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Sat, 30 Dec 2023 13:51:37 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9B=B0=EF=B8=8F=20=20make=20ipa=20related=20?= =?UTF-8?q?test=20cases=20more=20robust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MANIFEST.in | 1 + tests/update.TestCase | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 1aed9975..05a022b2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/tests/update.TestCase b/tests/update.TestCase index d8f278b6..f1c07fd9 100755 --- a/tests/update.TestCase +++ b/tests/update.TestCase @@ -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__":