Exemplo n.º 1
0
    def test_delete_comment_by_post_author(self):
        args={
            "user_id": 2,
            "comment_id": 10,
        }

        Comment.delete_comment(**args)

        comment = DBComment.get_by_id(10)
        self.assertIsNone(comment)
Exemplo n.º 2
0
def delete_comment(comment_id):
    try:
        args = {
            "user_id" : current_user.id,
            "comment_id": comment_id
        }
        Comment.delete_comment(**args)
        return redirect(request.referrer)
    except Exception as e:
        abort(400)
Exemplo n.º 3
0
    def test_delete_comment_ideal_case(self):
        args={
            "user_id": 2,
            "comment_id": 1,
        }

        Comment.delete_comment(**args)

        comment = DBComment.get_by_id(1)
        self.assertIsNone(comment)
Exemplo n.º 4
0
    def test_delete_others_comment(self):
        args={
            "user_id": 2,
            "comment_id": 2,
        }

        try:
            Comment.delete_comment(**args)
            self.fail("Expect AccessDeniedError")
        except AccessDeniedError:
            pass
Exemplo n.º 5
0
    def test_delete_comment_with_not_exist_comment(self):
        args={
            "user_id": 2,
            "comment_id": 200,
        }

        try:
            Comment.delete_comment(**args)
            self.fail("Expect CommentNotFoundError")
        except CommentNotFoundError:
            pass
Exemplo n.º 6
0
    def test_delete_comment_invalid_comment_id(self):
        args={
            "user_id": 2,
            "comment_id": -2,
        }

        try:
            Comment.delete_comment(**args)
            self.fail("Expect InvalidFieldError")
        except InvalidFieldError:
            pass
Exemplo n.º 7
0
    def test_update_others_comment(self):
        args={
            "user_id": 2,
            "comment_id": 2,
            "content": "Hello world"
        }

        try:
            Comment.update_comment(**args)
            self.fail("Expect AccessDeniedError")
        except AccessDeniedError:
            pass
Exemplo n.º 8
0
    def test_update_comment_with_empty_comment(self):
        args={
            "user_id": 2,
            "comment_id": 1,
            "content": ""
        }

        try:
            Comment.update_comment(**args)
            self.fail("Expect InvalidFieldError")
        except InvalidFieldError:
            pass
Exemplo n.º 9
0
    def test_update_comment_with_not_exist_comment(self):
        args={
            "user_id": 2,
            "comment_id": 200,
            "content": "This is my first comment on this page"
        }

        try:
            Comment.update_comment(**args)
            self.fail("Expect CommentNotFoundError")
        except CommentNotFoundError:
            pass
Exemplo n.º 10
0
    def test_update_comment_invalid_comment_id(self):
        args={
            "user_id": 2,
            "comment_id": -2,
            "content": "This is my first comment on this page"
        }

        try:
            Comment.update_comment(**args)
            self.fail("Expect InvalidFieldError")
        except InvalidFieldError:
            pass
Exemplo n.º 11
0
    def test_add_comment_with_not_exist_post(self):
        args={
            "user_id": 1,
            "post_id": 200,
            "content": "This is my first comment on this page"
        }

        try:
            Comment.add_comment(**args)
            self.fail("Expect PostNotFoundError")
        except PostNotFoundError:
            pass
Exemplo n.º 12
0
def add_comment():
    args = {
        "post_id": request.form["post_id"] or None,
        "user_id": current_user.id,
        "content": request.form["comment"] or None,
    }

    try:
        Comment.add_comment(**args)
        if request.form["next"]:
            return redirect(request.form["next"])
        else:
            return redirect("/")
    except:
        abort(400)
Exemplo n.º 13
0
    def test_update_comment_ideal_case(self):
        args={
            "user_id": 2,
            "comment_id": 1,
            "content": "new comment content here"
        }

        cm = Comment.update_comment(**args)
        self.assertIsNotNone(cm)

        comment = DBComment.get_by_id(1)
        self.assertIsNotNone(comment)
        self.assertEqual(comment.user_id, args["user_id"])
        self.assertEqual(comment.content, args["content"])
Exemplo n.º 14
0
    def test_add_comment_ideal_case(self):
        args={
            "user_id": 1,
            "post_id": 2,
            "content": "This is my first comment on this page"
        }

        cm = Comment.add_comment(**args)
        self.assertIsNotNone(cm)

        comment = DBComment.get_by_id(cm.id)
        self.assertIsNotNone(comment)
        self.assertEqual(comment.user_id, args["user_id"])
        self.assertEqual(comment.post_id, args["post_id"])
        self.assertEqual(comment.content, args["content"])