示例#1
0
    def test_update_data(self, mock_get_base):
        """
        # start_dateよりも古いツイートを取得できないかのテストはまだかけていない
        tweet_idが1〜50のものを持っている状態で、更新データとして、tweet_idが1〜100の
        ツイートを取得したときのテスト
        """
        mock_get_base.side_effect = response_data_mock

        ja_tz = timezone('Asia/Tokyo')
        start_time = datetime(2020, 4, 1, tzinfo=ja_tz)
        twitter_user = factory.TwitterUserFactory(content=self.content)
        for tweet_id in range(0, 50):
            tweet = factory.TweetFactory(twitter_user=twitter_user,
                                         tweet_id=str(tweet_id),
                                         tweet_date=start_time)
            factory.TweetCountFactory(tweet=tweet,
                                      retweet_count=10,
                                      favorite_count=10)
        twitter_user.loads_tweet()
        before_tweet_count = twitter_user.tweet_set.all().count()

        TwitterApi().update_data(self.content)

        updated_twitter_user = TwitterUser.objects.get(pk=twitter_user.pk)
        after_tweet_count = updated_twitter_user.tweet_set.all().count()
        updated_tweet = updated_twitter_user.tweet_set.get(tweet_id=1)
        self.assertNotEqual(twitter_user.name, updated_twitter_user.name)
        self.assertEqual(updated_twitter_user.all_tweet_count,
                         after_tweet_count)
        self.assertGreater(after_tweet_count, before_tweet_count)
        self.assertGreater(updated_twitter_user.all_retweet_count, 500)
        self.assertGreater(updated_twitter_user.all_favorite_count, 500)
        self.assertEqual(updated_tweet.tweetcount_set.all().count(), 2)
示例#2
0
    def test_has_tweets_no_twitter_and_only_twitter_user(self):
        content = factory.ContentFactory()

        self.assertFalse(content.has_tweets())

        factory.TwitterUserFactory(content=content)

        self.assertTrue(content.has_tweets())
示例#3
0
 def create_content_twitter_tweet_tweetcount(category, retweet=10):
     content = factory.ContentFactory(category=category)
     twitter_user = factory.TwitterUserFactory(content=content)
     for num in range(50):
         tweet = factory.TweetFactory(twitter_user=twitter_user)
         factory.TweetCountFactory(tweet=tweet,
                                   retweet_count=retweet,
                                   favorite_count=20)
     twitter_user.loads_tweet()
     return content
示例#4
0
    def test_appraise(self):
        content = factory.ContentFactory()
        twitter_user = factory.TwitterUserFactory(content=content)
        for num in range(50):
            tweet = factory.TweetFactory(tweet_id=str(num),
                                         twitter_user=twitter_user)
            factory.TweetCountFactory(tweet=tweet,
                                      retweet_count=10,
                                      favorite_count=20)
        twitter_user.loads_tweet()

        self.assertEqual(content.appraise(), 0.40)
示例#5
0
    def test_has_tweets(self):
        content = factory.ContentFactory()
        twitter_user = factory.TwitterUserFactory(content=content)
        factory.TweetFactory(twitter_user=twitter_user, tweet_id='1')

        self.assertTrue(content.has_tweets())
示例#6
0
 def setUp(self):
     self.twitter_user = factory.TwitterUserFactory()