Example #1
0
    def test_check_new_mentions(self):
        posts = [create_post()]
        self.bot.client.get_mentions_timeline = MagicMock(return_value=posts)
        self.bot.last_mention = create_post()
        last_id = self.bot.last_mention['id']

        self.bot.check_new_mentions()

        self.bot.client.get_mentions_timeline.assert_called_once_with(since_id=last_id)
        self.assertEqual(self.bot.last_mention, posts[0])
        self.assertTrue(NotficationService.return_value.send_notification.called)
    def test_get_age_score(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'),
        }

        scores = get_age_score(posts)
        scores = {x.id: x.score for x in scores}
        self.assertGreater(scores[1], scores[2])
        self.assertGreater(scores[2], scores[3])
        self.assertGreater(scores[3], scores[4])
Example #3
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 #4
0
    def test_check_new_mentions(self):
        posts = [create_post()]
        self.bot.client.get_mentions_timeline = MagicMock(return_value=posts)
        self.bot.last_mention = create_post()
        last_id = self.bot.last_mention['id']

        self.bot.check_new_mentions()

        self.bot.client.get_mentions_timeline.assert_called_once_with(
            since_id=last_id)
        self.assertEqual(self.bot.last_mention, posts[0])
        self.assertTrue(
            NotficationService.return_value.send_notification.called)
Example #5
0
    def test_get_age_score(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'),
        }

        scores = get_age_score(posts)
        scores = {x.id: x.score for x in scores}
        self.assertGreater(scores[1], scores[2])
        self.assertGreater(scores[2], scores[3])
        self.assertGreater(scores[3], scores[4])
    def test_get_keywords_score(self):
        Config.priority_keywords = "Test"
        posts = {
            1: create_post(id=1, text="Test"),
            2: create_post(id=2, text="test"),
            3: create_post(id=3, text="noscore"),
            4: create_post(id=4, text="test test"),
        }

        scores = get_keywords_score(posts)
        scores = {x.id: x.score for x in scores}
        self.assertEqual(scores[1], scores[2])
        self.assertLess(scores[3], scores[2])
        self.assertGreater(scores[4], scores[2])
Example #7
0
    def test_get_keywords_score(self):
        Config.priority_keywords = "Test"
        posts = {
            1: create_post(id=1, text="Test"),
            2: create_post(id=2, text="test"),
            3: create_post(id=3, text="noscore"),
            4: create_post(id=4, text="test test"),
        }

        scores = get_keywords_score(posts)
        scores = {x.id: x.score for x in scores}
        self.assertEqual(scores[1], scores[2])
        self.assertLess(scores[3], scores[2])
        self.assertGreater(scores[4], scores[2])
Example #8
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 #9
0
    def test_check_new_mentions_empty(self):
        posts = [create_post()]
        self.bot.client.get_mentions_timeline = MagicMock(return_value=posts)

        self.bot.check_new_mentions()

        self.bot.client.get_mentions_timeline.assert_called_once_with(count=1)
        self.assertEqual(self.bot.last_mention, posts[0])
Example #10
0
    def test_check_new_mentions_empty(self):
        posts = [create_post()]
        self.bot.client.get_mentions_timeline = MagicMock(return_value=posts)

        self.bot.check_new_mentions()

        self.bot.client.get_mentions_timeline.assert_called_once_with(count=1)
        self.assertEqual(self.bot.last_mention, posts[0])
Example #11
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 #12
0
    def test_sort_queue(self):
        posts = dict()
        for i in range(10):
            post = create_post()
            posts[post['id']] = post

        sorted = post_queue_sort(posts)
        key, previous = sorted.popitem(last=False)
        for post in sorted.values():
            self.assertLessEqual(post['score'], previous['score'])
Example #13
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 #14
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 #15
0
    def test_sort_queue(self):
        posts = dict()
        for i in range(10):
            post = create_post()
            posts[post['id']] = post


        sorted = post_queue_sort(posts)
        key, previous = sorted.popitem(last=False)
        for post in sorted.values():
            self.assertLessEqual(post['score'], previous['score'])
Example #16
0
    def test_sort_queue_len_1(self):
        """If less than 2, raises StatisticsError('variance requires at least two data points')"""
        post = create_post()
        posts = {post['id']: post}
        queue = PostQueue(posts)

        queue.sort()

        key, previous = queue.popitem(last=False)
        for post in queue.values():
            self.assertLessEqual(post['score'], previous['score'])
Example #17
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 #18
0
    def test_sort_queue(self):
        posts = {}
        for _ in range(10):
            post = create_post()
            posts[post['id']] = post

        queue = PostQueue(posts)

        queue.sort()

        key, previous = queue.popitem(last=False)
        for post in queue.values():
            self.assertLessEqual(post['score'], previous['score'])
Example #19
0
    def test_filter_queue(self):
        TwitterConfig.get()['search']['filter']['min_retweets']['enabled'] = True
        TwitterConfig.get()['search']['filter']['min_retweets']['number'] = 5

        posts = dict()
        for i in range(10):
            post = create_post(retweets=i)
            posts[post['id']] = post

        queue = PostQueue(posts)

        queue.filter()
        for post in queue.values():
            self.assertGreaterEqual(post['retweet_count'], 5)
Example #20
0
    def test_get_retweets_score(self):
        posts = dict()
        for i in range(10):
            post = create_post()
            posts[post['id']] = post


        scores = get_retweets_score(posts)

        self.assertEqual(len(scores), len(posts))
        sorted_scores = sorted(((x.id, x.score) for x in scores), key=lambda x: x[1], reverse=True)
        previous = sorted_scores.pop(0)[0]
        for id, score in sorted_scores:
            self.assertLessEqual(posts[id]['retweet_count'], posts[previous]['retweet_count'])
            previous = id
Example #21
0
    def test_get_retweets_score(self):
        posts = dict()
        for i in range(10):
            post = create_post()
            posts[post['id']] = post

        scores = get_retweets_score(posts)

        self.assertEqual(len(scores), len(posts))
        sorted_scores = sorted(((x.id, x.score) for x in scores),
                               key=lambda x: x[1],
                               reverse=True)
        previous = sorted_scores.pop(0)[0]
        for id, score in sorted_scores:
            self.assertLessEqual(posts[id]['retweet_count'],
                                 posts[previous]['retweet_count'])
            previous = id
Example #22
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