Esempio 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")
Esempio 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')
Esempio 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,
        )
Esempio 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)
Esempio 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")
Esempio n. 6
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,
        )
Esempio n. 7
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)
Esempio n. 8
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)
Esempio 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')
Esempio 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)
Esempio 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,
        )
Esempio 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)
Esempio n. 13
0
def dev_create_some_blog_posts(users):
    """Generator for random blog posts, for testing in development."""
    for i in range(1, 46):
        article = ""
        article += "<h3>{}</h3>".format(pick_random_from_list(title_list))
        for j in range(0, randint(4, 8)):
            if j > 0:
                if randint(0, 5) == 1:
                    article += "<h4>{}</h4>".format(
                        pick_random_from_list(title_list))
            article += "<p>{}</p>".format(
                pick_random_from_list(article_paragraphgs))
        a = BlogEntity(
            parent=blog_key(),
            created_by=users[randint(0, users.count() - 1)],
            title='{} {}'.format(i, pick_random_from_list(title_list)),
            article=article)
        a.put()
Esempio n. 14
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")
Esempio 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")
Esempio n. 16
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')
Esempio n. 17
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)
Esempio n. 18
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)