コード例 #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 testMarkRead2 (self):
        # comment1
        #     comment2
        #         comment3
        # comment4

        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)

        comment1.markCommentsAsRead()

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

        self.assertFalse (comment1.hasNew)
        self.assertFalse (comment2.hasNew)
        self.assertFalse (comment3.hasNew)
        self.assertFalse (comment4.hasNew)
コード例 #3
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)
コード例 #4
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)
コード例 #5
0
ファイル: treebuilder.py プロジェクト: Jenyay/ljwatcher
    def testNavalny (self):
        # http://navalny.livejournal.com/762032.html?style=mine
        username = "******"
        postid = 762032

        commentsFlat = self.loader.getComments (username, postid) 
        commentsTree = buildTree (commentsFlat)

        self.assertTrue (u'я видел без комментариев!' in commentsTree[0].body)
        self.assertEqual (commentsTree[0].dtalkid, 416265136)
        self.assertEqual (commentsTree[0].parentdtalkid, 0)
        self.assertEqual (commentsTree[0].user.name, 'feisty_lynx')
        self.assertEqual (commentsTree[0].user.userpic, 'http://l-userpic.livejournal.com/115132872/27471651')

        self.assertEqual (commentsTree[0][0].body, u'Благодаря Железняку мы узнали, что истинный патриот не обязательно должен ходить в лаптях, играть на балалайке, ездить на Жигулях и учить детей в России.')
        self.assertEqual (commentsTree[0][0].dtalkid, 416274352)
        self.assertEqual (commentsTree[0][0].parentdtalkid, 416265136)
        self.assertEqual (commentsTree[0][0].user.name, 'japondios')
        self.assertEqual (commentsTree[0][0].user.userpic, 'http://l-userpic.livejournal.com/112338611/35839794')
コード例 #6
0
ファイル: treebuilder.py プロジェクト: Jenyay/ljwatcher
    def testSimple (self):
        # http://jenyay-test.livejournal.com/2063.html
        username = "******"
        postid = 2063

        commentsFlat = self.loader.getComments (username, postid) 
        commentsTree = buildTree (commentsFlat)

        self.assertEqual (commentsTree[0].body, u'А вот и первый комментарий')
        self.assertEqual (commentsTree[0].dtalkid, 5391)
        self.assertEqual (commentsTree[0].parentdtalkid, 0)
        self.assertEqual (commentsTree[0].user.name, 'jenyay')
        self.assertEqual (commentsTree[0].user.userpic, 'http://l-userpic.livejournal.com/76819884/3365201')

        self.assertEqual (commentsTree[0][0].body, u'А это коммент на коммент :)')
        self.assertEqual (commentsTree[0][0].dtalkid, 5647)
        self.assertEqual (commentsTree[0][0].parentdtalkid, 5391)
        self.assertEqual (commentsTree[0][0].user.name, 'jenyay_test')
        self.assertEqual (commentsTree[0][0].user.userpic, '')
コード例 #7
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)
コード例 #8
0
ファイル: templates.py プロジェクト: Jenyay/ljwatcher
    def testCommentsTreeHtml (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)
        generator = HtmlGenerator (self.templatePath, tree)

        html = generator.makeCommentsTreeHtml ()
        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)