test_tweet.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. from base import BaseTestCase, Tweet, Conversation, get_timeline_tweet
  2. from parameterized import parameterized
  3. # image = tweet + 'div.attachments.media-body > div > div > a > div > img'
  4. # self.assert_true(self.get_image_url(image).split('/')[0] == 'http')
  5. timeline = [
  6. [1, 'Test account', 'mobile_test', '10 Aug 2016', '763483571793174528',
  7. '.'],
  8. [3, 'Test account', 'mobile_test', '3 Mar 2016', '705522133443571712',
  9. 'LIVE on #Periscope pscp.tv/w/aadiTzF6dkVOTXZSbX…'],
  10. [6, 'mobile test 2', 'mobile_test_2', '1 Oct 2014', '517449200045277184',
  11. 'Testing. One two three four. Test.']
  12. ]
  13. status = [
  14. [20, 'jack', 'jack', '21 Mar 2006', 'just setting up my twttr'],
  15. [134849778302464000, 'The Twoffice', 'TheTwoffice', '11 Nov 2011', 'test'],
  16. [105685475985080322, 'The Twoffice', 'TheTwoffice', '22 Aug 2011', 'regular tweet'],
  17. [572593440719912960, 'Test account', 'mobile_test', '3 Mar 2015', 'testing test']
  18. ]
  19. invalid = [
  20. ['mobile_test/status/120938109238'],
  21. ['TheTwoffice/status/8931928312']
  22. ]
  23. multiline = [
  24. [400897186990284800, 'mobile_test_3',
  25. """
  26. KEEP
  27. CALM
  28. AND
  29. CLICHÉ
  30. ON"""],
  31. [1718660434457239868, 'WebDesignMuseum',
  32. """
  33. Happy 32nd Birthday HTML tags!
  34. On October 29, 1991, the internet pioneer, Tim Berners-Lee, published a document entitled HTML Tags.
  35. The document contained a description of the first 18 HTML tags: <title>, <nextid>, <a>, <isindex>, <plaintext>, <listing>, <p>, <h1>…<h6>, <address>, <hp1>, <hp2>…, <dl>, <dt>, <dd>, <ul>, <li>,<menu> and <dir>. The design of the first version of HTML language was influenced by the SGML universal markup language.
  36. #WebDesignHistory"""]
  37. ]
  38. link = [
  39. ['nim_lang/status/1110499584852353024', [
  40. 'nim-lang.org/araq/ownedrefs.…',
  41. 'news.ycombinator.com/item?id…',
  42. 'teddit.net/r/programming…'
  43. ]],
  44. ['nim_lang/status/1125887775151140864', [
  45. 'en.wikipedia.org/wiki/Nim_(p…'
  46. ]],
  47. ['hiankun_taioan/status/1086916335215341570', [
  48. '(hackernoon.com/interview-wit…)'
  49. ]],
  50. ['archillinks/status/1146302618223951873', [
  51. 'flickr.com/photos/87101284@N…',
  52. 'hisafoto.tumblr.com/post/176…'
  53. ]],
  54. ['archillinks/status/1146292551936335873', [
  55. 'flickr.com/photos/michaelrye…',
  56. 'furtho.tumblr.com/post/16618…'
  57. ]]
  58. ]
  59. username = [
  60. ['Bountysource/status/1094803522053320705', ['nim_lang']],
  61. ['leereilly/status/1058464250098704385', ['godotengine', 'unity3d', 'nim_lang']]
  62. ]
  63. emoji = [
  64. ['Tesla/status/1134850442511257600', '🌈❤️🧡💛💚💙💜']
  65. ]
  66. retweet = [
  67. [7, 'mobile_test_2', 'mobile test 2', 'Test account', '@mobile_test', '1234'],
  68. [3, 'mobile_test_8', 'mobile test 8', 'jack', '@jack', 'twttr']
  69. ]
  70. class TweetTest(BaseTestCase):
  71. @parameterized.expand(timeline)
  72. def test_timeline(self, index, fullname, username, date, tid, text):
  73. self.open_nitter(username)
  74. tweet = get_timeline_tweet(index)
  75. self.assert_exact_text(fullname, tweet.fullname)
  76. self.assert_exact_text('@' + username, tweet.username)
  77. self.assert_exact_text(date, tweet.date)
  78. self.assert_text(text, tweet.text)
  79. permalink = self.find_element(tweet.date + ' a')
  80. self.assertIn(tid, permalink.get_attribute('href'))
  81. @parameterized.expand(status)
  82. def test_status(self, tid, fullname, username, date, text):
  83. tweet = Tweet()
  84. self.open_nitter(f'{username}/status/{tid}')
  85. self.assert_exact_text(fullname, tweet.fullname)
  86. self.assert_exact_text('@' + username, tweet.username)
  87. self.assert_exact_text(date, tweet.date)
  88. self.assert_text(text, tweet.text)
  89. @parameterized.expand(multiline)
  90. def test_multiline_formatting(self, tid, username, text):
  91. self.open_nitter(f'{username}/status/{tid}')
  92. self.assert_text(text.strip('\n'), Conversation.main)
  93. @parameterized.expand(emoji)
  94. def test_emoji(self, tweet, text):
  95. self.open_nitter(tweet)
  96. self.assert_text(text, Conversation.main)
  97. @parameterized.expand(link)
  98. def test_link(self, tweet, links):
  99. self.open_nitter(tweet)
  100. for link in links:
  101. self.assert_text(link, Conversation.main)
  102. @parameterized.expand(username)
  103. def test_username(self, tweet, usernames):
  104. self.open_nitter(tweet)
  105. for un in usernames:
  106. link = self.find_link_text(f'@{un}')
  107. self.assertIn(f'/{un}', link.get_property('href'))
  108. @parameterized.expand(retweet)
  109. def test_retweet(self, index, url, retweet_by, fullname, username, text):
  110. self.open_nitter(url)
  111. tweet = get_timeline_tweet(index)
  112. self.assert_text(f'{retweet_by} retweeted', tweet.retweet)
  113. self.assert_text(text, tweet.text)
  114. self.assert_exact_text(fullname, tweet.fullname)
  115. self.assert_exact_text(username, tweet.username)
  116. @parameterized.expand(invalid)
  117. def test_invalid_id(self, tweet):
  118. self.open_nitter(tweet)
  119. self.assert_text('Tweet not found', '.error-panel')
  120. #@parameterized.expand(reply)
  121. #def test_thread(self, tweet, num):
  122. #self.open_nitter(tweet)
  123. #thread = self.find_element(f'.timeline > div:nth-child({num})')
  124. #self.assertIn(thread.get_attribute('class'), 'thread-line')