本文整理汇总了Python中business.post.Post类的典型用法代码示例。如果您正苦于以下问题:Python Post类的具体用法?Python Post怎么用?Python Post使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Post类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_post_with_not_exist_author
def test_find_post_with_not_exist_author(self):
try:
Post.find_post_by_author_pagination(10, 4, 7)
self.fail("Expect UserNotFoundError")
except UserNotFoundError:
pass
示例2: test_find_post_with_invalid_categories
def test_find_post_with_invalid_categories(self):
try:
Post.find_post_by_keyword("")
self.fail("Expect InvalidFieldError")
except InvalidFieldError:
pass
示例3: test_find_post_with_invalid_author_id
def test_find_post_with_invalid_author_id(self):
try:
Post.find_post_by_author_pagination("abc")
self.fail("Expect InvalidFieldError")
except InvalidFieldError:
pass
示例4: test_delete_post_by_manager
def test_delete_post_by_manager(self):
args = {
"user_id": 1,
"post_id": 2
}
Post.delete_post(**args)
post = DBPost.get_by_id(2)
self.assertIsNone(post)
示例5: test_delete_post_all_field_valid
def test_delete_post_all_field_valid(self):
args = {
"user_id": 1,
"post_id": 1
}
Post.delete_post(**args)
post = DBPost.get_by_id(1)
self.assertIsNone(post)
示例6: test_delete_not_exist_post
def test_delete_not_exist_post(self):
args = {
"user_id": 2,
"post_id": 100
}
try:
Post.delete_post(**args)
self.fail("Expect PostNotFoundError")
except PostNotFoundError:
pass
示例7: test_add_post_without_content
def test_add_post_without_content(self):
args = {
"user_id": 2,
"title": "Hello",
"content": "",
}
try:
Post.add_post(**args)
self.fail("Expect InvalidFieldError")
except InvalidFieldError:
pass
示例8: test_delete_post_without_permission
def test_delete_post_without_permission(self):
"""
user who want to delete pos is not the author or manager
:return:
"""
args = {
"user_id": 2,
"post_id": 3
}
try:
Post.delete_post(**args)
self.fail("Expect AccessDeniedError")
except AccessDeniedError:
pass
示例9: show_single_post
def show_single_post(post_id):
try:
post = Post.get_post(post_id)
if post:
return render_template("single_post.html", post=post)
else:
abort(404)
except Exception as e:
abort(404)
示例10: edit_post
def edit_post(post_id):
try:
post = Post.get_post(post_id)
#only author can edit post
if post.author.id != current_user.id and current_user.role != "manager":
abort(403)
return render_template("add_post.html", post=post, categories=default.categories)
except Exception as e:
abort(404)
示例11: search_post_by_keyword
def search_post_by_keyword():
keyword = request.args["keyword"] or None
page = request.args.get("page", 1)
per_page = request.args.get("per_page", PER_PAGE)
try:
pagination = Post.find_post_by_keyword_pagination(keyword, page, per_page)
return render_template("search_result.html", pagination=pagination, keyword=keyword, menu_items=default.categories)
except Exception as e:
abort(400)
示例12: add_post
def add_post():
try:
args={
"user_id": current_user.id,
"title":request.form["title"] or None,
"content": request.form["content"] or None,
"categories": request.form.getlist("categories") or None,
"tags": request.form["tags"] or None,
"feature_image":request.form["feature_image"] or None,
}
post = Post.add_post(**args)
return redirect(url_for('post', post_id=post.id))
except:
abort(400)
示例13: update_post
def update_post():
args={
"user_id": current_user.id,
"post_id": request.form["post_id"] or None,
"title":request.form["title"] or None,
"content": request.form["content"] or None,
"categories": request.form.getlist("categories") or None,
"tags": request.form["tags"] or None,
"feature_image":request.form["feature_image"] or None,
}
try:
post = Post.update_post(**args)
return render_template("add_post.html", post=post, categories=default.categories)
except AccessDeniedError:
abort(403)
except Exception as e:
abort(400)
示例14: test_add_post_without_title
def test_add_post_without_title(self):
args ={
"user_id": 2,
"title": "",
"content": "<p>Sed itaque dignissimos eligendi reprehenderit, nesciunt ducimus voluptates dolores suscipit fugit ipsam aperiam praesentium laborum odit qui libero ipsum tempora, eos quis hic, sapiente perspiciatis amet labore voluptatibus alias. Vitae.</p>",
"feature_image":"http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg",
"tags": "wallpaper, nature",
"categories":"Uncategorized",
"draft": True,
}
p = Post.add_post(**args)
self.assertIsNotNone(p)
post = DBPost.get_by_id(p.id)
self.assertEqual(post.user_id, args["user_id"])
self.assertGreater(len(post.title), 0)
self.assertEqual(post.content, args["content"])
self.assertEqual(post.feature_image, args["feature_image"])
self.assertEqual(post.tags, args["tags"])
self.assertEqual(post.categories, args["categories"])
示例15: test_get_post_with_negative_id
def test_get_post_with_negative_id(self):
try:
post = Post.get_post(-1)
self.fail("Expect InvalidFieldError")
except InvalidFieldError:
pass