From 6176c6f66835b24c6be8b6924fba2c49ce01bab4 Mon Sep 17 00:00:00 2001 From: Zed Date: Sun, 30 Jun 2019 00:53:07 +0200 Subject: [PATCH] Add poll test --- public/style.css | 2 ++ tests/base.py | 8 ++++++++ tests/test_tweet_media.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 tests/test_tweet_media.py diff --git a/public/style.css b/public/style.css index 6cd3b86..35622a8 100644 --- a/public/style.css +++ b/public/style.css @@ -769,6 +769,8 @@ video { font-weight: bold; margin-left: 5px; margin-right: 6px; + min-width: 30px; + text-align: right; } .poll-choice-option { diff --git a/tests/base.py b/tests/base.py index f106f43..f1cbb25 100644 --- a/tests/base.py +++ b/tests/base.py @@ -28,6 +28,14 @@ class Timeline(object): protected = '.timeline-protected' +class Poll(object): + votes = '.poll-info' + choice = '.poll-meter' + value = 'poll-choice-value' + option = 'poll-choice-option' + leader = 'leader' + + class BaseTestCase(BaseCase): def setUp(self): super(BaseTestCase, self).setUp() diff --git a/tests/test_tweet_media.py b/tests/test_tweet_media.py new file mode 100644 index 0000000..7074c89 --- /dev/null +++ b/tests/test_tweet_media.py @@ -0,0 +1,37 @@ +from base import BaseTestCase, Poll +from parameterized import parameterized + +poll = [ + ['nim_lang/status/1064219801499955200', 'Style insensitivity', '91', 1, [ + ('47%', 'Yay'), ('53%', 'Nay') + ]], + + ['polls/status/1031986180622049281', 'What Tree Is Coolest?', '3,322', 1, [ + ('30%', 'Oak'), ('42%', 'Bonsai'), ('5%', 'Hemlock'), ('23%', 'Apple') + ]] +] + + +class MediaTest(BaseTestCase): + @parameterized.expand(poll) + def test_poll(self, tweet, text, votes, leader, choices): + self.open_nitter(tweet) + self.assert_text(text, '.main-tweet') + self.assert_text(votes, Poll.votes) + + poll_choices = self.find_elements(Poll.choice) + for i in range(len(choices)): + v, o = choices[i] + + choice = poll_choices[i] + value = choice.find_element_by_class_name(Poll.value) + option = choice.find_element_by_class_name(Poll.option) + choice_class = choice.get_attribute('class') + + self.assert_equal(v, value.text) + self.assert_equal(o, option.text) + + if i == leader: + self.assertIn(Poll.leader, choice_class) + else: + self.assertNotIn(Poll.leader, choice_class)