From f410720d1a2e4270e49f82d59eb2970bb9c2c536 Mon Sep 17 00:00:00 2001 From: Zed Date: Sat, 29 Jun 2019 00:42:10 +0200 Subject: [PATCH] Add more tweet tests --- tests/test_tweet.py | 84 ++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 32 deletions(-) diff --git a/tests/test_tweet.py b/tests/test_tweet.py index fb0b4bb..ac76450 100644 --- a/tests/test_tweet.py +++ b/tests/test_tweet.py @@ -4,37 +4,30 @@ from parameterized import parameterized # image = tweet + 'div.attachments.media-body > div > div > a > div > img' # self.assert_true(self.get_image_url(image).split('/')[0] == 'http') -timeline_tweets = [ - [1, 'Test account', 'mobile_test', '10 Aug 2016', +timeline = [ + [1, 'Test account', 'mobile_test', '10 Aug 2016', '763483571793174528', '.'], - [3, 'Test account', 'mobile_test', '3 Mar 2016', + [3, 'Test account', 'mobile_test', '3 Mar 2016', '705522133443571712', 'LIVE on #Periscope pscp.tv/w/aadiTzF6dkVOTXZSbXโ€ฆ'], - [6, 'mobile test 2', 'mobile_test_2', '1 Oct 2014', + [6, 'mobile test 2', 'mobile_test_2', '1 Oct 2014', '517449200045277184', 'Testing. One two three four. Test.'] ] -status_tweets = [ - [20, 'jack ๐ŸŒ๐ŸŒ๐ŸŒŽ', 'jack', '21 Mar 2006', - 'just setting up my twttr'], - - [134849778302464000, 'The Twoffice', 'TheTwoffice', '10 Nov 2011', - 'test'], - - [105685475985080322, 'The Twoffice', 'TheTwoffice', '22 Aug 2011', - 'regular tweet'], - - [572593440719912960, 'Test account', 'mobile_test', '2 Mar 2015', - 'testing test'] +status = [ + [20, 'jack ๐ŸŒ๐ŸŒ๐ŸŒŽ', 'jack', '21 Mar 2006', 'just setting up my twttr'], + [134849778302464000, 'The Twoffice', 'TheTwoffice', '10 Nov 2011', 'test'], + [105685475985080322, 'The Twoffice', 'TheTwoffice', '22 Aug 2011', 'regular tweet'], + [572593440719912960, 'Test account', 'mobile_test', '2 Mar 2015', 'testing test'] ] -invalid_tweets = [ +invalid = [ ['mobile_test/status/120938109238'], ['TheTwoffice/status/8931928312'] ] -multiline_tweets = [ +multiline = [ [1142904127594401797, 'hot_pengu', """ 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: @@ -51,37 +44,48 @@ CLICHร‰ ON"""] ] -link_tweets = [ +link = [ ['nim_lang/status/1110499584852353024', [ 'nim-lang.org/araq/ownedrefs.โ€ฆ', 'news.ycombinator.com/item?idโ€ฆ', 'old.reddit.com/r/programmingโ€ฆ' ]], - ['nim_lang/status/1125887775151140864', [ 'en.wikipedia.org/wiki/Nim_(pโ€ฆ)' ]], - ['hiankun_taioan/status/1086916335215341570', [ '(hackernoon.com/interview-witโ€ฆ)' ]] ] -emoji_tweets = [ +username = [ + ['Bountysource/status/1094803522053320705', ['nim_lang']], + ['leereilly/status/1058464250098704385', ['godotengine', 'unity3d', 'nim_lang']] +] + +emoji = [ ['Tesla/status/1134850442511257600', '๐ŸŒˆโค๏ธ๐Ÿงก๐Ÿ’›๐Ÿ’š๐Ÿ’™๐Ÿ’œ'] ] -class TestTweet(BaseTestCase): - @parameterized.expand(timeline_tweets) - def test_timeline(self, index, fullname, username, date, text): +retweet = [ + [7, 'mobile_test_2', 'mobile test 2', 'Test account', '@mobile_test', '1234'], + [3, 'mobile_test_8', 'mobile test 8', 'jack ๐ŸŒ๐ŸŒ๐ŸŒŽ', '@jack', 'twttr'] +] + + +class TweetTest(BaseTestCase): + @parameterized.expand(timeline) + def test_timeline(self, index, fullname, username, date, tid, text): 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) + permalink = self.find_element(tweet.date + ' a') + self.assertIn(tid, permalink.get_attribute('href')) - @parameterized.expand(status_tweets) + @parameterized.expand(status) def test_status(self, tid, fullname, username, date, text): tweet = Tweet() self.open_nitter(f'{username}/status/{tid}') @@ -90,23 +94,39 @@ class TestTweet(BaseTestCase): self.assert_exact_text(date, tweet.date) self.assert_text(text, tweet.text) - @parameterized.expand(multiline_tweets) + @parameterized.expand(multiline) def test_multiline_formatting(self, tid, username, text): self.open_nitter(f'{username}/status/{tid}') self.assert_text(text.strip('\n'), '.main-tweet') - @parameterized.expand(emoji_tweets) - def test_emojis(self, tweet, text): + @parameterized.expand(emoji) + def test_emoji(self, tweet, text): self.open_nitter(tweet) self.assert_text(text, '.main-tweet') - @parameterized.expand(link_tweets) - def test_links(self, tweet, links): + @parameterized.expand(link) + def test_link(self, tweet, links): self.open_nitter(tweet) for link in links: self.assert_text(link, '.main-tweet') - @parameterized.expand(invalid_tweets) + @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) def test_invalid_id(self, tweet): self.open_nitter(tweet) self.assert_text('Tweet not found', '.error-panel')