2014-08-19 23:20:32 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
import mozfile
|
|
|
|
import unittest
|
|
|
|
import zipfile
|
2016-11-18 00:36:18 +03:00
|
|
|
|
|
|
|
import mozunit
|
|
|
|
|
2014-08-19 23:20:32 +04:00
|
|
|
from mozversion import get_version
|
|
|
|
|
|
|
|
|
|
|
|
class ApkTest(unittest.TestCase):
|
|
|
|
"""test getting version information from an android .apk"""
|
|
|
|
|
2016-09-30 17:08:37 +03:00
|
|
|
application_changeset = 'a' * 40
|
|
|
|
platform_changeset = 'b' * 40
|
2014-08-19 23:20:32 +04:00
|
|
|
|
2015-02-12 06:36:00 +03:00
|
|
|
def create_apk_zipfiles(self, zfile):
|
|
|
|
zfile.writestr('application.ini',
|
|
|
|
"""[App]\nSourceStamp=%s\n""" % self.application_changeset)
|
|
|
|
zfile.writestr('platform.ini',
|
|
|
|
"""[Build]\nSourceStamp=%s\n""" % self.platform_changeset)
|
|
|
|
zfile.writestr('AndroidManifest.xml', '')
|
|
|
|
|
2014-08-19 23:20:32 +04:00
|
|
|
def test_basic(self):
|
|
|
|
with mozfile.NamedTemporaryFile() as f:
|
|
|
|
with zipfile.ZipFile(f.name, 'w') as z:
|
2015-02-12 06:36:00 +03:00
|
|
|
self.create_apk_zipfiles(z)
|
2014-08-19 23:20:32 +04:00
|
|
|
v = get_version(f.name)
|
|
|
|
self.assertEqual(v.get('application_changeset'), self.application_changeset)
|
|
|
|
self.assertEqual(v.get('platform_changeset'), self.platform_changeset)
|
|
|
|
|
2015-02-12 06:36:00 +03:00
|
|
|
def test_with_package_name(self):
|
|
|
|
with mozfile.NamedTemporaryFile() as f:
|
|
|
|
with zipfile.ZipFile(f.name, 'w') as z:
|
|
|
|
self.create_apk_zipfiles(z)
|
|
|
|
z.writestr('package-name.txt', "org.mozilla.fennec")
|
|
|
|
v = get_version(f.name)
|
|
|
|
self.assertEqual(v.get('package_name'), "org.mozilla.fennec")
|
|
|
|
|
2014-08-19 23:20:32 +04:00
|
|
|
if __name__ == '__main__':
|
2016-11-18 00:36:18 +03:00
|
|
|
mozunit.main()
|