Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
 def test_get_post_valid(self):
     post = Post.get_post(1)
     self.assertIsNotNone(post)
Beispiel #4
0
 def test_get_post_not_exist(self):
     post = Post.get_post(122)
     self.assertIsNone(post)
Beispiel #5
0
 def test_get_post_with_string_id(self):
     try:
         post = Post.get_post("abc")
         self.fail("Expect InvalidFieldError")
     except InvalidFieldError:
         pass
Beispiel #6
0
 def test_get_post_with_negative_id(self):
     try:
         post = Post.get_post(-1)
         self.fail("Expect InvalidFieldError")
     except InvalidFieldError:
         pass