本文整理汇总了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'])
示例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)))
示例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'])
示例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.")
示例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'])