tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_apk.py (1273B)


      1 #!/usr/bin/env python
      2 
      3 # This Source Code Form is subject to the terms of the Mozilla Public
      4 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 # You can obtain one at http://mozilla.org/MPL/2.0/.
      6 
      7 import zipfile
      8 
      9 import mozunit
     10 import pytest
     11 from mozversion import get_version
     12 
     13 """test getting version information from an android .apk"""
     14 
     15 application_changeset = "a" * 40
     16 platform_changeset = "b" * 40
     17 
     18 
     19 @pytest.fixture(name="apk")
     20 def fixture_apk(tmpdir):
     21    path = str(tmpdir.join("apk.zip"))
     22    with zipfile.ZipFile(path, "w") as z:
     23        z.writestr(
     24            "application.ini", """[App]\nSourceStamp=%s\n""" % application_changeset
     25        )
     26        z.writestr("platform.ini", """[Build]\nSourceStamp=%s\n""" % platform_changeset)
     27        z.writestr("AndroidManifest.xml", "")
     28    return path
     29 
     30 
     31 def test_basic(apk):
     32    v = get_version(apk)
     33    assert v.get("application_changeset") == application_changeset
     34    assert v.get("platform_changeset") == platform_changeset
     35 
     36 
     37 def test_with_package_name(apk):
     38    with zipfile.ZipFile(apk, "a") as z:
     39        z.writestr("package-name.txt", "org.mozilla.fennec")
     40    v = get_version(apk)
     41    assert v.get("package_name") == "org.mozilla.fennec"
     42 
     43 
     44 if __name__ == "__main__":
     45    mozunit.main()