From 6150f5234298d6b3ea57f7c5ad8f325fcc261549 Mon Sep 17 00:00:00 2001 From: Zed Date: Fri, 28 Jun 2019 19:18:52 +0200 Subject: [PATCH] Use test paramerization --- tests/test_profile.py | 70 ++++++++++++--------- tests/test_search.py | 11 ++-- tests/test_tweet.py | 141 ++++++++++++++++++++++-------------------- 3 files changed, 121 insertions(+), 101 deletions(-) diff --git a/tests/test_profile.py b/tests/test_profile.py index 7c7427c..15a6595 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -1,44 +1,56 @@ from base import BaseTestCase, Profile +from parameterized import parameterized + +profiles = [ + ['Test account', 'mobile_test', + 'Test Account. test test Testing username with @mobile_test_2 and a #hashtag'], + ['mobile test 2', 'mobile_test_2', ''] +] + +verified = [['jack'], ['elonmusk']] + +protected = [ + ['mobile test 7', 'mobile_test_7', ''], + ['Randy', 'Poop', 'Social media fanatic.'] +] + +invalid = [['thisprofiledoesntexist'], ['%']] class TestProfile(BaseTestCase): - def test_data(self): - self.open_nitter('mobile_test') - self.assert_exact_text('Test account', Profile.fullname) - self.assert_exact_text('@mobile_test', Profile.username) - self.assert_exact_text('Test Account. test test Testing username with @mobile_test_2 and a #hashtag', - Profile.bio) + @parameterized.expand(profiles) + def test_data(self, fullname, username, bio): + self.open_nitter(username) + self.assert_exact_text(fullname, Profile.fullname) + self.assert_exact_text(f'@{username}', Profile.username) - self.open_nitter('mobile_test_2') - self.assert_exact_text('mobile test 2', Profile.fullname) - self.assert_exact_text('@mobile_test_2', Profile.username) - self.assert_element_not_visible(Profile.bio) + if len(bio) > 0: + self.assert_exact_text(bio, Profile.bio) + else: + self.assert_element_absent(Profile.bio) - def test_verified(self): - self.open_nitter('jack') + @parameterized.expand(verified) + def test_verified(self, username): + self.open_nitter(username) self.assert_element_visible(Profile.verified) - self.open_nitter('elonmusk') - self.assert_element_visible(Profile.verified) - - def test_protected(self): - self.open_nitter('mobile_test_7') + @parameterized.expand(protected) + def test_protected(self, fullname, username, bio): + self.open_nitter(username) self.assert_element_visible(Profile.protected) - self.assert_exact_text('mobile test 7', Profile.fullname) - self.assert_exact_text('@mobile_test_7', Profile.username) + self.assert_exact_text(fullname, Profile.fullname) + self.assert_exact_text(f'@{username}', Profile.username) self.assert_text('Tweets are protected') - self.open_nitter('poop') - self.assert_element_visible(Profile.protected) - self.assert_exact_text('Randy', Profile.fullname) - self.assert_exact_text('@Poop', Profile.username) - self.assert_text('Social media fanatic.', Profile.bio) - self.assert_text('Tweets are protected') + if len(bio) > 0: + self.assert_text(bio, Profile.bio) + else: + self.assert_element_absent(Profile.bio) - def test_invalid_username(self): - for p in ['test', 'thisprofiledoesntexist', '%']: - self.open_nitter(p) - self.assert_text(f'User "{p}" not found') + @parameterized.expand(invalid) + def test_invalid_username(self, username): + self.open_nitter(username) + self.assert_text(f'User "{username}" not found') def test_suspended(self): # TODO: detect suspended diff --git a/tests/test_search.py b/tests/test_search.py index 6bb24d9..1ba434c 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1,10 +1,9 @@ from base import BaseTestCase +from parameterized import parameterized class TestSearch(BaseTestCase): - def test_username_search(self): - self.search_username('mobile_test') - self.assert_text('@mobile_test') - - self.search_username('mobile_test_2') - self.assert_text('@mobile_test_2') + @parameterized.expand([['mobile_test'], ['mobile_test_2']]) + def test_username_search(self, username): + self.search_username(username) + self.assert_text(f'@{username}') diff --git a/tests/test_tweet.py b/tests/test_tweet.py index 662799d..fb0b4bb 100644 --- a/tests/test_tweet.py +++ b/tests/test_tweet.py @@ -1,103 +1,112 @@ from base import BaseTestCase, Tweet, get_timeline_tweet +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') -class TweetInfo(): - def __init__(self, index, fullname, username, date, text): - self.index = index - self.fullname = fullname - self.username = username - self.date = date - self.text = text timeline_tweets = [ - TweetInfo(1, 'Test account', 'mobile_test', '10 Aug 2016', - '.'), + [1, 'Test account', 'mobile_test', '10 Aug 2016', + '.'], - TweetInfo(3, 'Test account', 'mobile_test', '3 Mar 2016', - 'LIVE on #Periscope pscp.tv/w/aadiTzF6dkVOTXZSbX…'), + [3, 'Test account', 'mobile_test', '3 Mar 2016', + 'LIVE on #Periscope pscp.tv/w/aadiTzF6dkVOTXZSbX…'], - TweetInfo(6, 'mobile test 2', 'mobile_test_2', '1 Oct 2014', - 'Testing. One two three four. Test.') + [6, 'mobile test 2', 'mobile_test_2', '1 Oct 2014', + 'Testing. One two three four. Test.'] ] status_tweets = [ - TweetInfo(20, 'jack 🌍🌏🌎', 'jack', '21 Mar 2006', - 'just setting up my twttr'), + [20, 'jack 🌍🌏🌎', 'jack', '21 Mar 2006', + 'just setting up my twttr'], - TweetInfo(134849778302464000, 'The Twoffice', 'TheTwoffice', '10 Nov 2011', - 'test'), + [134849778302464000, 'The Twoffice', 'TheTwoffice', '10 Nov 2011', + 'test'], - TweetInfo(105685475985080322, 'The Twoffice', 'TheTwoffice', '22 Aug 2011', - 'regular tweet'), + [105685475985080322, 'The Twoffice', 'TheTwoffice', '22 Aug 2011', + 'regular tweet'], - TweetInfo(572593440719912960, 'Test account', 'mobile_test', '2 Mar 2015', - 'testing test') + [572593440719912960, 'Test account', 'mobile_test', '2 Mar 2015', + 'testing test'] ] invalid_tweets = [ - 'mobile_test/status/120938109238', - 'TheTwoffice/status/8931928312' + ['mobile_test/status/120938109238'], + ['TheTwoffice/status/8931928312'] ] multiline_tweets = [ - TweetInfo(1142904127594401797, '', 'hot_pengu', '', - """ + [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: @exelotl - #pixelart #gbadev #gba #indiedev"""), + #pixelart #gbadev #gba #indiedev"""], - TweetInfo(400897186990284800, '', 'mobile_test_3', '', - """ + [400897186990284800, 'mobile_test_3', + """ ♔ KEEP CALM AND CLICHÉ - ON""") + ON"""] +] + +link_tweets = [ + ['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 = [ + ['Tesla/status/1134850442511257600', '🌈❤️🧡💛💚💙💜'] ] class TestTweet(BaseTestCase): - def test_timeline(self): - for info in timeline_tweets: - self.open_nitter(f'{info.username}') - tweet = get_timeline_tweet(info.index) - self.assert_exact_text(info.fullname, tweet.fullname) - self.assert_exact_text('@' + info.username, tweet.username) - self.assert_exact_text(info.date, tweet.date) - self.assert_text(info.text, tweet.text) + @parameterized.expand(timeline_tweets) + def test_timeline(self, index, fullname, username, date, 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) - def test_status(self): + @parameterized.expand(status_tweets) + def test_status(self, tid, fullname, username, date, text): tweet = Tweet() - for info in status_tweets: - self.open_nitter(f'{info.username}/status/{info.index}') - self.assert_exact_text(info.fullname, tweet.fullname) - self.assert_exact_text('@' + info.username, tweet.username) - self.assert_exact_text(info.date, tweet.date) - self.assert_text(info.text, tweet.text) + 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) - def test_multiline_formatting(self): - for info in multiline_tweets: - self.open_nitter(f'{info.username}/status/{info.index}') - self.assert_text(info.text.strip('\n'), '.main-tweet') + @parameterized.expand(multiline_tweets) + def test_multiline_formatting(self, tid, username, text): + self.open_nitter(f'{username}/status/{tid}') + self.assert_text(text.strip('\n'), '.main-tweet') - def test_emojis(self): - self.open_nitter('Tesla/status/1134850442511257600') - self.assert_text('🌈❤️🧡💛💚💙💜', '.main-tweet') + @parameterized.expand(emoji_tweets) + def test_emojis(self, tweet, text): + self.open_nitter(tweet) + self.assert_text(text, '.main-tweet') - def test_links(self): - self.open_nitter('nim_lang/status/1110499584852353024') - self.assert_text('nim-lang.org/araq/ownedrefs.…', '.main-tweet') - self.assert_text('news.ycombinator.com/item?id…', '.main-tweet') - self.assert_text('old.reddit.com/r/programming…', '.main-tweet') + @parameterized.expand(link_tweets) + def test_links(self, tweet, links): + self.open_nitter(tweet) + for link in links: + self.assert_text(link, '.main-tweet') - self.open_nitter('nim_lang/status/1125887775151140864') - self.assert_text('en.wikipedia.org/wiki/Nim_(p…)', '.main-tweet') - - self.open_nitter('hiankun_taioan/status/1086916335215341570') - self.assert_text('(hackernoon.com/interview-wit…)', '.main-tweet') - - def test_invalid_id(self): - for tweet in invalid_tweets: - self.open_nitter(tweet) - self.assert_text('Tweet not found', '.error-panel') + @parameterized.expand(invalid_tweets) + def test_invalid_id(self, tweet): + self.open_nitter(tweet) + self.assert_text('Tweet not found', '.error-panel')