def test_GetByStorageKey(self):
        blogpost = blogpost_model.Blogpost(self.author, self.headline,
                                           self.body)
        blogpost.put()

        result = blogpost_model.Blogpost.GetByStorageKey(blogpost.id)
        expected = blogpost

        self.assertEquals(result, expected)
    def test_GetAll(self):
        blogpost = blogpost_model.Blogpost(self.author, self.headline,
                                           self.body)
        blogpost.put()

        result = blogpost_model.Blogpost.GetAll()
        expected = [blogpost]

        self.assertEquals(result, expected)
    def test_Put(self):
        blogpost = blogpost_model.Blogpost(self.author, self.headline,
                                           self.body)
        blogpost.put()

        self.assertTrue(
            blogpost.id in blogpost_model.Blogpost.instances['Blogpost'])
        self.assertEquals(len(blogpost_model.Blogpost.instances['Blogpost']),
                          1)
    def test_GetComments_WithComments(self):
        blogpost = blogpost_model.Blogpost(self.author, self.headline,
                                           self.body)
        blogpost.AddComment(self.comment)

        result = blogpost.GetComments()
        expected = [self.comment]

        self.assertEquals(result, expected)
    def test_RemoveLabel_LabelNotFound(self):
        blogpost = blogpost_model.Blogpost(self.author, self.headline,
                                           self.body)

        self.assertTrue(self.label.label not in blogpost.labels)

        blogpost.RemoveLabel(self.label)

        self.assertTrue(self.label.label not in blogpost.labels)
    def test_AddLabel_MultipleLabels(self):
        blogpost = blogpost_model.Blogpost(self.author, self.headline,
                                           self.body)

        for label in self.GenerateLabels():
            blogpost.AddLabel(label)
            self.assertTrue(label.label in blogpost.labels)
            self.assertTrue(label.AddToBlogpost.called)

        self.assertEquals(len(blogpost.labels), 5)
    def test_RemoveComment_CommentFound(self):
        blogpost = blogpost_model.Blogpost(self.author, self.headline,
                                           self.body)
        blogpost.AddComment(self.comment)

        self.assertTrue(self.comment.id in blogpost.comments)

        blogpost.RemoveComment(self.comment)

        self.assertTrue(self.comment.id not in blogpost.comments)
    def test_Constructor(self):
        blogpost = blogpost_model.Blogpost(self.author, self.headline,
                                           self.body)

        self.assertTrue(self.author.AddBlogpost.called)
        self.assertEquals(self.headline, blogpost.headline)
        self.assertEquals(self.body, blogpost.body)
        self.assertIsInstance(blogpost.comments, OrderedDict)
        self.assertIsInstance(blogpost.labels, OrderedDict)
        self.assertIsNotNone(blogpost.created_timestamp)
        self.assertIsNotNone(blogpost.id)
    def test_RemoveLabel_LabelFound(self):
        blogpost = blogpost_model.Blogpost(self.author, self.headline,
                                           self.body)

        blogpost.AddLabel(self.label)

        self.assertTrue(self.label.label in blogpost.labels)

        blogpost.RemoveLabel(self.label)

        self.assertTrue(self.label.label not in blogpost.labels)
        self.assertTrue(self.label.RemoveFromBlogpost.called)
Esempio n. 10
0
    def SubmitBlogpost(self, username, headline, body):
        """Submits a blog post.

        Args:
          username: string; A string representation a post author's name.
          headline: string; A string representing the blog post's headline.
          body: string; A string representing the body of the blog post.

        Returns:
          A Blogpost instance with a nested Author instance.

        """
        author = self.GetOrInsertAuthor(username)

        post = blogpost_model.Blogpost(author, headline, body)
        post.put()

        return post
Esempio n. 11
0
    def test_ToJson_NoCommentsOrLabels(self):
        blogpost = blogpost_model.Blogpost(self.author, self.headline,
                                           self.body)
        self.author.ToJson.return_value = {
            'username': self.author,
            'id': self.author.id
        }

        result = blogpost.ToJson()

        self.assertTrue(self.author.ToJson.called)

        self.assertEquals(result['labels'], [])
        self.assertEquals(result['comments'], [])
        self.assertEquals(result['headline'], blogpost.headline)
        self.assertEquals(result['body'], blogpost.body)
        self.assertEquals(result['id'], blogpost.id)
        self.assertEquals(result['author'], self.author.ToJson.return_value)
        self.assertEquals(result['created_timestamp'],
                          str(blogpost.created_timestamp))
Esempio n. 12
0
    def test_AddComment(self):
        blogpost = blogpost_model.Blogpost(self.author, self.headline,
                                           self.body)
        blogpost.AddComment(self.comment)

        self.assertTrue(self.comment.id in blogpost.comments)
Esempio n. 13
0
 def test_GetLabels_NoLabels(self):
     blogpost = blogpost_model.Blogpost(self.author, self.headline,
                                        self.body)
     result = blogpost.GetLabels()
     expected = []
     self.assertEquals(result, expected)