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