chiark / gitweb /
added test case for common.isApkDebuggable()
authorHans-Christoph Steiner <hans@eds.org>
Mon, 8 Dec 2014 21:55:14 +0000 (22:55 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Sun, 14 Dec 2014 12:25:20 +0000 (13:25 +0100)
Just getting into the habit of adding tests to everything that I change...
Also, it should be useful to have an unsigned APK in the test collection,
since `fdroid update` should handle it gracefully and give a warning of
some kind.

tests/common.TestCase [new file with mode: 0755]
tests/run-tests
tests/urzip-release-unsigned.apk [new file with mode: 0644]
tests/urzip-release.apk [new file with mode: 0644]

diff --git a/tests/common.TestCase b/tests/common.TestCase
new file mode 100755 (executable)
index 0000000..d4bbd61
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# http://www.drdobbs.com/testing/unit-testing-with-python/240165163
+
+import inspect
+import optparse
+import os
+import sys
+import unittest
+
+localmodule = os.path.realpath(os.path.join(
+        os.path.dirname(inspect.getfile(inspect.currentframe())),
+        '..'))
+print('localmodule: ' + localmodule)
+if localmodule not in sys.path:
+    sys.path.insert(0,localmodule)
+
+import fdroidserver.common
+
+class CommonTest(unittest.TestCase):
+    '''fdroidserver/common.py'''
+
+    def testIsApkDebuggable(self):
+        config = dict()
+        config['aapt'] = '/usr/bin/aapt'
+        # these are set debuggable
+        testfiles = []
+        testfiles.append(os.path.join(os.path.dirname(__file__), 'urzip.apk'))
+        testfiles.append(os.path.join(os.path.dirname(__file__), 'urzip-badsig.apk'))
+        testfiles.append(os.path.join(os.path.dirname(__file__), 'urzip-badcert.apk'))
+        for apkfile in testfiles:
+            debuggable = fdroidserver.common.isApkDebuggable(apkfile, config)
+            self.assertTrue(debuggable,
+                            "debuggable APK state was not properly parsed!")
+        # these are set NOT debuggable
+        testfiles = []
+        testfiles.append(os.path.join(os.path.dirname(__file__), 'urzip-release.apk'))
+        testfiles.append(os.path.join(os.path.dirname(__file__), 'urzip-release-unsigned.apk'))
+        for apkfile in testfiles:
+            debuggable = fdroidserver.common.isApkDebuggable(apkfile, config)
+            self.assertFalse(debuggable,
+                             "debuggable APK state was not properly parsed!")
+
+
+if __name__ == "__main__":
+    parser = optparse.OptionParser()
+    parser.add_option("-v", "--verbose", action="store_true", default=False,
+                      help="Spew out even more information than normal")
+    (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
+
+    newSuite = unittest.TestSuite()
+    newSuite.addTest(unittest.makeSuite(CommonTest))
+    unittest.main()
index ae566b74ef53646fd9b5b23f6d4665f652acb345..486bb3ea605fad6fbff4c3280ac38ef8d871e313 100755 (executable)
@@ -98,6 +98,7 @@ echo_header "test python getsig replacement"
 cd $WORKSPACE/tests/getsig
 ./make.sh
 cd $WORKSPACE/tests
+./common.TestCase
 ./update.TestCase
 
 
diff --git a/tests/urzip-release-unsigned.apk b/tests/urzip-release-unsigned.apk
new file mode 100644 (file)
index 0000000..7bc2229
Binary files /dev/null and b/tests/urzip-release-unsigned.apk differ
diff --git a/tests/urzip-release.apk b/tests/urzip-release.apk
new file mode 100644 (file)
index 0000000..28a0345
Binary files /dev/null and b/tests/urzip-release.apk differ