Skip to content

Commit

Permalink
Merge branch 'master' into issue-179-local-test-port
Browse files Browse the repository at this point in the history
  • Loading branch information
piri-p authored May 7, 2024
2 parents 2c87498 + 6f22139 commit 0a82905
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 10 deletions.
22 changes: 15 additions & 7 deletions mozdownload/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,12 @@ def __init__(self, destination=None, platform=None,

self.destination = destination or os.getcwd()

if not locale:
if application in APPLICATIONS_MULTI_LOCALE:
self.locale = 'multi'
else:
self.locale = 'en-US'
else:
if application in APPLICATIONS_MULTI_LOCALE:
self.locale = 'multi'
elif locale:
self.locale = locale
else:
self.locale = 'en-US'
self.locale_build = self.locale not in ('en-US', 'multi')

self.platform = platform or self.detect_platform()
Expand Down Expand Up @@ -451,6 +450,8 @@ def get_latest_build_date(self):
months.entries[-1] + '/')
parser = self._create_directory_parser(url)
parser.entries = parser.filter(r'.*%s' % self.platform_regex)
if not parser.entries:
raise errors.NotFoundError('No builds have been found', url)
parser.entries.sort()

date = ''.join(parser.entries[-1].split('-')[:6])
Expand Down Expand Up @@ -540,6 +541,10 @@ def get_build_info_for_date(self, date, build_index=None):
build_index -= 1
if not build_index or self.is_build_dir(build):
break

if build_index >= len(parser.entries):
raise errors.NotFoundError('Specified build number has not been found ', url)

self.logger.info('Selected build: %s' % parser.entries[build_index])

return (parser.entries, build_index)
Expand Down Expand Up @@ -761,7 +766,7 @@ def get_build_info(self):
self.build_index = 0
self.logger.info('Selected build: build%s' % self.build_number)
else:
raise errors.NotSupportedError('Selected build not available')
raise errors.NotFoundError('Specified build number has not been found ', url)

@property
def candidate_build_list_regex(self):
Expand Down Expand Up @@ -984,6 +989,9 @@ def get_build_info_for_index(self, build_index=None):
if not build_index or self.is_build_dir(build):
break

if build_index >= len(parser.entries):
raise errors.NotFoundError('Specified build number has not been found ', url)

self.logger.info('Selected build: %s' % parser.entries[build_index])

return (parser.entries, build_index)
Expand Down
4 changes: 2 additions & 2 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coveralls[yaml]==3.3.1
pytest==8.1.1
coveralls[yaml]==4.0.0
pytest==8.2.0
pytest-cov==5.0.0
pytest-mock==3.14.0
wptserve==4.0.2
3 changes: 3 additions & 0 deletions tests/daily_scraper/test_daily_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
({'application': 'fenix', 'platform': 'android-x86_64', 'date': '2022-11-14'},
'2022-11-14-17-01-36-fenix-108.0b1.multi.android-x86_64.apk',
'fenix/nightly/2022/11/2022-11-14-17-01-36-fenix-108.0b1-android-x86_64/fenix-108.0b1.multi.android-x86_64.apk'),
({'application': 'fenix', 'platform': 'android-arm64-v8a', 'date': '2022-11-14', 'locale': 'de'},
'2022-11-14-17-01-36-fenix-108.0b1.multi.android-arm64-v8a.apk',
'fenix/nightly/2022/11/2022-11-14-17-01-36-fenix-108.0b1-android-arm64-v8a/fenix-108.0b1.multi.android-arm64-v8a.apk'),
]

@pytest.mark.parametrize("args,filename,url", firefox_tests + thunderbird_tests + fenix_tests)
Expand Down
19 changes: 19 additions & 0 deletions tests/daily_scraper/test_invalid_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/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 pytest

from mozdownload import DailyScraper
import mozdownload.errors as errors

