diff --git a/src/power_grid_model_io/utils/download.py b/src/power_grid_model_io/utils/download.py index 631a9ffc..88731aeb 100644 --- a/src/power_grid_model_io/utils/download.py +++ b/src/power_grid_model_io/utils/download.py @@ -215,7 +215,7 @@ def get_download_path( """ # If no specific download path was given, we need to generate a unique key (based on the given unique key) - if dir_path is None or file_name is None: + if file_name is None or unique_key is not None: if unique_key is None: raise ValueError("Supply a unique key in order to auto generate a download path.") @@ -228,8 +228,7 @@ def get_download_path( if file_name is None: file_name = Path(f"{unique_key}.download") # Otherwise, use the unique key as a sub directory - else: - assert dir_path is None # sanity check + elif dir_path is None: dir_path = Path(tempfile.gettempdir()) / unique_key # If no dir_path is given, use the system's designated folder for temporary files. diff --git a/tests/unit/utils/test_download.py b/tests/unit/utils/test_download.py index 98d74eb3..8db11c3d 100644 --- a/tests/unit/utils/test_download.py +++ b/tests/unit/utils/test_download.py @@ -26,6 +26,8 @@ # The / and + will be replaced with a _ and - character and the trailing = character(s) will be removed. FOO_KEY = "LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564" +TEMP_DIR = Path(tempfile.gettempdir()).resolve() + @pytest.fixture() def temp_dir(): @@ -374,12 +376,20 @@ def test_get_download_path__ignore_unique_key(temp_dir: Path): assert path == temp_dir / "file_name.zip" +def test_get_download_path__temp_dir(): + # Act + path = get_download_path(file_name="file_name.zip") + + # Assert + assert path == TEMP_DIR / "file_name.zip" + + def test_get_download_path__auto_dir(): # Act path = get_download_path(file_name="file_name.zip", unique_key="foo") # Assert - assert path == Path(tempfile.gettempdir()).resolve() / FOO_KEY / "file_name.zip" + assert path == TEMP_DIR / FOO_KEY / "file_name.zip" def test_get_download_path__auto_file_name(temp_dir: Path):