From baa734b32e31f26aafba96992f43866b26729a69 Mon Sep 17 00:00:00 2001 From: Zed Date: Mon, 1 Jul 2019 07:12:46 +0200 Subject: [PATCH] Add thread/conversation tests --- tests/base.py | 10 ++++++++ tests/test_thread.py | 55 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tests/test_thread.py diff --git a/tests/base.py b/tests/base.py index 3337146..9d84916 100644 --- a/tests/base.py +++ b/tests/base.py @@ -28,6 +28,16 @@ class Timeline(object): protected = '.timeline-protected' +class Conversation(object): + main = '.main-tweet' + before = '.before-tweet' + after = '.after-tweet' + replies = '.replies' + thread = '.reply' + tweet = '.status-el' + tweet_text = '.status-content' + + class Poll(object): votes = '.poll-info' choice = '.poll-meter' diff --git a/tests/test_thread.py b/tests/test_thread.py new file mode 100644 index 0000000..0ea9a4a --- /dev/null +++ b/tests/test_thread.py @@ -0,0 +1,55 @@ +from base import BaseTestCase, Conversation +from parameterized import parameterized + +thread = [ + ['octonion/status/975253897697611777', [], 'Based', ['Crystal', 'Julia'], [ + ['For', 'Then', 'Okay,', 'Python', 'Speed', 'Java', 'Coding', 'I', 'more'], + ['yeah,'] + ]], + + ['octonion/status/975254452625002496', ['Based'], 'Crystal', ['Julia'], []], + + ['octonion/status/975256058384887808', ['Based', 'Crystal'], 'Julia', [], []], + + ['gauravssnl/status/975364889039417344', + ['Based', 'For', 'Then', 'Okay,', 'Python'], 'Speed', [], [ + ['Java', 'more'], ['JAVA!'] + ]], + + ['d0m96/status/1141811379407425537', [], 'I\'m', + ['The', 'The', 'Today', 'Some', 'If', 'There', 'Above'], + [['Thank', 'Also,', 'Awesome.', 'Thank']]], + + ['Nitrux_NX/status/1138643619550810112', [], '"The', [], + [['@bipin_joshi11', 'bc']]], + + ['gmpreussner/status/999766552546299904', [], 'A', [], + [['I'], ['I']]] +] + + +class ThreadTest(BaseTestCase): + def find_tweets(self, selector): + return self.find_elements(f"{selector} {Conversation.tweet_text}") + + def compare_first_word(self, tweets, selector): + if len(tweets) > 0: + self.assert_element_visible(selector) + for i, tweet in enumerate(self.find_tweets(selector)): + text = tweet.text.split(" ")[0] + self.assert_equal(tweets[i], text) + + @parameterized.expand(thread) + def test_thread(self, tweet, before, main, after, replies): + self.open_nitter(tweet) + self.assert_element_visible(Conversation.main) + + self.assert_text(main, Conversation.main) + self.assert_text(main, Conversation.main) + + self.compare_first_word(before, Conversation.before) + self.compare_first_word(after, Conversation.after) + + for i, reply in enumerate(self.find_elements(Conversation.thread)): + selector = Conversation.replies + f" > div:nth-child({i + 1})" + self.compare_first_word(replies[i], selector)