Skip to content

Commit

Permalink
Add new unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLorenzo committed Mar 10, 2017
1 parent 94a0eb2 commit d374cf0
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions mozapkpublisher/test/test_get_apk.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
from tempfile import mkdtemp

from mozapkpublisher.exceptions import CheckSumMismatch, WrongArgumentGiven
from mozapkpublisher.get_apk import GetAPK, _craft_apk_and_checksums_file_names, _get_architecture_in_file_name, check_apk_against_checksum_file
from mozapkpublisher.get_apk import GetAPK, \
craft_apk_and_checksums_url_and_download_locations, _craft_apk_and_checksums_file_names, _get_architecture_in_file_name, \
check_apk_against_checksum_file, _fetch_checksum_from_file

VALID_CONFIG = {'version': '50.0b8'}
CHECKSUM_APK = os.path.join(os.path.dirname(__file__), 'data', 'blob')
get_apk = GetAPK(VALID_CONFIG)

DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')


def test_mutually_exclusive_group():
with pytest.raises(WrongArgumentGiven):
Expand Down Expand Up @@ -42,6 +46,29 @@ def test_get_api_suffix():
assert get_apk.get_api_suffix('x86') == ['x86']


def test_craft_apk_and_checksums_url_and_download_locations():
assert craft_apk_and_checksums_url_and_download_locations(
'https://ftp.mozilla.org/pub/mobile/candidates/52.0b1-candidates/build1/android-api-15/multi',
'/a/fake/download/directory', '52.0b1', 'multi', 'arm'
) == [{
'url': 'https://ftp.mozilla.org/pub/mobile/candidates/52.0b1-candidates/build1/android-api-15/multi/fennec-52.0b1.multi.android-arm.apk',
'download_location': '/a/fake/download/directory/fennec-52.0b1.multi.android-arm.apk',
}, {
'url': 'https://ftp.mozilla.org/pub/mobile/candidates/52.0b1-candidates/build1/android-api-15/multi/fennec-52.0b1.multi.android-arm.checksums',
'download_location': '/a/fake/download/directory/fennec-52.0b1.multi.android-arm.checksums',
}]
assert craft_apk_and_checksums_url_and_download_locations(
'https://ftp.mozilla.org/pub/mobile/nightly/latest-mozilla-aurora-android-api-15',
'/a/fake/download/directory', '53.0a2', 'multi', 'arm'
) == [{
'url': 'https://ftp.mozilla.org/pub/mobile/nightly/latest-mozilla-aurora-android-api-15/fennec-53.0a2.multi.android-arm.apk',
'download_location': '/a/fake/download/directory/fennec-53.0a2.multi.android-arm.apk',
}, {
'url': 'https://ftp.mozilla.org/pub/mobile/nightly/latest-mozilla-aurora-android-api-15/fennec-53.0a2.multi.android-arm.checksums',
'download_location': '/a/fake/download/directory/fennec-53.0a2.multi.android-arm.checksums',
}]


def test_craft_apk_and_checksums_file_names():
assert _craft_apk_and_checksums_file_names('50.0b8', 'multi', 'arm') == \
['fennec-50.0b8.multi.android-arm.apk', 'fennec-50.0b8.multi.android-arm.checksums']
Expand All @@ -55,11 +82,11 @@ def test_get_architecture_in_file_name():


@pytest.mark.parametrize('checksum_file,raises', ((
os.path.join(os.path.dirname(__file__), 'data', 'checksums.old'), False,
os.path.join(DATA_DIR, 'checksums.old'), False,
), (
os.path.join(os.path.dirname(__file__), 'data', 'checksums.tc'), False,
os.path.join(DATA_DIR, 'checksums.tc'), False,
), (
os.path.join(os.path.dirname(__file__), 'data', 'checksums.broken'), True,
os.path.join(DATA_DIR, 'checksums.broken'), True,
)))
def test_check_apk_against_checksum_file(checksum_file, raises):
try:
Expand All @@ -75,3 +102,12 @@ def test_check_apk_against_checksum_file(checksum_file, raises):
assert check_apk_against_checksum_file(CHECKSUM_APK, cfile) is None
finally:
shutil.rmtree(temp_dir)


@pytest.mark.parametrize('checksum_file', (
os.path.join(DATA_DIR, 'checksums.old'),
os.path.join(DATA_DIR, 'checksums.tc'),
))
def test_fetch_checksum_from_file(checksum_file):
assert _fetch_checksum_from_file(checksum_file, CHECKSUM_APK) == \
'd5ee2608eb21d827deef87732dc4796c7209098b8db39f95c3fac87c0dc7b186f2b097f0a52e856e6ac504ff3039a3e23936615be55a172665cdd0250f3a4379'

0 comments on commit d374cf0

Please sign in to comment.