def test_nsfw_filter_include(self): post_filter = PostFilter() user = MockObjects.get_blank_user() post = MockPrawPost(over_18=True) self.assertTrue(post_filter.nsfw_filter(post, user)) post = MockPrawPost(over_18=False) self.assertTrue(post_filter.nsfw_filter(post, user))
def test_score_filter_greater_than_score(self): Injector.get_settings_manager().restrict_by_score = True post_filter = PostFilter() post = MockPrawPost(score=5000) self.assertTrue(post_filter.score_filter(post)) post = MockPrawPost(score=2000) self.assertFalse(post_filter.score_filter(post))
def test_get_submissions_with_old_stickied_posts_subreddits_filtered(self, start_extractor, start_downloader, get_raw_submissions): allowed_subreddit = MockPrawSubreddit(name='allowed') forbidden_subreddit = MockPrawSubreddit(name='forbidden') reddit_user = get_blank_user() reddit_user.date_limit = datetime.now() - timedelta(days=20) mock_posts_list = [] for x in range(2): mock_posts_list.append(MockPrawPost(created=datetime.now() - timedelta(days=100), stickied=True, subreddit=allowed_subreddit)) for x in range(2, 18): mock_posts_list.append(MockPrawPost(created=datetime.now() - timedelta(days=x), subreddit=allowed_subreddit)) for x in range(18, 30): mock_posts_list.append(MockPrawPost(created=datetime.now() - timedelta(days=x), subreddit=forbidden_subreddit)) get_raw_submissions.return_value = self.submission_generator(mock_posts_list) self.assertEqual(30, len(mock_posts_list)) download_runner = DownloadRunner(None, None, None, None) download_runner.validated_subreddits.append(allowed_subreddit.display_name) submissions = download_runner.get_submissions(None, reddit_user, subreddit_filter=True) self.assertEqual(16, len(submissions)) for sub in submissions: self.assertGreater(sub.created, reddit_user.date_limit) self.assertFalse(sub.stickied)
def test_get_submissions_with_new_stickied_posts(self, start_extractor, start_downloader, get_raw_submissions): reddit_user = get_blank_user() reddit_user.date_limit = datetime.now() - timedelta(days=10) mock_posts_list = [] for x in range(2): mock_posts_list.append( MockPrawPost(created=datetime.now() - timedelta(days=x), stickied=True)) for x in range(2, 20): mock_posts_list.append( MockPrawPost(created=datetime.now() - timedelta(days=x))) get_raw_submissions.return_value = self.submission_generator( mock_posts_list) self.assertEqual(20, len(mock_posts_list)) download_runner = DownloadRunner(None, None, None, None) submissions = download_runner.get_submissions(None, reddit_user) self.assertEqual(10, len(submissions)) stickied = 0 for sub in submissions: self.assertGreater(sub.created, reddit_user.date_limit) if sub.stickied: stickied += 1 self.assertEqual(2, stickied)
def test_date_limit_last_download_time(self): post_filter = PostFilter() user = MockObjects.get_blank_user() user.date_limit = MOCK_DATE_LIMIT post = MockPrawPost(created=MOCK_DATE_LIMIT + 1000) self.assertTrue(post_filter.date_filter(post, user)) post = MockPrawPost(created=MOCK_DATE_LIMIT - 1000) self.assertFalse(post_filter.date_filter(post, user))
def test_score_filter_less_than_score(self): settings_manager = Injector.get_settings_manager() settings_manager.restrict_by_score = True settings_manager.score_limit_operator = 'LESS' post_filter = PostFilter() post = MockPrawPost(score=1000) self.assertTrue(post_filter.score_filter(post)) post = MockPrawPost(score=4000) self.assertFalse(post_filter.score_filter(post))
def test_score_filter_no_limit_restriction(self): Injector.get_settings_manager().restrict_by_score = False post_filter = PostFilter() post = MockPrawPost(score=10000) self.assertTrue(post_filter.score_filter(post))