コード例 #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_GetBlogposts_NoPosts(self):
        label = label_model.Label('Test')

        result = label.GetBlogposts()
        expected = []

        self.assertEquals(result, expected)
コード例 #3
0
    def test_GetAll(self):
        label = label_model.Label('Test')
        label.put()

        result = label_model.Label.GetAll()
        expected = [label]

        self.assertEquals(result, expected)
コード例 #4
0
    def test_RemoveFromBlogpost_LabelNotPresent(self):
        label = label_model.Label('Test')
        self.blogpost.id = '12345'

        label.RemoveFromBlogpost(self.blogpost)

        self.assertTrue(self.blogpost.id not in label.blogposts)
        self.assertFalse(self.blogpost.RemoveLabel.called)
コード例 #5
0
    def test_GetByStorageKey(self):
        label = label_model.Label('Test')
        label.put()

        result = label_model.Label.GetByStorageKey(label.storage_key)
        expected = label

        self.assertEquals(result, expected)
コード例 #6
0
    def test_ToJson_NoBlogposts(self):
        label = label_model.Label('Test')

        result = label.ToJson()

        self.assertEquals(result['blogposts'], [])
        self.assertEquals(result['label'], label.label)
        self.assertEquals(result['id'], label.storage_key)
        self.assertEquals(result['created_timestamp'],
                          str(label.created_timestamp))
コード例 #7
0
    def test_GetBlogposts_WithPosts(self):
        label = label_model.Label('Test')
        self.blogpost.id = '12345'

        label.AddToBlogpost(self.blogpost)

        result = label.GetBlogposts()
        expected = [self.blogpost]

        self.assertEquals(result, expected)
        self.assertEquals(result[0].id, self.blogpost.id)
コード例 #8
0
    def test_AddToBlogpost_NewPost(self):
        label = label_model.Label('Test')
        self.blogpost.id = '12345'

        label.AddToBlogpost(self.blogpost)

        self.assertTrue(self.blogpost.id in label.blogposts)

        self.assertEquals(len(label.blogposts), 1)
        self.assertTrue(self.blogpost.AddLabel.called)
        self.assertEquals(self.blogpost.AddLabel.call_count, 1)
コード例 #9
0
ファイル: engine.py プロジェクト: cheesesashimi/BloggerEngine
    def GetOrInsertLabel(self, label_text):
        """Gets or inserts a label.

        Args:
          label_text: string; The label text to get or insert.

        Returns:
          A populated Label instance.

        """
        label = label_model.Label.GetByStorageKey(label_text)
        if not label:
            label = label_model.Label(label_text)
            label.put()
        return label
コード例 #10
0
ファイル: engine.py プロジェクト: cheesesashimi/BloggerEngine
    def AddLabelToBlogpost(self, label_text, blogpost_id):
        """Adds a label to a given blog post.

        Args:
          label_text: string; The label text to add to a blog post.
          blogpost_id: string; The blog post ID to add the label to.

        Returns:
          A Label instance.

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

        label = label_model.Label.GetByStorageKey(label_text)
        if not label:
            label = label_model.Label(label_text)
            label.put()

        post.AddLabel(label)
        label.AddToBlogpost(post)
        return label
コード例 #11
0
    def test_Put(self):
        label = label_model.Label('Test')
        label.put()

        self.assertTrue(
            label.storage_key in label_model.Label.instances['Label'])
コード例 #12
0
 def test_Constructor(self):
     label = label_model.Label('Test')
     self.assertEquals(label.label, 'test')
     self.assertIsInstance(label.blogposts, OrderedDict)