Ejemplo n.º 1
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")
Ejemplo n.º 2
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')
Ejemplo n.º 3
0
    def test_create_blog_entry_with_existing_title(self):
        """BlogEntity.register should fail with a non-unique title."""
        james = UserEntity.register(username='******', password='******')

        BlogEntity.create_blog_entry(parent=blog_key(),
                                     title='a',
                                     article='content',
                                     created_by=james)
        self.assertRaises(
            myExceptions.NotUnique,
            BlogEntity.create_blog_entry,
            parent=blog_key(),
            title='a',
            article='content',
            created_by=james,
        )
Ejemplo n.º 4
0
    def test_delete_post_wrong_user(self):
        """delete_post should raise error if wrong user attempts to del it."""
        james = UserEntity.register(username='******', password='******')
        kimmy = UserEntity.register(username='******', password='******')

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

        self.assertRaises(myExceptions.EditOthersPosts, a.delete_post, kimmy)
Ejemplo n.º 5
0
    def test_create_blog_entry(self):
        """."""
        james = UserEntity.register(username='******', password='******')

        self.assertEqual(type(
            BlogEntity.create_blog_entry(parent=blog_key(),
                                         title='a',
                                         article='content',
                                         created_by=james)),
                         BlogEntity,
                         msg="'create_blog_entry' should return a BlogEntity")
Ejemplo n.º 6
0
    def test_blog_add_comment(self):
        """.add_comment should return a CommentEnity if valid"""
        james = UserEntity.register(username='******', password='******')

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

        self.assertEqual(
            type(a.add_comment(commentBy=james, comment='Awesome')),
            CommentsEntity)
Ejemplo n.º 7
0
    def test_edit_blog_entry_check_data(self):
        """edit_blog_post should fail if using a title from different post."""
        james = UserEntity.register(username='******', password='******')

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

        a.edit_blog_entry(title='abc', article='123', created_by=james)
        self.assertEqual(a.title, 'abc', msg=None)
        self.assertEqual(a.article, '123', msg=None)
Ejemplo n.º 8
0
    def test_edit_blog_entry_with_existing_title(self):
        """edit_blog_post should fail if using a title from different post."""
        james = UserEntity.register(username='******', password='******')

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

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

        self.assertRaises(
            myExceptions.NotUnique,
            a.edit_blog_entry,
            title='b',
            article='contents',
            created_by=james,
        )
Ejemplo n.º 9
0
    def test_blog_vote_on_own_post_fail(self):
        """user cannot vote on own post"""
        james = UserEntity.register(username='******', password='******')

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

        self.assertRaises(myExceptions.VoteOnOwnPostNotAllowed,
                          a.vote,
                          voteBy=james,
                          voteType='up')
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
    def test_edit_blog_entry_wrong_user(self):
        """edit_blog_post should fail if using a title from different post."""
        james = UserEntity.register(username='******', password='******')
        jimmy = UserEntity.register(username='******', password='******')

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

        self.assertRaises(
            myExceptions.EditOthersPosts,
            a.edit_blog_entry,
            title='a',
            article='contents',
            created_by=jimmy,
        )
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
    def test_blog_vote_on_others_post(self):
        """user should be able to vote on other posts"""
        james = UserEntity.register(username='******', password='******')
        john = UserEntity.register(username='******', password='******')
        jimbo = UserEntity.register(username='******', password='******')
        jake = UserEntity.register(username='******', password='******')
        jonas = UserEntity.register(username='******', password='******')

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

        a.vote(voteBy=john, voteType='up')
        a.vote(voteBy=jimbo, voteType='down')
        a.vote(voteBy=jake, voteType='up')
        a.vote(voteBy=jonas, voteType='up')

        self.assertEqual(
            a.getVotes(), {
                'up': 3,
                'down': 1
            },
            msg=
            "'getvotes' should return a dict with keyword 'up' and 'down, here with values 3 and 1'"
        )  # noqa

        self.assertEqual(a.getVotesFromUser(john),
                         'up',
                         msg="'voting 'up' should set the vote to 'up'")

        a.vote(voteBy=john, voteType='up')
        self.assertEqual(a.getVotesFromUser(john),
                         None,
                         msg="'Voting 'up' twice should remove the vote")

        self.assertEqual(a.getVotesFromUser(jimbo),
                         'down',
                         msg="'voting 'down' should set the vote to 'down'")

        a.vote(voteBy=jimbo, voteType='down')
        self.assertEqual(a.getVotesFromUser(jimbo),
                         None,
                         msg="'Voting 'down' twice should remove the vote")
Ejemplo n.º 14
0
    def test_blog_get_comments(self):
        """.get_comment should return a list of all CommentEnities on a post"""
        james = UserEntity.register(username='******', password='******')

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

        a.add_comment(commentBy=james, comment='test')

        self.assertEqual(
            type(a.get_comments()[0]),
            CommentsEntity,
            msg="'get_comments should return a query of CommentsEntity'")

        self.assertEqual(a.get_comments().count(), 1)

        self.assertEqual(a.get_comments()[0].comment, 'test')
Ejemplo n.º 15
0
    def test_blog_get_by(self):
        """get_by_id_str and by_title should return the correct BlogEntity"""
        james = UserEntity.register(username='******', password='******')

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

        a_id = str(a.key().id())

        self.assertEqual(BlogEntity.get_by_id_str(a_id).key().id(),
                         a.key().id(),
                         msg="'by_title' should return the 'a'-blog_entry")

        self.assertEqual(
            BlogEntity.by_title('a title').key().id(),
            a.key().id(),
            msg="'get_by_id_str' should return the 'a'-blog_entry")
Ejemplo n.º 16
0
 def post(self):
     """Create a blog-entry if logged in and form filled out correcly."""
     if not self.user:
         self.redirect('/login')
     else:
         title = self.request.get("title").strip()
         article = self.request.get("article")
         if title and article and self.user:
             try:
                 a = BlogEntity.create_blog_entry(parent=blog_key(),
                                                  created_by=self.user,
                                                  title=title,
                                                  article=article)
                 self.redirect('/blogs/%s' % str(a.key().id()))
             except myExceptions.NotUnique:
                 self.render_this(title=title,
                                  article=article,
                                  error_notUnique=True)
         else:
             self.render_this(title=title,
                              article=article,
                              error_missing_fields=True)
Ejemplo n.º 17
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)