From 06261cc5cd6f34936b8ee2daa89fc759b29a9c31 Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Sun, 14 Mar 2021 12:03:43 +1000 Subject: [PATCH] Add some more integration tests --- bulkredditdownloader/downloader.py | 14 +++++---- .../tests/test_integration.py | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/bulkredditdownloader/downloader.py b/bulkredditdownloader/downloader.py index c1c2b5b..d4b47f2 100644 --- a/bulkredditdownloader/downloader.py +++ b/bulkredditdownloader/downloader.py @@ -137,8 +137,9 @@ class RedditDownloader: else: logger.error(f'Could not find config file at {self.args.config}, attempting to find elsewhere') possible_paths = [Path('./config.cfg'), - Path(self.config_directory, 'config.cfg'), Path('./default_config.cfg'), + Path(self.config_directory, 'config.cfg'), + Path(self.config_directory, 'default_config.cfg'), ] self.config_location = None for path in possible_paths: @@ -243,17 +244,17 @@ class RedditDownloader: if any([self.args.submitted, self.args.upvoted, self.args.saved]): if self.args.user: if not self._check_user_existence(self.args.user): - raise errors.RedditUserError(f'User {self.args.user} does not exist') + logger.error(f'User {self.args.user} does not exist') + return [] generators = [] sort_function = self._determine_sort_function() if self.args.submitted: logger.debug(f'Retrieving submitted posts of user {self.args.user}') generators.append( sort_function( - self.reddit_instance.redditor(self.args.user).submissions, - limit=self.args.limit)) + self.reddit_instance.redditor(self.args.user).submissions, limit=self.args.limit)) if not self.authenticated and any((self.args.upvoted, self.args.saved)): - raise errors.RedditAuthenticationError('Accessing user lists requires authentication') + logger.error('Accessing user lists requires authentication') else: if self.args.upvoted: logger.debug(f'Retrieving upvoted posts of user {self.args.user}') @@ -263,7 +264,8 @@ class RedditDownloader: generators.append(self.reddit_instance.redditor(self.args.user).saved(limit=self.args.limit)) return generators else: - raise errors.BulkDownloaderException('A user must be supplied to download user data') + logger.error('A user must be supplied to download user data') + return [] else: return [] diff --git a/bulkredditdownloader/tests/test_integration.py b/bulkredditdownloader/tests/test_integration.py index 644dd07..d025828 100644 --- a/bulkredditdownloader/tests/test_integration.py +++ b/bulkredditdownloader/tests/test_integration.py @@ -199,3 +199,34 @@ def test_cli_archive_long(test_args: list[str], tmp_path: Path): result = runner.invoke(cli, test_args) assert result.exit_code == 0 assert re.search(r'Writing submission .*? to file in .*? format', result.output) + + +@pytest.mark.online +@pytest.mark.reddit +@pytest.mark.slow +@pytest.mark.skipif(Path('test_config.cfg') is False, reason='A test config file is required for integration tests') +@pytest.mark.parametrize('test_args', ( + ['--user', 'sdclhgsolgjeroij', '--submitted', '-L', 10], + ['--user', 'me', '--upvoted', '-L', 10], + ['--user', 'sdclhgsolgjeroij', '--upvoted', '-L', 10], +)) +def test_cli_download_soft_fail(test_args: list[str], tmp_path: Path): + runner = CliRunner() + test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args + result = runner.invoke(cli, test_args) + assert result.exit_code == 0 + + +@pytest.mark.online +@pytest.mark.reddit +@pytest.mark.slow +@pytest.mark.skipif(Path('test_config.cfg') is False, reason='A test config file is required for integration tests') +@pytest.mark.parametrize('test_args', ( + ['--time', 'random'], + ['--sort', 'random'], +)) +def test_cli_download_hard_fail(test_args: list[str], tmp_path: Path): + runner = CliRunner() + test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args + result = runner.invoke(cli, test_args) + assert result.exit_code != 0