1
0
Fork 0

add test. fix typos.

This commit is contained in:
Jay R. Wren 2021-11-01 09:28:46 -04:00 committed by Serene-Arc
parent dd8d74ee25
commit 2b50ee0724
4 changed files with 22 additions and 3 deletions

View File

@ -78,7 +78,7 @@ The following options are common between both the `archive` and `download` comma
- Can be specified multiple times
- Disables certain modules from being used
- See [Disabling Modules](#disabling-modules) for more information and a list of module names
- `--ignore`
- `--ignore-user`
- This will add a user to ignore
- Can be specified multiple times
- `--include-id-file`

View File

@ -17,7 +17,5 @@ class RedditCloner(RedditDownloader, Archiver):
def download(self):
for generator in self.reddit_lists:
for submission in generator:
if submission.author.name in self.args.ignore_user:
continue
self._download_submission(submission)
self.write_entry(submission)

View File

@ -51,6 +51,10 @@ class RedditDownloader(RedditConnector):
elif submission.subreddit.display_name.lower() in self.args.skip_subreddit:
logger.debug(f'Submission {submission.id} in {submission.subreddit.display_name} in skip list')
return
elif submission.author.name in self.args.ignore_user:
logger.debug(
f'Submission {submission.id} in {submission.subreddit.display_name} by {submission.author.name} an ignored user')
return
elif not isinstance(submission, praw.models.Submission):
logger.warning(f'{submission.id} is not a submission')
return

View File

@ -200,3 +200,20 @@ def test_download_submission(
RedditDownloader._download_submission(downloader_mock, submission)
folder_contents = list(tmp_path.iterdir())
assert len(folder_contents) == expected_files_len
@pytest.mark.parametrize('test_ignore_user', (
'alice',
))
def test_download_ignores_user(
test_ignore_user: str,
mock_function: MagicMock,
downloader_mock: MagicMock,
):
downloader_mock.args.ignore_user = test_ignore_user
submission = downloader_mock.reddit_instance.submission(id='m1hqw6')
mock_function.return_value = MagicMock()
mock_function.return_value.__name__ = 'test'
submission.author.name = test_ignore_user
RedditDownloader._download_submission(downloader_mock, submission)
assert mock_function.call_count == 0