예제 #1
0
    def test_get_comments_on_post(self):
        """get_comments_on_post should return all comments on post."""
        james = UserEntity.register(username='******', password='******')

        a = BlogEntity.create_blog_entry(parent=blog_key(),
                                         title='a',
                                         article='content',
                                         created_by=james)

        c1 = CommentsEntity.comment_on_post(commentBy=james,
                                            commentOn=a,
                                            comment='abc')

        c2 = CommentsEntity.comment_on_post(commentBy=james,
                                            commentOn=a,
                                            comment='123')

        comments = CommentsEntity.get_comments_on_post(a)
        self.assertEqual(comments.count(), 2, msg='should return 2 comments')
        self.assertEqual(comments[0].comment,
                         c1.comment,
                         msg='should match first comment')
        self.assertEqual(comments[1].comment,
                         c2.comment,
                         msg='should match first comment')
예제 #2
0
    def test_get_by_id_str(self):
        """get_by_id_str should return the correct comment."""
        james = UserEntity.register(username='******', password='******')

        a = BlogEntity.create_blog_entry(parent=blog_key(),
                                         title='a',
                                         article='content',
                                         created_by=james)

        c = CommentsEntity.comment_on_post(commentBy=james,
                                           commentOn=a,
                                           comment='abc')

        comment_id = str(c.key().id())
        self.assertEqual(type(CommentsEntity.get_by_id_str(comment_id)),
                         CommentsEntity,
                         msg=None)
예제 #3
0
    def test_comment_on_post(self):
        """comment_on_post should return a CommentEntity."""
        james = UserEntity.register(username='******', password='******')

        a = BlogEntity.create_blog_entry(parent=blog_key(),
                                         title='a',
                                         article='content',
                                         created_by=james)

        self.assertEqual(
            type(
                CommentsEntity.comment_on_post(commentBy=james,
                                               commentOn=a,
                                               comment='abc')), CommentsEntity)
예제 #4
0
    def test_delete_post(self):
        """delete_post should delete the post and its comments and votes."""
        james = UserEntity.register(username='******', password='******')
        kimmy = UserEntity.register(username='******', password='******')
        dane = UserEntity.register(username='******', password='******')
        joe = UserEntity.register(username='******', password='******')

        a = BlogEntity.create_blog_entry(parent=blog_key(),
                                         title='a',
                                         article='content',
                                         created_by=james)

        b = BlogEntity.create_blog_entry(parent=blog_key(),
                                         title='b',
                                         article='content',
                                         created_by=james)

        a.vote(voteBy=kimmy, voteType='up')
        a.vote(voteBy=dane, voteType='up')
        a.vote(voteBy=joe, voteType='down')
        b.vote(voteBy=kimmy, voteType='up')
        b.vote(voteBy=dane, voteType='up')
        b.vote(voteBy=joe, voteType='down')

        a.add_comment(commentBy=kimmy, comment='abc')
        a.add_comment(commentBy=dane, comment='abc')
        a.add_comment(commentBy=joe, comment='123')
        b.add_comment(commentBy=kimmy, comment='abc')
        b.add_comment(commentBy=dane, comment='abc')
        b.add_comment(commentBy=joe, comment='123')

        a.delete_post(james)
        votes = VotesEntity.all()
        for vote in votes:
            self.assertNotEqual(vote.voteOn.title,
                                'a',
                                msg="Votes of post 'a' should be deleted")
        comments = CommentsEntity.all()
        for comment in comments:
            self.assertNotEqual(comment.commentOn.title,
                                'a',
                                msg="Comments of post 'a' should be deleted")

        bloe_entries = BlogEntity.all()
        for blog_entity in bloe_entries:
            self.assertNotEqual(blog_entity.title,
                                'a',
                                msg="Post 'a' should be deleted")
예제 #5
0
    def test_edit_comment(self):
        """edit_comment should return a comment with corrected text."""
        james = UserEntity.register(username='******', password='******')
        jane = UserEntity.register(username='******', password='******')

        a = BlogEntity.create_blog_entry(parent=blog_key(),
                                         title='a',
                                         article='content',
                                         created_by=james)

        c = CommentsEntity.comment_on_post(commentBy=james,
                                           commentOn=a,
                                           comment='abc')

        new_comment = '123'
        self.assertRaises(myExceptions.EditOthersComments,
                          c.edit_comment,
                          comment=new_comment,
                          commentBy=jane)

        self.assertEquals(
            c.edit_comment(comment=new_comment, commentBy=james).comment,
            new_comment)
예제 #6
0
    def blog_comment(self, comment, blog_entry, comment_id, delete_comment,
                     redirect):
        """Handle blog comments."""

        comment_entry = CommentsEntity.get_by_id_str(comment_id)

        if comment_entry and blog_entry:
            if comment_entry.commentOn.key().id() == blog_entry.key().id():
                if comment_entry.commentBy.key().id() == self.user.key().id():
                    if delete_comment:
                        # Delete comment
                        comment_entry.delete()
                    else:
                        # Edit comment
                        comment_entry.edit_comment(comment, self.user)
                    self.render("/thanks.html", redirect=redirect)
        elif blog_entry:
            # New comment
            try:
                blog_entry.add_comment(commentBy=self.user, comment=comment)
                self.render("/thanks.html", redirect=redirect)
            except myExceptions.TooShort as e:
                self.redirect("/error?errorType=TooShort&errorMsg=", e)
예제 #7
0
 def test_verify_comment(self):
     """Verify that the comment is valid."""
     self.assertTrue(CommentsEntity.verify_comment('abc'),
                     'should return true for okey output')
     self.assertFalse(CommentsEntity.verify_comment('ab'),
                      'should return false for too short output')