def test_scan_new_contests_with_language(self): TwitterConfig.get()['search']['queries'] = [OrderedDict()] TwitterConfig.get()['search']['queries'][0]['test1'] = None TwitterConfig.get()['search']['queries'][0]['lang'] = 'el' posts = list() for i in range(2): posts.append({ 'id': i, 'full_text': 'test', 'retweet_count': 1, 'user': { 'id': random.randint(1, 1000), 'screen_name': 'test' }, 'retweeted': False, 'created_at': 'Thu Oct 08 08:34:51 +0000 2015' }) self.bot.client = MagicMock() self.bot.client.search_tweets.return_value = posts self.bot.scan_new_contests() self.bot.client.search_tweets.assert_called_once_with('test1', 50, language='el') self.assertEqual(len(self.bot.post_queue), 2)
def test_clear_queue_full(self): TwitterConfig.get()['search']['max_queue'] = 60 self.bot.post_queue = MagicMock() self.bot.post_queue.__len__.return_value = TwitterConfig.get( )['search']['max_queue'] + 1 self.bot.clear_queue() self.assertTrue(self.bot.post_queue.popitem.called) self.bot.post_queue.popitem.assert_called_with()
def test_enter_contest_skip_already_retweeted(self): TwitterConfig.get()['search']['skip_retweeted'] = True posts = 10 self.bot.ignore_list = list() for i in range(posts): self.bot.post_queue[i] = { 'id': i, 'full_text': 'test', 'score': 0, 'user': { 'id': random.randint(1, 1000) }, 'retweeted': True } self.bot.post_queue[9]['retweeted'] = False queue_copy = self.bot.post_queue.copy() self.bot.client.get_tweet = lambda x: queue_copy[x] self.bot.enter_contest() self.assertEqual(len(self.bot.post_queue), 0) self.assertTrue(self.bot.client.retweet.called) self.bot.client.retweet.assert_called_with(9) self.assertListEqual([x for x in range(10)], self.bot.ignore_list)
def test_load_values(self): load_fixture_config() # Global settings self.assertEqual(TwitterConfig.get().consumer_key, "test") self.assertEqual(TwitterConfig.get().consumer_secret, "test") self.assertEqual(TwitterConfig.get().access_token_key, "test") self.assertEqual(TwitterConfig.get().access_token_secret, "test") self.assertEqual(TwitterConfig.get().min_ratelimit_percent, 10) # Search settings self.assertIsInstance(TwitterConfig.get().search.queries, list) self.assertEqual(len(TwitterConfig.get().search.queries), 3) self.assertEqual(TwitterConfig.get().search.queries[0], "test1") self.assertEqual(TwitterConfig.get().search.queries[1], "test2") self.assertIsInstance(TwitterConfig.get().search.queries[2], OrderedDict) self.assertIn("test3", TwitterConfig.get().search.queries[2]) self.assertIn("lang", TwitterConfig.get().search.queries[2]) self.assertEqual(TwitterConfig.get().search.queries[2]["test3"], None) self.assertEqual(TwitterConfig.get().search.queries[2]["lang"], "el") self.assertEqual(TwitterConfig.get().search.max_queue, 100) self.assertEqual(TwitterConfig.get().search.max_quote_depth, 20) self.assertEqual(TwitterConfig.get().search.min_quote_similarity, 0.5) # Filter self.assertEqual(TwitterConfig.get().search.filter.min_retweets.enabled, False) self.assertEqual(TwitterConfig.get().search.filter.min_retweets.number, 20) # Sort self.assertEqual(TwitterConfig.get().search.sort.by_keywords.enabled, True) self.assertEqual(TwitterConfig.get().search.sort.by_keywords.keywords, ["ps4", "pc"]) # Actions self.assertEqual(TwitterConfig.get().actions.follow.enabled, True) self.assertEqual(TwitterConfig.get().actions.follow.multiple, False) self.assertEqual(TwitterConfig.get().actions.follow.keywords, ["follow", "follower"]) self.assertEqual(TwitterConfig.get().actions.follow.max_following, 1950) self.assertEqual(TwitterConfig.get().actions.favorite.enabled, True) self.assertEqual(TwitterConfig.get().actions.favorite.keywords, ["fav", "favorite"]) self.assertEqual(TwitterConfig.get().actions.tag_friend.enabled, True) self.assertEqual(TwitterConfig.get().actions.tag_friend.friends, ["friend1", "friend2", "friend3"]) self.assertEqual(TwitterConfig.get().actions.tag_friend.friend_keywords, ["friend", "friends"]) self.assertEqual(TwitterConfig.get().actions.tag_friend.tag_keywords, ["tag"]) # Scheduler self.assertEqual(TwitterConfig.get().scheduler.search_interval, 5400) self.assertEqual(TwitterConfig.get().scheduler.retweet_interval, 600) self.assertEqual(TwitterConfig.get().scheduler.retweet_random_margin, 60) self.assertEqual(TwitterConfig.get().scheduler.blocked_users_update_interval, 300) self.assertEqual(TwitterConfig.get().scheduler.clear_queue_interval, 60) self.assertEqual(TwitterConfig.get().scheduler.rate_limit_update_interval, 60) self.assertEqual(TwitterConfig.get().scheduler.check_mentions_interval, 600)
def test_clear_queue_empty(self): TwitterConfig.get()['search']['max_queue'] = 60 self.bot.post_queue = MagicMock() self.bot.post_queue.__len__.return_value = 0 self.bot.clear_queue() self.assertFalse(self.bot.post_queue.popitem.called)