diff --git a/bdfr/downloader.py b/bdfr/downloader.py index 5acb7de..72cc019 100644 --- a/bdfr/downloader.py +++ b/bdfr/downloader.py @@ -344,7 +344,7 @@ class RedditDownloader: try: if not user.id: return False - except prawcore.exceptions.NotFound: + except (prawcore.exceptions.NotFound, AttributeError): return False return True diff --git a/tests/test_downloader.py b/tests/test_downloader.py index 0d609ef..189f66a 100644 --- a/tests/test_downloader.py +++ b/tests/test_downloader.py @@ -458,3 +458,21 @@ def test_read_excluded_submission_ids_from_file(downloader_mock: MagicMock, tmp_ downloader_mock.args.exclude_id_file = [test_file] results = RedditDownloader._read_excluded_ids(downloader_mock) assert results == {'aaaaaa', 'bbbbbb'} + + +@pytest.mark.online +@pytest.mark.reddit +@pytest.mark.parametrize(('test_redditor_name', 'expected'), ( + ('anthonyhui', True), # Real + ('lhnhfkuhwreolo', False), # Fake + ('Bree-Boo', False), # Banned +)) +def test_check_user_existence( + test_redditor_name: str, + expected: bool, + reddit_instance: praw.Reddit, + downloader_mock: MagicMock, +): + downloader_mock.reddit_instance = reddit_instance + result = RedditDownloader._check_user_existence(downloader_mock, test_redditor_name) + assert result == expected