From 7345795189d703358d2ace6bc9973c8a4e8feb7b Mon Sep 17 00:00:00 2001 From: piri-p Date: Mon, 6 May 2024 09:20:07 +0200 Subject: [PATCH] Raise NotFoundError if no daily build can be found for latest build date (#672) --- mozdownload/scraper.py | 2 ++ tests/daily_scraper/test_invalid_platform.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/daily_scraper/test_invalid_platform.py diff --git a/mozdownload/scraper.py b/mozdownload/scraper.py index a9ae5d2f..763d5d39 100755 --- a/mozdownload/scraper.py +++ b/mozdownload/scraper.py @@ -451,6 +451,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]) diff --git a/tests/daily_scraper/test_invalid_platform.py b/tests/daily_scraper/test_invalid_platform.py new file mode 100644 index 00000000..70c721fd --- /dev/null +++ b/tests/daily_scraper/test_invalid_platform.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': '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)