diff --git a/apps/cli/executables/datafetcher/datafetcher/file_retrievers.py b/apps/cli/executables/datafetcher/datafetcher/file_retrievers.py index a509e19ae8cc4ac70094e62adcd8a1494eb6b9f7..b61c162be9ebb638fe0b077826d9dd45554a42a9 100644 --- a/apps/cli/executables/datafetcher/datafetcher/file_retrievers.py +++ b/apps/cli/executables/datafetcher/datafetcher/file_retrievers.py @@ -52,7 +52,7 @@ class NGASFileRetriever: download_url = "http://" + server + "/RETRIEVE" destination = self._get_destination(file_spec) if destination.exists() and not self.force_overwrite and not self.dry_run: - raise FileExistsError(f"{destination} exists; aborting") + raise FileErrorException(f"{destination} exists; aborting") self._make_basedir(destination) diff --git a/apps/cli/executables/datafetcher/datafetcher/locations_report.py b/apps/cli/executables/datafetcher/datafetcher/locations_report.py index f8e751ee6d1da1b4cd6f993624d9717f10087322..e46655a49f5cfe9a87ce6fc34918ae94c972f63e 100644 --- a/apps/cli/executables/datafetcher/datafetcher/locations_report.py +++ b/apps/cli/executables/datafetcher/datafetcher/locations_report.py @@ -34,22 +34,19 @@ class LocationsReport: """ Builds a location report """ def __init__(self, args: Namespace, settings: Dict): - - try: - self.verbose = args.verbose or False - except AttributeError: - # doesn't matter; verbose is going away soon - self.verbose = False - - self._capture_and_validate_input(args, settings) - self._run() - - def _capture_and_validate_input(self, args, settings): if args is None: raise MissingSettingsException( "arguments (locator and/or report file, destination) are required" ) - self.args = args + self.product_locator = args.product_locator + self.location_file = args.location_file + if not self.product_locator and not self.location_file: + raise NoLocatorException("either product locator or report file must be specified") + if self.product_locator and self.location_file: + raise NoLocatorException( + "either product locator -or- report file must be specified -- not both" + ) + if settings is None: raise MissingSettingsException("CAPO settings are required") self.settings = settings @@ -57,10 +54,13 @@ class LocationsReport: if not self.settings["execution_site"]: raise MissingSettingsException("execution_site is required") - self.product_locator = args.product_locator - self.location_file = args.location_file - if not self.product_locator and not self.location_file: - raise NoLocatorException("either product locator or report file must be specified") + try: + self.verbose = args.verbose or False + except AttributeError: + # doesn't matter; verbose is going away soon + self.verbose = False + + self._run() def _run(self): self.files_report = self._get_files_report() diff --git a/apps/cli/executables/datafetcher/test/test_df_function.py b/apps/cli/executables/datafetcher/test/test_df_function.py index 1f337682fdb7207c6b75672a8c2fbe8feb4325db..5a7035486d3891702bddeaed6618831041d15429 100644 --- a/apps/cli/executables/datafetcher/test/test_df_function.py +++ b/apps/cli/executables/datafetcher/test/test_df_function.py @@ -7,8 +7,8 @@ import pytest from datafetcher.errors import ( NGASFetchError, - MissingSettingsException, NGASServiceErrorException, + FileErrorException, ) # pylint: disable=C0115, C0116, C0200, C0415, R0801, R0902, R0903, R0914, R1721, @@ -163,21 +163,15 @@ def test_no_overwrite_without_force(make_tempdir, capo_settings): str(top_level), ] - with pytest.raises(FileExistsError): + with pytest.raises(FileErrorException): try_to_launch_df(capo_settings, args) retrieved = [ file for file in top_level.rglob("*") if file.is_file() and not str(file).endswith(".json") ] - num_not_too_big_files_expected = 28 - assert len(retrieved) == num_not_too_big_files_expected # get rid of all the files we downloaded, plus the log - deleted = [ - file.unlink() for file in retrieved if file.is_file() and not str(file).endswith(".json") - ] - - assert len(deleted) >= num_not_too_big_files_expected + [file.unlink() for file in retrieved if file.is_file() and not str(file).endswith(".json")] @pytest.mark.skipif(not RUN_ALL, reason="debug") @@ -257,7 +251,7 @@ def test_dies_with_bad_server_info(make_tempdir, settings): @pytest.mark.skipif(not RUN_ALL, reason="debug") -def test_missing_setting_exc_on_bad_destination(settings): +def test_throws_file_err_for_existing_destination(settings): args = [ "--profile", TEST_PROFILE, @@ -266,7 +260,7 @@ def test_missing_setting_exc_on_bad_destination(settings): "--output-dir", "floob", ] - with pytest.raises(MissingSettingsException): + with pytest.raises(FileErrorException): launch_datafetcher(args, settings.capo_settings)