Example #1
0
    def test_filter_keywords(self):
        TwitterConfig.get()['search']['filter']['blacklist']['enabled'] = True
        TwitterConfig.get()['search']['filter']['blacklist']['keywords'] = [
            'keyword'
        ]

        posts = {
            1: create_post(id=1, full_text='should be fine'),
            2: create_post(id=2, full_text='contains keyword'),
        }

        queue = PostQueue(posts)

        self.method.filter(queue)

        self.assertEqual(len(queue), 1)

        for post_id, post in queue.items():
            self.assertNotIn('keyword', post['full_text'])
Example #2
0
    def test_filter_users(self):
        TwitterConfig.get()['search']['filter']['blacklist']['enabled'] = True
        TwitterConfig.get()['search']['filter']['blacklist']['users'] = [
            'bad_user'
        ]

        posts = {
            1: create_post(id=1, screen_name='good_user'),
            2: create_post(id=2, screen_name='Bad_user'),
        }

        queue = PostQueue(posts)

        self.method.filter(queue)

        self.assertEqual(len(queue), 1)

        for post_id, post in queue.items():
            self.assertNotEqual('bad_user', post['user']['screen_name'])
Example #3
0
    def test_filter(self):
        TwitterConfig.get(
        )['search']['filter']['min_retweets']['enabled'] = True
        TwitterConfig.get()['search']['filter']['min_retweets']['number'] = 10

        posts = {
            1: create_post(id=1, retweets=1),
            2: create_post(id=2, retweets=5),
            3: create_post(id=3, retweets=15),
            4: create_post(id=4, retweets=20),
        }

        queue = PostQueue(posts)

        self.method.filter(queue)

        self.assertEqual(len(queue), 2)

        for post_id, post in queue.items():
            self.assertGreaterEqual(post['retweet_count'], 10)
Example #4
0
    def test_filter_keywords_empty(self):
        TwitterConfig.get()['search']['filter']['blacklist']['enabled'] = True
        TwitterConfig.get()['search']['filter']['blacklist']['keywords'] = []

        posts = {
            1: create_post(id=1, full_text='should be fine'),
            2: create_post(id=2, full_text='contains keyword'),
        }
        queue = PostQueue(posts)

        self.method.filter(queue)

        self.assertEqual(len(queue), 2)
Example #5
0
    def test_get_age_rate(self):
        posts = {
            1: create_post(id=1, date='Thu Oct 08 08:34:51 +0000 2015'),
            2: create_post(id=2, date='Thu Oct 07 08:34:51 +0000 2015'),
            3: create_post(id=3, date='Thu Oct 06 08:34:51 +0000 2015'),
            4: create_post(id=4, date='Thu Oct 05 08:34:51 +0000 2015'),
        }

        queue = PostQueue(posts)

        rates = self.method.get_rating(queue)
        rates = {x.id: x.score for x in rates}
        self.assertGreater(rates[1], rates[2])
        self.assertGreater(rates[2], rates[3])
        self.assertGreater(rates[3], rates[4])
Example #6
0
    def test_get_keywords_rate(self):
        TwitterConfig.get()['search']['sort']['by_keywords']['enabled'] = True
        TwitterConfig.get()['search']['sort']['by_keywords']['keywords'] = [
            "Test"
        ]

        posts = {
            1: create_post(id=1, full_text="Test"),
            2: create_post(id=2, full_text="test"),
            3: create_post(id=3, full_text="norate"),
            4: create_post(id=4, full_text="test test"),
        }

        queue = PostQueue(posts)

        rates = self.method.get_rating(queue)

        rates = {x.id: x.score for x in rates}
        self.assertEqual(rates[1], rates[2])
        self.assertLess(rates[3], rates[2])
        self.assertGreater(rates[4], rates[2])
Example #7
0
    def test_get_retweets_rate(self):
        TwitterConfig.get(
        )['search']['sort']['by_retweets_count']['enabled'] = True

        posts = {}
        for _ in range(10):
            post = create_post()
            posts[post['id']] = post

        queue = PostQueue(posts)
        rates = self.method.get_rating(queue)

        self.assertEqual(len(rates), len(posts))

        sorted_rates = sorted(((x.id, x.score) for x in rates),
                              key=lambda x: x[1],
                              reverse=True)

        previous = sorted_rates.pop(0)[0]
        for id, rate in sorted_rates:
            self.assertLessEqual(posts[id]['retweet_count'],
                                 posts[previous]['retweet_count'])
            previous = id