@pytest.mark.parametrize('args', [
({'application': 'firefox', 'date': '2013-07-02', 'build_number': 3}),
])
def test_invalid_build(httpd, tmpdir, args):
"""Testing download scenarios with invalid branch parameters for DailyScraper"""

with pytest.raises(errors.NotFoundError):
DailyScraper(destination=str(tmpdir), base_url=httpd.get_url(), **args)
19 changes: 19 additions & 0 deletions tests/daily_scraper/test_invalid_platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/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 pytest

from mozdownload import DailyScraper
import mozdownload.errors as errors

@pytest.mark.parametrize('args', [
({'application': 'fenix', 'platform': 'mac'}),
])
def test_invalid_platform(httpd, tmpdir, args):
"""Testing download scenarios with invalid platform parameters for DailyScraper"""

with pytest.raises(errors.NotFoundError):
DailyScraper(destination=str(tmpdir), base_url=httpd.get_url(), **args)
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ def test_invalid_build_number(httpd, tmpdir):

args = {'application': 'firefox', 'build_number': '2', 'platform': 'linux', 'version': '23.0.1'}

with pytest.raises(errors.NotSupportedError):
with pytest.raises(errors.NotFoundError):
ReleaseCandidateScraper(destination=tmpdir, base_url=httpd.get_url(), **args)
3 changes: 3 additions & 0 deletions tests/release_scraper/test_release_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
({'application': 'fenix', 'platform': 'android-x86_64', 'version': '120.1.0'},
'fenix-120.1.0.multi.android-x86_64.apk',
'fenix/releases/120.1.0/android/fenix-120.1.0-android-x86_64/fenix-120.1.0.multi.android-x86_64.apk'),
({'application': 'fenix', 'platform': 'android-arm64-v8a', 'version': '120.1.0', 'locale': 'de'},
'fenix-120.1.0.multi.android-arm64-v8a.apk',
'fenix/releases/120.1.0/android/fenix-120.1.0-android-arm64-v8a/fenix-120.1.0.multi.android-arm64-v8a.apk'),
({'platform': 'win32', 'version': '23.0.1'},
'firefox-23.0.1.en-US.win32.exe',
'firefox/releases/23.0.1/win32/en-US/Firefox Setup 23.0.1.exe'),
Expand Down
3 changes: 3 additions & 0 deletions tests/release_scraper/test_release_scraper_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
({'application': 'fenix', 'platform': 'android-x86_64', 'version': 'latest-beta'},
'fenix-120.0b9.multi.android-x86_64.apk',
'fenix/releases/120.0b9/android/fenix-120.0b9-android-x86_64/fenix-120.0b9.multi.android-x86_64.apk'),
({'application': 'fenix', 'platform': 'android-arm64-v8a', 'version': 'latest', 'locale': 'de'},
'fenix-120.1.0.multi.android-arm64-v8a.apk',
'fenix/releases/120.1.0/android/fenix-120.1.0-android-arm64-v8a/fenix-120.1.0.multi.android-arm64-v8a.apk'),
({'application': 'firefox', 'platform': 'linux', 'version': 'latest'},
'firefox-23.0.1.en-US.linux.tar.bz2',
'firefox/releases/23.0.1/linux-i686/en-US/firefox-23.0.1.tar.bz2'),
Expand Down
20 changes: 20 additions & 0 deletions tests/tinderbox_scraper/test_invalid_build_tinderbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/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 pytest

from mozdownload import TinderboxScraper
import mozdownload.errors as errors


@pytest.mark.parametrize("args", [
({'application': 'firefox', 'branch': 'mozilla-central', 'build_number': '4', 'date': '2013-07-23'}),
])
def test_invalid_build_tinderbox(httpd, tmpdir, args):
"""Testing download scenarios with invalid parameters for TinderboxScraper"""

with pytest.raises(errors.NotFoundError):
TinderboxScraper(destination=str(tmpdir), base_url=httpd.get_url(), **args)

0 comments on commit 0a82905

Please sign in to comment.