当前位置: 首页>>代码示例>>Python>>正文


Python Tweet.create_from_json方法代码示例

本文整理汇总了Python中models.Tweet.create_from_json方法的典型用法代码示例。如果您正苦于以下问题:Python Tweet.create_from_json方法的具体用法?Python Tweet.create_from_json怎么用?Python Tweet.create_from_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Tweet的用法示例。


在下文中一共展示了Tweet.create_from_json方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_from_json_example0

# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import create_from_json [as 别名]
    def test_create_from_json_example0(self):
        """
        create_from_json() should return a Tweet object with
        the fields set to their proper values.
        """

        # Iterates through the test data below and checks that all the fields match up.
        # The test data is a set of raw JSON text from the Twitter api and documentation,
        # along with corresponding manually-extracted data.
        for idx, body in enumerate(example_tweet_bodies):
            data = example_data[idx]

            raw_tweet = json.loads(body)
            tweet = Tweet.create_from_json(raw_tweet)
            self.assertIsInstance(tweet, Tweet)

            # check for model validity
            tweet.clean_fields()

            self.assertEqual(tweet.tweet_id, data['tweet_id'], 'tweet_id matches')
            self.assertEqual(tweet.text, data['text'], 'text matches')
            self.assertEqual(tweet.truncated, data['truncated'], 'truncated matches')
            self.assertEqual(tweet.lang, data['lang'], 'lang matches')

            # Basic user info
            self.assertEqual(tweet.user_id, data['user_id'], 'user_id matches')
            self.assertEqual(tweet.user_screen_name, data['user_screen_name'], 'user_screen_name matches')
            self.assertEqual(tweet.user_name, data['user_name'], 'user_name matches')
            self.assertEqual(tweet.user_verified, data['user_verified'], 'user_verified matches')

            # Timing parameters
            # May need to convert the date depending on timezone settings
            if settings.USE_TZ:
                data['created_at'] = timezone.make_aware(data['created_at'], timezone.get_current_timezone())
            self.assertEqual(tweet.created_at, data['created_at'], 'created_at matches')
            self.assertEqual(tweet.user_utc_offset, data['user_utc_offset'], 'user_utc_offset matches')
            self.assertEqual(tweet.user_time_zone, data['user_time_zone'], 'user_time_zone matches')

            # none, low, or medium
            self.assertEqual(tweet.filter_level, data['filter_level'], 'filter_level matches')

            # Geo parameters
            self.assertEqual(tweet.latitude, data['latitude'], 'latitude matches')
            self.assertEqual(tweet.longitude, data['longitude'], 'longitude matches')
            self.assertEqual(tweet.user_geo_enabled, data['user_geo_enabled'], 'user_geo_enabled matches')
            self.assertEqual(tweet.user_location, data['user_location'], 'user_location matches')

            # Engagement - not likely to be very useful for streamed tweets but whatever
            self.assertEqual(tweet.favorite_count, data['favorite_count'], 'favorite_count matches')
            self.assertEqual(tweet.retweet_count, data['retweet_count'], 'retweet_count matches')
            self.assertEqual(tweet.user_followers_count, data['user_followers_count'], 'user_followers_count matches')
            self.assertEqual(tweet.user_friends_count, data['user_friends_count'], 'user_friends_count matches')

            # Relation to other tweets
            self.assertEqual(tweet.in_reply_to_status_id, data['in_reply_to_status_id'],
                             'in_reply_to_status_id matches')
            self.assertEqual(tweet.retweeted_status_id, data['retweeted_status_id'], 'retweeted_status_id matches')
开发者ID:michaelbrooks,项目名称:twitter-db,代码行数:59,代码来源:tests.py


注:本文中的models.Tweet.create_from_json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。