예제 #1
0
class TreeBuilderTest (unittest.TestCase):
    """Проверка построения дерева коммертариев по списку"""
    
    def setUp (self):
        self.loader = PostLoader (testparams.ljusername, testparams.ljpassword)


    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, '')


    @unittest.skipUnless (testparams.runLongTests, 'Skip Navalny Post')
    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')
예제 #2
0
    def testNavalnyPost (self):
        # http://navalny.livejournal.com/762032.html?style=mine
        username = "******"
        postid = 762032

        loader = PostLoader (testparams.ljusername, testparams.ljpassword)

        post = loader.getPost (LJUrl (username, postid) )
        generator = HtmlGenerator (self.templatePath, post)
        html = generator.makePostHtml ()

        self._contentInText (post, html)
        self.assertTrue (u'Комментариев: 3245' in html)

        with open ('../temp/testNavalnyPost.htm', 'w') as fp:
            fp.write (html.encode ('utf8'))
예제 #3
0
    def testRealPost1 (self):
        # http://jenyay.livejournal.com/244224.html?style=mine
        username = "******"
        postid = 244224

        loader = PostLoader (testparams.ljusername, testparams.ljpassword)

        post = loader.getPost (LJUrl (username, postid) )
        generator = HtmlGenerator (self.templatePath, post)
        html = generator.makePostHtml ()

        self._contentInText (post, html)
        self.assertTrue (u'Комментариев: 37' in html)
        self.assertTrue (u'О двойных стандартах' in html)
        self.assertTrue (u'Архивируем rar-ом под Виндой файлы' in html)
        self.assertTrue (u'Винда - стандарт.' in html)
        self.assertTrue (u'Не, если программа не поддерживает работу с Unicode, то это опять же виновата программа.' in html)

        with open ('../temp/testRealPost1.htm', 'w') as fp:
            fp.write (html.encode ('utf8'))
예제 #4
0
 def setUp (self):
     self.loader = PostLoader (testparams.ljusername, testparams.ljpassword)
예제 #5
0
class PostLoaderTest (unittest.TestCase):
    """Тесты высокоуровненой работы с сервером ЖЖ (загрузка комментариев и постов)"""
    def setUp (self):
        self.loader = PostLoader (testparams.ljusername, testparams.ljpassword)


    def testLoadRealPost1 (self):
        # http://jenyay.livejournal.com/244224.html?style=mine
        username = "******"
        postid = 244224

        post = self.loader.getPost (LJUrl (username, postid) )

        self.assertEqual (post.commentsCount, 37)
        self.assertTrue (u'Архивируем rar-ом под Виндой файлы с русскими буквами в имени' in post.body)
        self.assertEqual (post.title, u'О двойных стандартах')
        self.assertEqual (post.user.name, u'jenyay')
        self.assertEqual (post.user.userpic, u'http://l-userpic.livejournal.com/76819884/3365201')
        self.assertEqual (post.url.pureUrl, u'http://jenyay.livejournal.com/244224.html')
        self.assertTrue (u'Винда - стандарт.' not in post.body)
        self.assertTrue (u'О двойных стандартах' not in post.body)
        self.assertTrue (u'stuffittrans' not in post.body)


    def testLoadComments (self):
        # http://jenyay.livejournal.com/244224.html?style=mine
        username = "******"
        postid = 244224

        result = self.loader.getComments (username, postid)
        self.assertEqual (len (result), 37)


    def testLoadComments2 (self):
        # http://jenyay-test.livejournal.com/2063.html
        username = "******"
        postid = 2063

        result = self.loader.getComments (username, postid)
        self.assertEqual (len (result), 48)

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

        commentnumber2 = 1
        self.assertEqual (result[commentnumber2].body, u'А это коммент на коммент :)')
        self.assertEqual (result[commentnumber2].dtalkid, 5647)
        self.assertEqual (result[commentnumber2].parentdtalkid, 5391)
        self.assertEqual (result[commentnumber2].user.name, 'jenyay_test')
        self.assertEqual (result[commentnumber2].user.userpic, '')
        self.assertEqual (len (result[commentnumber2].comments), 0)


        commentnumber3 = 2
        self.assertEqual (result[commentnumber3].body, u'И еще один коммент')
        self.assertEqual (result[commentnumber3].dtalkid, 5903)
        self.assertEqual (result[commentnumber3].parentdtalkid, 5647)
        self.assertEqual (result[commentnumber3].user.name, 'jenyay')
        self.assertEqual (result[commentnumber3].user.userpic, 'http://l-userpic.livejournal.com/76819884/3365201')
        self.assertEqual (len (result[commentnumber3].comments), 0)


    @unittest.skipUnless (testparams.runLongTests, 'Skip Navalny Post')
    def testLoadNavalny (self):
        # http://navalny.livejournal.com/762032.html?style=mine
        username = "******"
        postid = 762032

        comments = 3245

        result = self.loader.getComments (username, postid)
        self.assertEqual (len (result), comments)