From 6f22139e42a1f12c9ddcec2a4b50adb724f75dcf Mon Sep 17 00:00:00 2001 From: piri-p Date: Mon, 6 May 2024 15:59:53 +0200 Subject: [PATCH] Add consistent build number error notification for scrapers (#121) (#677) --- mozdownload/scraper.py | 9 ++++++++- tests/daily_scraper/test_invalid_build.py | 19 ++++++++++++++++++ .../test_release_candidate_scraper_indices.py | 2 +- .../test_invalid_build_tinderbox.py | 20 +++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 tests/daily_scraper/test_invalid_build.py create mode 100644 tests/tinderbox_scraper/test_invalid_build_tinderbox.py diff --git a/mozdownload/scraper.py b/mozdownload/scraper.py index 07e40faf..fc6cc4e7 100755 --- a/mozdownload/scraper.py +++ b/mozdownload/scraper.py @@ -541,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) @@ -762,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): @@ -985,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) diff --git a/tests/daily_scraper/test_invalid_build.py b/tests/daily_scraper/test_invalid_build.py new file mode 100644 index 00000000..a14c8119 --- /dev/null +++ b/tests/daily_scraper/test_invalid_build.py @@ -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) diff --git a/tests/release_candidate_scraper/test_release_candidate_scraper_indices.py b/tests/release_candidate_scraper/test_release_candidate_scraper_indices.py index 97673ef5..02b367d6 100644 --- a/tests/release_candidate_scraper/test_release_candidate_scraper_indices.py +++ b/tests/release_candidate_scraper/test_release_candidate_scraper_indices.py @@ -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) diff --git a/tests/tinderbox_scraper/test_invalid_build_tinderbox.py b/tests/tinderbox_scraper/test_invalid_build_tinderbox.py new file mode 100644 index 00000000..1d291545 --- /dev/null +++ b/tests/tinderbox_scraper/test_invalid_build_tinderbox.py @@ -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)