test_tweet.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. from base import BaseTestCase, Tweet, 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', '10 Nov 2011', 'test'],
  16. [105685475985080322, 'The Twoffice', 'TheTwoffice', '22 Aug 2011', 'regular tweet'],
  17. [572593440719912960, 'Test account', 'mobile_test', '2 Mar 2015', 'testing test']
  18. ]
  19. invalid = [
  20. ['mobile_test/status/120938109238'],
  21. ['TheTwoffice/status/8931928312']
  22. ]
  23. multiline = [
  24. [1142904127594401797, 'hot_pengu',
  25. """
  26. New tileset, dust effects, background. The 'sea' has per-line parallax and wavey fx which we think is really cool even tho u didn't notice 🐶. code:
  27. @exelotl
  28. #pixelart #gbadev #gba #indiedev"""],
  29. [400897186990284800, 'mobile_test_3',
  30. """
  31. KEEP
  32. CALM
  33. AND
  34. CLICHÉ
  35. ON"""]
  36. ]
  37. link = [
  38. ['nim_lang/status/1110499584852353024', [
  39. 'nim-lang.org/araq/ownedrefs.…',
  40. 'news.ycombinator.com/item?id…',
  41. 'old.reddit.com/r/programming…'
  42. ]],
  43. ['nim_lang/status/1125887775151140864', [
  44. 'en.wikipedia.org/wiki/Nim_(p…'
  45. ]],
  46. ['hiankun_taioan/status/1086916335215341570', [
  47. '(hackernoon.com/interview-wit…)'
  48. ]],
  49. ['archillinks/status/1146302618223951873', [
  50. 'flickr.com/photos/87101284@N…',
  51. 'hisafoto.tumblr.com/post/176…'
  52. ]],
  53. ['archillinks/status/1146292551936335873', [
  54. 'flickr.com/photos/michaelrye…',
  55. 'furtho.tumblr.com/post/16618…'
  56. ]]
  57. ]
  58. username = [
  59. ['Bountysource/status/1094803522053320705', ['nim_lang']],
  60. ['leereilly/status/1058464250098704385', ['godotengine', 'unity3d', 'nim_lang']]
  61. ]
  62. emoji = [
  63. ['Tesla/status/1134850442511257600', '🌈❤️🧡💛💚💙💜']
  64. ]
  65. retweet = [
  66. [7, 'mobile_test_2', 'mobile test 2', 'Test account', '@mobile_test', '1234'],
  67. [3, 'mobile_test_8', 'mobile test 8', 'jack 🌍🌏🌎', '@jack', 'twttr']
  68. ]
  69. reply = [
  70. ['mobile_test?max_position=471336696307392513', '@mobile_test', '@mobile_test'],
  71. ['mobile_test_2?max_position=375101899214561280', '@mobile_test_2', '@mobile_test']
  72. ]
  73. class TweetTest(BaseTestCase):
  74. @parameterized.expand(timeline)
  75. def test_timeline(self, index, fullname, username, date, tid, text):
  76. self.open_nitter(username)
  77. tweet = get_timeline_tweet(index)
  78. self.assert_exact_text(fullname, tweet.fullname)
  79. self.assert_exact_text('@' + username, tweet.username)
  80. self.assert_exact_text(date, tweet.date)
  81. self.assert_text(text, tweet.text)
  82. permalink = self.find_element(tweet.date + ' a')
  83. self.assertIn(tid, permalink.get_attribute('href'))
  84. @parameterized.expand(status)
  85. def test_status(self, tid, fullname, username, date, text):
  86. tweet = Tweet()
  87. self.open_nitter(f'{username}/status/{tid}')
  88. self.assert_exact_text(fullname, tweet.fullname)
  89. self.assert_exact_text('@' + username, tweet.username)
  90. self.assert_exact_text(date, tweet.date)
  91. self.assert_text(text, tweet.text)
  92. @parameterized.expand(multiline)
  93. def test_multiline_formatting(self, tid, username, text):
  94. self.open_nitter(f'{username}/status/{tid}')
  95. self.assert_text(text.strip('\n'), '.main-tweet')
  96. @parameterized.expand(emoji)
  97. def test_emoji(self, tweet, text):
  98. self.open_nitter(tweet)
  99. self.assert_text(text, '.main-tweet')
  100. @parameterized.expand(link)
  101. def test_link(self, tweet, links):
  102. self.open_nitter(tweet)
  103. for link in links:
  104. self.assert_text(link, '.main-tweet')
  105. @parameterized.expand(username)
  106. def test_username(self, tweet, usernames):
  107. self.open_nitter(tweet)
  108. for un in usernames:
  109. link = self.find_link_text(f'@{un}')
  110. self.assertIn(f'/{un}', link.get_property('href'))
  111. @parameterized.expand(retweet)
  112. def test_retweet(self, index, url, retweet_by, fullname, username, text):
  113. self.open_nitter(url)
  114. tweet = get_timeline_tweet(index)
  115. self.assert_text(f'{retweet_by} retweeted', tweet.retweet)
  116. self.assert_text(text, tweet.text)
  117. self.assert_exact_text(fullname, tweet.fullname)
  118. self.assert_exact_text(username, tweet.username)
  119. @parameterized.expand(invalid)
  120. def test_invalid_id(self, tweet):
  121. self.open_nitter(tweet)
  122. self.assert_text('Tweet not found', '.error-panel')
  123. @parameterized.expand(reply)
  124. def test_reply(self, tweet, username, reply):
  125. self.open_nitter(tweet)
  126. tweet = get_timeline_tweet(2)
  127. self.assert_text(username, tweet.username)
  128. self.assert_text('Replying to ' + reply, tweet.reply)