コード例 #1
0
ファイル: sync.py プロジェクト: Jenyay/ljwatcher
    def _getInitialPost (self, makenewcomments=None):
        """
        Создать пост со списком комментариев
        makenewcomments - функция, которая принимает post, а возвращает список новых комментариев
        """
        # comment1
        #     comment2
        #         comment3
        # comment4
        postauthor = LJUser ('postauthor', 'http://example.com/image-jenyay-test.jpg')
        post = Post (postauthor, u'Это пост в ЖЖ', u'Заголовок', 123)

        user1 = LJUser ('jenyay-test', 'http://example.com/image-jenyay-test.jpg')
        comment1 = Comment (user1, u'Бла-бла-бла', 1000, 0, post)

        user2 = LJUser ('jenyay', 'http://example.com/image-jenyay.jpg')
        comment2 = Comment (user2, u'Ответ на коммент', 1001, 1000, post)

        user3 = LJUser ('username3', 'http://example.com/image-username3.jpg')
        comment3 = Comment (user3, u'Ответ на еще один коммент', 1002, 1001, post)

        user4 = LJUser ('username4', 'http://example.com/image-username4.jpg')
        comment4 = Comment (user4, u'Ответ на пост', 1003, 0, post)

        commentsFlat = [comment1, comment2, comment3, comment4]

        if makenewcomments:
            commentsFlat += makenewcomments (post)

        tree = buildTree (commentsFlat)
        post.addComments (tree)
        return post
コード例 #2
0
ファイル: ljclasses.py プロジェクト: Jenyay/ljwatcher
    def testFindComment (self):
        # comment1
        #     comment2
        #         comment3
        # comment4

        postauthor = LJUser ('postauthor', 'http://example.com/image-jenyay-test.jpg')
        post = Post (postauthor, u'Это пост в ЖЖ', u'Заголовок', 123)

        user1 = LJUser ('jenyay-test', 'http://example.com/image-jenyay-test.jpg')
        comment1 = Comment (user1, u'Бла-бла-бла', 1000, 0, post)

        user2 = LJUser ('jenyay', 'http://example.com/image-jenyay.jpg')
        comment2 = Comment (user2, u'Ответ на коммент', 1001, 1000, post)

        user3 = LJUser ('username3', 'http://example.com/image-username3.jpg')
        comment3 = Comment (user3, u'Ответ на еще один коммент', 1002, 1001, post)

        user4 = LJUser ('username4', 'http://example.com/image-username4.jpg')
        comment4 = Comment (user4, u'Ответ на пост', 1003, 0, post)

        commentsFlat = [comment1, comment2, comment3, comment4]
        tree = buildTree (commentsFlat)

        post.addComments (tree)

        self.assertEqual (post.getComment (900), None)
        self.assertEqual (post.getComment (1000), comment1)
        self.assertEqual (post.getComment (1001), comment2)
        self.assertEqual (post.getComment (1002), comment3)
        self.assertEqual (post.getComment (1003), comment4)

        self.assertEqual (comment1.getComment (1001), comment2)
        self.assertEqual (comment1.getComment (1002), comment3)
        self.assertEqual (comment1.getComment (1003), None)
コード例 #3
0
ファイル: templates.py プロジェクト: Jenyay/ljwatcher
    def testPostHtml (self):
        user1 = LJUser ('jenyay-test', 'http://example.com/image-jenyay-test.jpg')
        comment1 = Comment (user1, u'Бла-бла-бла', 1000, 0)

        user2 = LJUser ('jenyay', 'http://example.com/image-jenyay.jpg')
        comment2 = Comment (user2, u'Ответ на коммент', 1001, 1000)

        user3 = LJUser ('username3', 'http://example.com/image-username3.jpg')
        comment3 = Comment (user3, u'Ответ на еще один коммент', 1002, 1001)

        user4 = LJUser ('username4', 'http://example.com/image-username4.jpg')
        comment4 = Comment (user4, u'Ответ на пост', 1003, 0)

        commentsFlat = [comment1, comment2, comment3, comment4]
        tree = buildTree (commentsFlat)

        postauthor = LJUser ('postauthor', 'http://example.com/image-jenyay-test.jpg')
        post = Post (postauthor, u'Это пост в ЖЖ', u'Заголовок', 123)

        post.addComments (tree)

        generator = HtmlGenerator (self.templatePath, post)

        html = generator.makePostHtml ()
        self._commentInText (comment1, html, generator.indent * 0)
        self._commentInText (comment2, html, generator.indent * 1)
        self._commentInText (comment3, html, generator.indent * 2)
        self._commentInText (comment4, html, generator.indent * 0)

        self._contentInText (post, html)
コード例 #4
0
ファイル: ljclasses.py プロジェクト: Jenyay/ljwatcher
    def testMarkRead1 (self):
        # comment1
        #     comment2
        #         comment3
        # comment4

        postauthor = LJUser ('postauthor', 'http://example.com/image-jenyay-test.jpg')
        post = Post (postauthor, u'Это пост в ЖЖ', u'Заголовок', 123)

        user1 = LJUser ('jenyay-test', 'http://example.com/image-jenyay-test.jpg')
        comment1 = Comment (user1, u'Бла-бла-бла', 1000, 0)

        user2 = LJUser ('jenyay', 'http://example.com/image-jenyay.jpg')
        comment2 = Comment (user2, u'Ответ на коммент', 1001, 1000)

        user3 = LJUser ('username3', 'http://example.com/image-username3.jpg')
        comment3 = Comment (user3, u'Ответ на еще один коммент', 1002, 1001)

        user4 = LJUser ('username4', 'http://example.com/image-username4.jpg')
        comment4 = Comment (user4, u'Ответ на пост', 1003, 0)

        commentsFlat = [comment1, comment2, comment3, comment4]
        tree = buildTree (commentsFlat)

        post.addComments (tree)
        post.markCommentsAsRead ()

        self.assertFalse (comment1.isNew)
        self.assertFalse (comment2.isNew)
        self.assertFalse (comment3.isNew)
        self.assertFalse (comment4.isNew)

        self.assertFalse (comment1.hasNew)
        self.assertFalse (comment2.hasNew)
        self.assertFalse (comment3.hasNew)
        self.assertFalse (comment4.hasNew)

        self.assertEqual (comment1.post, None)
        self.assertEqual (comment2.post, None)
        self.assertEqual (comment3.post, None)
        self.assertEqual (comment4.post, None)