From bd34c37052f7b0bf2e678051fb464a49dbd0adcc Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Wed, 30 Jun 2021 12:21:17 +1000 Subject: [PATCH 1/3] Add exception for special friends subreddit --- bdfr/connector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bdfr/connector.py b/bdfr/connector.py index 68efc0c..8a6f0bf 100644 --- a/bdfr/connector.py +++ b/bdfr/connector.py @@ -394,7 +394,7 @@ class RedditConnector(metaclass=ABCMeta): @staticmethod def check_subreddit_status(subreddit: praw.models.Subreddit): - if subreddit.display_name == 'all': + if subreddit.display_name in ('all', 'friends'): return try: assert subreddit.id From c4aa6177372e73a469e58cdc5de57675de69a7a8 Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Fri, 2 Jul 2021 14:17:13 +1000 Subject: [PATCH 2/3] Add test for friends subreddit --- .../test_download_integration.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/integration_tests/test_download_integration.py b/tests/integration_tests/test_download_integration.py index fca0f8b..56da1d5 100644 --- a/tests/integration_tests/test_download_integration.py +++ b/tests/integration_tests/test_download_integration.py @@ -58,6 +58,21 @@ def test_cli_download_subreddits(test_args: list[str], tmp_path: Path): assert 'Added submissions from subreddit ' in result.output +@pytest.mark.online +@pytest.mark.reddit +@pytest.mark.authenticated +@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') +@pytest.mark.parametrize('test_args', ( + ['--subreddit', 'friends', '-L', 10, '--authenticate'], +)) +def test_cli_download_user_specific_subreddits(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 'Added submissions from subreddit ' 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') From 8db9d0bcc4119d22b3fcb4e6810d737bf981957c Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Fri, 2 Jul 2021 14:29:39 +1000 Subject: [PATCH 3/3] Add test for unauthenticated instances --- bdfr/connector.py | 3 +++ tests/integration_tests/test_download_integration.py | 1 + 2 files changed, 4 insertions(+) diff --git a/bdfr/connector.py b/bdfr/connector.py index 8a6f0bf..a4165fc 100644 --- a/bdfr/connector.py +++ b/bdfr/connector.py @@ -242,6 +242,9 @@ class RedditConnector(metaclass=ABCMeta): if self.args.subreddit: out = [] for reddit in self.split_args_input(self.args.subreddit): + if reddit == 'friends' and self.authenticated is False: + logger.error('Cannot read friends subreddit without an authenticated instance') + continue try: reddit = self.reddit_instance.subreddit(reddit) try: diff --git a/tests/integration_tests/test_download_integration.py b/tests/integration_tests/test_download_integration.py index 56da1d5..4ee0bba 100644 --- a/tests/integration_tests/test_download_integration.py +++ b/tests/integration_tests/test_download_integration.py @@ -214,6 +214,7 @@ def test_cli_download_long(test_args: list[str], tmp_path: Path): ['--subreddit', 'submitters', '-L', 10], # Private subreddit ['--subreddit', 'donaldtrump', '-L', 10], # Banned subreddit ['--user', 'djnish', '--user', 'helen_darten', '-m', 'cuteanimalpics', '-L', 10], + ['--subreddit', 'friends', '-L', 10], )) def test_cli_download_soft_fail(test_args: list[str], tmp_path: Path): runner = CliRunner()