nitter/tests/test_tweet.py

145 lines
4.7 KiB
Python
Raw Normal View History

2019-06-28 02:56:02 +00:00
from base import BaseTestCase, Tweet, get_timeline_tweet
2019-06-28 17:18:52 +00:00
from parameterized import parameterized
2019-06-28 02:56:02 +00:00
# image = tweet + 'div.attachments.media-body > div > div > a > div > img'
# self.assert_true(self.get_image_url(image).split('/')[0] == 'http')
2019-06-28 22:42:10 +00:00
timeline = [
[1, 'Test account', 'mobile_test', '10 Aug 2016', '763483571793174528',
2019-06-28 17:18:52 +00:00
'.'],
2019-06-28 02:56:02 +00:00
2019-06-28 22:42:10 +00:00
[3, 'Test account', 'mobile_test', '3 Mar 2016', '705522133443571712',
2019-06-28 17:18:52 +00:00
'LIVE on #Periscope pscp.tv/w/aadiTzF6dkVOTXZSbX…'],
2019-06-28 02:56:02 +00:00
2020-06-01 03:30:52 +00:00
[6, 'mobile test 2', 'mobile_test_2', '1 Oct 2014', '517449200045277184',
2019-06-28 17:18:52 +00:00
'Testing. One two three four. Test.']
2019-06-28 02:56:02 +00:00
]
2019-06-28 22:42:10 +00:00
status = [
2022-06-03 22:52:28 +00:00
[20, 'jack', 'jack', '21 Mar 2006', 'just setting up my twttr'],
2020-06-01 00:25:56 +00:00
[134849778302464000, 'The Twoffice', 'TheTwoffice', '11 Nov 2011', 'test'],
2019-06-28 22:42:10 +00:00
[105685475985080322, 'The Twoffice', 'TheTwoffice', '22 Aug 2011', 'regular tweet'],
2020-06-01 00:25:56 +00:00
[572593440719912960, 'Test account', 'mobile_test', '3 Mar 2015', 'testing test']
2019-06-28 02:56:02 +00:00
]
2019-06-28 22:42:10 +00:00
invalid = [
2019-06-28 17:18:52 +00:00
['mobile_test/status/120938109238'],
['TheTwoffice/status/8931928312']
2019-06-28 02:56:02 +00:00
]
2019-06-28 22:42:10 +00:00
multiline = [
2019-06-28 17:18:52 +00:00
[400897186990284800, 'mobile_test_3',
"""
2019-06-28 02:56:02 +00:00
KEEP
CALM
AND
CLICHÉ
2019-06-28 17:18:52 +00:00
ON"""]
]
2019-06-28 22:42:10 +00:00
link = [
2019-06-28 17:18:52 +00:00
['nim_lang/status/1110499584852353024', [
'nim-lang.org/araq/ownedrefs.…',
'news.ycombinator.com/item?id…',
'teddit.net/r/programming…'
2019-06-28 17:18:52 +00:00
]],
['nim_lang/status/1125887775151140864', [
'en.wikipedia.org/wiki/Nim_(p…'
2019-06-28 17:18:52 +00:00
]],
['hiankun_taioan/status/1086916335215341570', [
'(hackernoon.com/interview-wit…)'
]],
['archillinks/status/1146302618223951873', [
'flickr.com/photos/87101284@N…',
'hisafoto.tumblr.com/post/176…'
]],
['archillinks/status/1146292551936335873', [
'flickr.com/photos/michaelrye…',
'furtho.tumblr.com/post/16618…'
2019-06-28 17:18:52 +00:00
]]
]
2019-06-28 22:42:10 +00:00
username = [
['Bountysource/status/1094803522053320705', ['nim_lang']],
['leereilly/status/1058464250098704385', ['godotengine', 'unity3d', 'nim_lang']]
]
emoji = [
2019-06-28 17:18:52 +00:00
['Tesla/status/1134850442511257600', '🌈❤️🧡💛💚💙💜']
2019-06-28 02:56:02 +00:00
]
2019-06-28 22:42:10 +00:00
retweet = [
[7, 'mobile_test_2', 'mobile test 2', 'Test account', '@mobile_test', '1234'],
2022-06-03 22:52:28 +00:00
[3, 'mobile_test_8', 'mobile test 8', 'jack', '@jack', 'twttr']
2019-06-28 22:42:10 +00:00
]
# reply = [
# ['mobile_test/with_replies', 15]
# ]
2019-08-12 14:55:04 +00:00
2019-06-28 22:42:10 +00:00
class TweetTest(BaseTestCase):
@parameterized.expand(timeline)
def test_timeline(self, index, fullname, username, date, tid, text):
2019-06-28 17:18:52 +00:00
self.open_nitter(username)
tweet = get_timeline_tweet(index)
self.assert_exact_text(fullname, tweet.fullname)
self.assert_exact_text('@' + username, tweet.username)
self.assert_exact_text(date, tweet.date)
self.assert_text(text, tweet.text)
2019-06-28 22:42:10 +00:00
permalink = self.find_element(tweet.date + ' a')
self.assertIn(tid, permalink.get_attribute('href'))
2019-06-28 17:18:52 +00:00
2019-06-28 22:42:10 +00:00
@parameterized.expand(status)
2019-06-28 17:18:52 +00:00
def test_status(self, tid, fullname, username, date, text):
2019-06-28 02:56:02 +00:00
tweet = Tweet()
2019-06-28 17:18:52 +00:00
self.open_nitter(f'{username}/status/{tid}')
self.assert_exact_text(fullname, tweet.fullname)
self.assert_exact_text('@' + username, tweet.username)
self.assert_exact_text(date, tweet.date)
self.assert_text(text, tweet.text)
2019-06-28 22:42:10 +00:00
@parameterized.expand(multiline)
2019-06-28 17:18:52 +00:00
def test_multiline_formatting(self, tid, username, text):
self.open_nitter(f'{username}/status/{tid}')
self.assert_text(text.strip('\n'), '.main-tweet')
2019-06-28 22:42:10 +00:00
@parameterized.expand(emoji)
def test_emoji(self, tweet, text):
2019-06-28 17:18:52 +00:00
self.open_nitter(tweet)
self.assert_text(text, '.main-tweet')
2019-06-28 22:42:10 +00:00
@parameterized.expand(link)
def test_link(self, tweet, links):
2019-06-28 17:18:52 +00:00
self.open_nitter(tweet)
for link in links:
self.assert_text(link, '.main-tweet')
2019-06-28 22:42:10 +00:00
@parameterized.expand(username)
def test_username(self, tweet, usernames):
self.open_nitter(tweet)
for un in usernames:
link = self.find_link_text(f'@{un}')
self.assertIn(f'/{un}', link.get_property('href'))
@parameterized.expand(retweet)
def test_retweet(self, index, url, retweet_by, fullname, username, text):
self.open_nitter(url)
tweet = get_timeline_tweet(index)
self.assert_text(f'{retweet_by} retweeted', tweet.retweet)
self.assert_text(text, tweet.text)
self.assert_exact_text(fullname, tweet.fullname)
self.assert_exact_text(username, tweet.username)
@parameterized.expand(invalid)
2019-06-28 17:18:52 +00:00
def test_invalid_id(self, tweet):
self.open_nitter(tweet)
self.assert_text('Tweet not found', '.error-panel')
2019-08-12 14:55:04 +00:00
# @parameterized.expand(reply)
# def test_thread(self, tweet, num):
# self.open_nitter(tweet)
# thread = self.find_element(f'.timeline > div:nth-child({num})')
# self.assertIn(thread.get_attribute('class'), 'thread-line')