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


Python Post.add_post方法代码示例

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


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

示例1: test_add_post_to_followers_news

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import add_post [as 别名]
    def test_add_post_to_followers_news(self):
        users = self._mass_test_follow()

        Post.add_post(users[1].id, "Test message!")

        self.assertEqual('1', users[0].get_news(0, -1)[0]['id'])
        self.assertEqual('1', users[2].get_news(0, -1)[0]['id'])
        self.assertEqual('1', users[3].get_news(0, -1)[0]['id'])
开发者ID:georgyturevich,项目名称:django_retwis,代码行数:10,代码来源:tests.py

示例2: test_get_news

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import add_post [as 别名]
    def test_get_news(self):
        users = self._mass_test_follow()

        data = [
            [users[1].id, 'Test message 1!'],
            [users[1].id, 'Test message 2!'],
            [users[1].id, 'Test message 3!'],
            [users[2].id, 'Test message 1!'],
            [users[2].id, 'Test message 2!']
        ]

        for i, (test_user_id, test_status) in enumerate(data):
            Post.add_post(test_user_id, test_status)

        self.assertEqual(5, len(users[0].get_news(0, -1)))
        self.assertEqual(3, len(users[1].get_news(0, -1)))
        self.assertEqual(5, len(users[2].get_news(0, -1)))
        self.assertEqual(5, len(users[3].get_news(0, -1)))
开发者ID:georgyturevich,项目名称:django_retwis,代码行数:20,代码来源:tests.py

示例3: test_get_posts

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import add_post [as 别名]
    def test_get_posts(self):
        users = self._create_test_users()

        data = [
            [users[0].id, 'Test message 1!'],
            [users[0].id, 'Test message 2!'],
            [users[0].id, 'Test message 3!']
        ]

        for i, (test_user_id, test_status) in enumerate(data):
            Post.add_post(test_user_id, test_status)

        posts = users[0].get_posts(0, -1)

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

        for i, post in enumerate(reversed(posts)):
            self.assertEqual(data[i][0], post['user'].id)
            self.assertEqual(data[i][1], post['status'])
开发者ID:georgyturevich,项目名称:django_retwis,代码行数:21,代码来源:tests.py

示例4: run_scraper

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import add_post [as 别名]
def run_scraper():
    try:
        fetch_time = datetime.datetime.now()
        post_dicts = fetch_posts(from_page_num=1, to_page_num=3)
        post_dicts.sort(key=lambda p: p['id'])
        
        for post_dict in post_dicts:
            print post_dict['id'], post_dict['title'].encode('utf-8')
            Post.add_post(id=post_dict['id'],
                          post_type=post_dict['post_type'],
                          by=post_dict['by'],
                          created_at=post_dict['created_at'],
                          url=post_dict['url'],
                          rank_when_fetched=post_dict['rank'],
                          score=post_dict['score'],
                          comment_count=post_dict['comment_count'],
                          title=post_dict['title'],
                          last_fetch_at=fetch_time
                          )
    except Exception as e:
        report_error(e, raise_again=False)
        raise app_exceptions.ScraperError("Something went wrong with the scraper, error has been reported.")
开发者ID:shshank,项目名称:hackernews_chrono,代码行数:24,代码来源:runner.py

示例5: save

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import add_post [as 别名]
    def save(self, request):
        if not request.user.id:
            return

        Post.add_post(request.user.id, self.cleaned_data['status'])
开发者ID:georgyturevich,项目名称:django_retwis,代码行数:7,代码来源:forms.py


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