From 77a01e1627e8c47a6cf27f76894c08f661894d14 Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Wed, 4 Jan 2023 19:49:09 +1000 Subject: [PATCH] Add tests for new option --- bdfr/connector.py | 5 ++++- .../test_download_integration.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bdfr/connector.py b/bdfr/connector.py index 8fe149a..860750d 100644 --- a/bdfr/connector.py +++ b/bdfr/connector.py @@ -111,6 +111,7 @@ class RedditConnector(metaclass=ABCMeta): self.args.filename_restriction_scheme = self.cfg_parser.get( "DEFAULT", "filename_restriction_scheme", fallback=None ) + logger.debug(f"Setting filename restriction scheme to '{self.args.filename_restriction_scheme}'") # Update config on disk with open(self.config_location, "w") as file: self.cfg_parser.write(file) @@ -399,7 +400,9 @@ class RedditConnector(metaclass=ABCMeta): raise errors.BulkDownloaderException(f"User {name} is banned") def create_file_name_formatter(self) -> FileNameFormatter: - return FileNameFormatter(self.args.file_scheme, self.args.folder_scheme, self.args.time_format) + return FileNameFormatter( + self.args.file_scheme, self.args.folder_scheme, self.args.time_format, self.args.filename_restriction_scheme + ) def create_time_filter(self) -> RedditTypes.TimeType: try: diff --git a/tests/integration_tests/test_download_integration.py b/tests/integration_tests/test_download_integration.py index 545bd31..35ca0c0 100644 --- a/tests/integration_tests/test_download_integration.py +++ b/tests/integration_tests/test_download_integration.py @@ -421,3 +421,22 @@ def test_user_serv_fail(test_args: list[str], response: int, tmp_path: Path): result = runner.invoke(cli, test_args) assert result.exit_code == 0 assert f"received {response} HTTP response" in result.output + + +@pytest.mark.online +@pytest.mark.reddit +@pytest.mark.skipif(not does_test_config_exist, reason="A test config file is required for integration tests") +@pytest.mark.parametrize( + "test_args", + ( + ["-l", "102vd5i", "--filename-restriction-scheme", "windows"], + ["-l", "m3hxzd", "--filename-restriction-scheme", "windows"], + ), +) +def test_cli_download_explicit_filename_restriction_scheme(test_args: list[str], tmp_path: Path): + runner = CliRunner() + test_args = create_basic_args_for_download_runner(test_args, tmp_path) + result = runner.invoke(cli, test_args) + assert result.exit_code == 0 + assert "Downloaded submission" in result.output + assert "Forcing Windows-compatible filenames" in result.output