chiark / gitweb /
added test case for common.isApkDebuggable()
[fdroidserver.git] / tests / common.TestCase
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3
4 # http://www.drdobbs.com/testing/unit-testing-with-python/240165163
5
6 import inspect
7 import optparse
8 import os
9 import sys
10 import unittest
11
12 localmodule = os.path.realpath(os.path.join(
13         os.path.dirname(inspect.getfile(inspect.currentframe())),
14         '..'))
15 print('localmodule: ' + localmodule)
16 if localmodule not in sys.path:
17     sys.path.insert(0,localmodule)
18
19 import fdroidserver.common
20
21 class CommonTest(unittest.TestCase):
22     '''fdroidserver/common.py'''
23
24     def testIsApkDebuggable(self):
25         config = dict()
26         config['aapt'] = '/usr/bin/aapt'
27         # these are set debuggable
28         testfiles = []
29         testfiles.append(os.path.join(os.path.dirname(__file__), 'urzip.apk'))
30         testfiles.append(os.path.join(os.path.dirname(__file__), 'urzip-badsig.apk'))
31         testfiles.append(os.path.join(os.path.dirname(__file__), 'urzip-badcert.apk'))
32         for apkfile in testfiles:
33             debuggable = fdroidserver.common.isApkDebuggable(apkfile, config)
34             self.assertTrue(debuggable,
35                             "debuggable APK state was not properly parsed!")
36         # these are set NOT debuggable
37         testfiles = []
38         testfiles.append(os.path.join(os.path.dirname(__file__), 'urzip-release.apk'))
39         testfiles.append(os.path.join(os.path.dirname(__file__), 'urzip-release-unsigned.apk'))
40         for apkfile in testfiles:
41             debuggable = fdroidserver.common.isApkDebuggable(apkfile, config)
42             self.assertFalse(debuggable,
43                              "debuggable APK state was not properly parsed!")
44
45
46 if __name__ == "__main__":
47     parser = optparse.OptionParser()
48     parser.add_option("-v", "--verbose", action="store_true", default=False,
49                       help="Spew out even more information than normal")
50     (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
51
52     newSuite = unittest.TestSuite()
53     newSuite.addTest(unittest.makeSuite(CommonTest))
54     unittest.main()