From e5be624f1e2f4d985f50b53c3c72ab78e6988721 Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Wed, 23 Jun 2021 14:30:39 +1000 Subject: [PATCH] Check submission URL against filter before factory --- bdfr/downloader.py | 5 ++++- tests/test_integration.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/bdfr/downloader.py b/bdfr/downloader.py index ab6bf56..f4220db 100644 --- a/bdfr/downloader.py +++ b/bdfr/downloader.py @@ -54,6 +54,9 @@ class RedditDownloader(RedditConnector): elif not isinstance(submission, praw.models.Submission): logger.warning(f'{submission.id} is not a submission') return + elif not self.download_filter.check_url(submission.url): + logger.debug(f'Submission {submission.id} filtered due to URL {submission.url}') + return logger.debug(f'Attempting to download submission {submission.id}') try: @@ -76,7 +79,7 @@ class RedditDownloader(RedditConnector): logger.debug(f'File {destination} from submission {submission.id} already exists, continuing') continue elif not self.download_filter.check_resource(res): - logger.debug(f'Download filter removed {submission.id} with URL {submission.url}') + logger.debug(f'Download filter removed {submission.id} file with URL {submission.url}') continue try: res.download(self.args.max_wait_time) diff --git a/tests/test_integration.py b/tests/test_integration.py index 0a6de3d..6bad3f6 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -189,6 +189,20 @@ def test_cli_download_download_filters(test_args: list[str], tmp_path: Path): assert 'Download filter removed ' 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', ( + ['--subreddit', 'tumblr', '-L', '10', '--skip-domain', 'i.redd.it'], +)) +def test_cli_download_download_filter_domain(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 'filtered due to URL' in result.output + + @pytest.mark.online @pytest.mark.reddit @pytest.mark.slow