def test_nsfw_filter_only(self):
        user = get_user(download_nsfw=NsfwFilter.ONLY)
        submission = MockPrawSubmission(over_18=True)
        self.assertTrue(self.sub_filter.nsfw_filter(submission, user))

        submission.over_18 = False
        self.assertFalse(self.sub_filter.nsfw_filter(submission, user))
    def test_nsfw_filter_exclude(self):
        user = get_user(download_nsfw=NsfwFilter.EXCLUDE)
        submission = MockPrawSubmission(over_18=False)
        self.assertTrue(self.sub_filter.nsfw_filter(submission, user))

        submission.over_18 = True
        self.assertFalse(self.sub_filter.nsfw_filter(submission, user))
Пример #3
0
    def test_get_submissions_with_new_pinned_posts_restricted_download(self, get_raw_submissions, reddit_utils):
        allowed_subreddit = get_subreddit(name='allowed')
        setattr(allowed_subreddit, 'display_name', 'allowed')
        forbidden_subreddit = get_subreddit(name='forbidden')
        setattr(forbidden_subreddit, 'display_name', 'forbidden')
        user = get_user(absolute_date_limit=self.now - timedelta(days=10))
        mock_submissions = []
        for x in range(2):
            mock_submissions.append(MockPrawSubmission(created=self.now - timedelta(days=x), pinned=True,
                                                       subreddit=allowed_subreddit))
        for x in range(2, 20):
            mock_submissions.append(MockPrawSubmission(created=self.now - timedelta(days=x),
                                                       subreddit=allowed_subreddit))
        for x in range(2, 20):
            mock_submissions.append(MockPrawSubmission(created=self.now - timedelta(days=x),
                                                       subreddit=forbidden_subreddit))
        get_raw_submissions.return_value = self.submission_generator(mock_submissions)
        self.assertEqual(38, len(mock_submissions))

        download_runner = DownloadRunner()
        download_runner.filter_subreddits = True
        download_runner.validated_subreddits.append(allowed_subreddit.display_name)
        submissions = download_runner.get_submissions(None, user)

        self.assertEqual(10, len(submissions))
        pinned = 0
        for sub in submissions:
            self.assertGreater(sub.created, user.absolute_date_limit.timestamp())
            self.assertNotEqual(sub.subreddit, forbidden_subreddit)
            if sub.pinned:
                pinned += 1
        self.assertEqual(2, pinned)
    def test_date_filter_absolute_limit(self):
        limit = datetime.now() - timedelta(days=10)
        date = datetime.now() - timedelta(days=5)
        user = get_user(absolute_date_limit=limit, date_limit=None)
        submission = MockPrawSubmission(created=date)
        self.assertTrue(self.sub_filter.date_filter(submission, user))

        submission.created = (date - timedelta(days=20)).timestamp()
        self.assertFalse(self.sub_filter.date_filter(submission, user))
    def test_score_filter_no_limit_restriction(self):
        user = get_user(post_score_limit_operator=LimitOperator.NO_LIMIT,
                        post_score_limit=1000)
        submission = MockPrawSubmission(score=2000)
        f = self.sub_filter.score_filter(submission, user)
        self.assertTrue(f)

        submission.score = 500
        self.assertTrue(self.sub_filter.score_filter(submission, user))
    def test_score_filter_less_than(self):
        user = get_user(post_score_limit_operator=LimitOperator.LESS_THAN,
                        post_score_limit=1000)
        submission = MockPrawSubmission(score=500)
        self.assertTrue(self.sub_filter.score_filter(submission, user))

        submission.score = 1000
        self.assertTrue(self.sub_filter.score_filter(submission, user))

        submission.score = 2000
        self.assertFalse(self.sub_filter.score_filter(submission, user))
Пример #7
0
    def test_get_submissions_with_old_stickied_posts(self, get_raw_submissions, reddit_utils):
        user = get_user(absolute_date_limit=self.now - timedelta(days=10))
        mock_submissions = []
        for x in range(2):
            mock_submissions.append(MockPrawSubmission(created=self.now - timedelta(days=100), stickied=True))
        for x in range(2, 20):
            mock_submissions.append(MockPrawSubmission(created=self.now - timedelta(days=x)))
        get_raw_submissions.return_value = self.submission_generator(mock_submissions)
        self.assertEqual(20, len(mock_submissions))

        download_runner = DownloadRunner()
        submissions = download_runner.get_submissions(None, user)

        self.assertEqual(8, len(submissions))
        for sub in submissions:
            self.assertGreater(sub.created, user.absolute_date_limit.timestamp())
            self.assertFalse(sub.stickied)