コード例 #1
0
    def setUp(self):
        author_model.Author.instances = {}
        base_model.BaseModel.instances = {}
        blogpost_model.Blogpost.instances = {}
        comment_model.Comment.instances = {}
        label_model.Label.instances = {}

        colin = author_model.Author('colin')
        colin.put()

        zack = author_model.Author('zack')
        zack.put()

        blogpost1 = blogpost_model.Blogpost(zack, 'Hi!', 'Lorem ipsum...')
        blogpost1.put()

        blogpost2 = blogpost_model.Blogpost(zack, 'Caps lock',
                                            'Not the caps lock!')
        blogpost2.put()

        blogpost3 = blogpost_model.Blogpost(colin, 'Hi!', 'Hello world.')
        blogpost3.put()

        label1 = label_model.Label('intro')
        label1.put()
        label1.AddToBlogpost(blogpost1)
        label1.AddToBlogpost(blogpost3)

        label2 = label_model.Label('funny')
        label2.put()
        label2.AddToBlogpost(blogpost2)

        label3 = label_model.Label('good stuff')
        label3.put()
        label3.AddToBlogpost(blogpost1)
        label3.AddToBlogpost(blogpost2)
        label3.AddToBlogpost(blogpost3)

        comment1 = comment_model.Comment(colin, blogpost1, '...et dolar.')
        comment1.put()

        comment2 = comment_model.Comment(colin, blogpost2,
                                         'Anything but the caps lock!')
        comment2.put()

        comment3 = comment_model.Comment(zack, blogpost3, 'Welcome!')
        comment3.put()

        self.username = '******'
        self.headline = 'Hello world!'
        self.body = 'Yo!'
        self.label_text = 'good'

        self.authors = [colin, zack]
        self.blogposts = [blogpost1, blogpost2, blogpost3]
        self.comments = [comment1, comment2, comment3]
        self.labels = [label1, label2, label3]

        self.blogger_engine = engine.BloggerEngine()
コード例 #2
0
    def test_ToJson(self):
        comment = comment_model.Comment(self.author, self.blogpost,
                                        self.comment_text)

        self.author.ToJson.return_value = {
            'username': '******',
            'id': self.author.id
        }

        self.blogpost.ToJson.return_value = {
            'headline': 'hi',
            'body': 'hello',
            'id': str(id(self.blogpost))
        }

        result = comment.ToJson()

        self.assertTrue(self.author.ToJson.called)
        self.assertTrue(self.blogpost.ToJson.called)
        self.assertEquals(result['author'], self.author.ToJson.return_value)
        self.assertEquals(result['blogpost'],
                          self.blogpost.ToJson.return_value)
        self.assertEquals(result['created_timestamp'],
                          str(comment.created_timestamp))
        self.assertEquals(result['comment_text'], comment.comment_text)
        self.assertEquals(result['id'], comment.id)
コード例 #3
0
    def test_Put(self):
        comment = comment_model.Comment(self.author, self.blogpost,
                                        self.comment_text)
        comment.put()

        self.assertTrue(
            comment.id in comment_model.Comment.instances['Comment'])
コード例 #4
0
    def test_RemoveFromBlogpost(self):
        comment = comment_model.Comment(self.author, self.blogpost,
                                        self.comment_text)
        comment.RemoveFromBlogpost()

        self.assertTrue(self.author.AddComment.called)
        self.assertTrue(self.blogpost.RemoveComment.called)
コード例 #5
0
 def test_Constructor(self):
     comment = comment_model.Comment(self.author, self.blogpost,
                                     self.comment_text)
     self.assertTrue(self.author.AddComment.called)
     self.assertTrue(self.blogpost.AddComment.called)
     self.assertEquals(comment.comment_text, self.comment_text)
     self.assertIsNotNone(comment.created_timestamp)
     self.assertIsNotNone(comment.id)
コード例 #6
0
    def test_GetByStorageKey(self):
        comment = comment_model.Comment(self.author, self.blogpost,
                                        self.comment_text)
        comment.put()

        result = comment_model.Comment.GetByStorageKey(comment.id)
        expected = comment

        self.assertEquals(result, expected)
コード例 #7
0
    def test_GetAll(self):
        comment = comment_model.Comment(self.author, self.blogpost,
                                        self.comment_text)
        comment.put()

        result = comment_model.Comment.GetAll()
        expected = [comment]

        self.assertEquals(result, expected)
コード例 #8
0
ファイル: engine.py プロジェクト: cheesesashimi/BloggerEngine
    def SubmitComment(self, username, comment_text, blogpost_id):
        """Submits a comment.

        Args:
          username: string; A string representing the comment author's username.
          comment_text: string; The comment text's content.
          blogpost_id: string; The blog post ID to add the comment to.

        """
        post = blogpost_model.Blogpost.GetByStorageKey(blogpost_id)
        if not post:
            return None

        author = self.GetOrInsertAuthor(username)
        comment = comment_model.Comment(author, post, comment_text)
        comment.put()

        return comment