Add some more integration tests
This commit is contained in:
parent
61ba21639d
commit
06261cc5cd
2 changed files with 39 additions and 6 deletions
|
@ -137,8 +137,9 @@ class RedditDownloader:
|
||||||
else:
|
else:
|
||||||
logger.error(f'Could not find config file at {self.args.config}, attempting to find elsewhere')
|
logger.error(f'Could not find config file at {self.args.config}, attempting to find elsewhere')
|
||||||
possible_paths = [Path('./config.cfg'),
|
possible_paths = [Path('./config.cfg'),
|
||||||
Path(self.config_directory, 'config.cfg'),
|
|
||||||
Path('./default_config.cfg'),
|
Path('./default_config.cfg'),
|
||||||
|
Path(self.config_directory, 'config.cfg'),
|
||||||
|
Path(self.config_directory, 'default_config.cfg'),
|
||||||
]
|
]
|
||||||
self.config_location = None
|
self.config_location = None
|
||||||
for path in possible_paths:
|
for path in possible_paths:
|
||||||
|
@ -243,17 +244,17 @@ class RedditDownloader:
|
||||||
if any([self.args.submitted, self.args.upvoted, self.args.saved]):
|
if any([self.args.submitted, self.args.upvoted, self.args.saved]):
|
||||||
if self.args.user:
|
if self.args.user:
|
||||||
if not self._check_user_existence(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 = []
|
generators = []
|
||||||
sort_function = self._determine_sort_function()
|
sort_function = self._determine_sort_function()
|
||||||
if self.args.submitted:
|
if self.args.submitted:
|
||||||
logger.debug(f'Retrieving submitted posts of user {self.args.user}')
|
logger.debug(f'Retrieving submitted posts of user {self.args.user}')
|
||||||
generators.append(
|
generators.append(
|
||||||
sort_function(
|
sort_function(
|
||||||
self.reddit_instance.redditor(self.args.user).submissions,
|
self.reddit_instance.redditor(self.args.user).submissions, limit=self.args.limit))
|
||||||
limit=self.args.limit))
|
|
||||||
if not self.authenticated and any((self.args.upvoted, self.args.saved)):
|
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:
|
else:
|
||||||
if self.args.upvoted:
|
if self.args.upvoted:
|
||||||
logger.debug(f'Retrieving upvoted posts of user {self.args.user}')
|
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))
|
generators.append(self.reddit_instance.redditor(self.args.user).saved(limit=self.args.limit))
|
||||||
return generators
|
return generators
|
||||||
else:
|
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:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
|
@ -199,3 +199,34 @@ def test_cli_archive_long(test_args: list[str], tmp_path: Path):
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert re.search(r'Writing submission .*? to file in .*? format', result.output)
|
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
|
||||||
|
|
Loading…
Reference in a new issue