From af167ddef4d8d18cd8b5e26c871ebd8704893b6d Mon Sep 17 00:00:00 2001 From: Zed Date: Mon, 1 Jul 2019 00:29:40 +0200 Subject: [PATCH] Add media tests --- tests/base.py | 8 ++++ tests/test_tweet_media.py | 83 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/tests/base.py b/tests/base.py index f1cbb25..3337146 100644 --- a/tests/base.py +++ b/tests/base.py @@ -36,6 +36,14 @@ class Poll(object): leader = 'leader' +class Media(object): + container = '.attachments' + row = '.gallery-row' + image = '.still-image' + video = '.gallery-video' + gif = '.gallery-gif' + + class BaseTestCase(BaseCase): def setUp(self): super(BaseTestCase, self).setUp() diff --git a/tests/test_tweet_media.py b/tests/test_tweet_media.py index 7074c89..a7e0d37 100644 --- a/tests/test_tweet_media.py +++ b/tests/test_tweet_media.py @@ -1,4 +1,4 @@ -from base import BaseTestCase, Poll +from base import BaseTestCase, Poll, Media from parameterized import parameterized poll = [ @@ -11,6 +11,37 @@ poll = [ ]] ] +image = [ + ['mobile_test/status/519364660823207936', 'BzUnaDFCUAAmrjs'], + ['mobile_test_2/status/324619691039543297', 'BIFH45vCUAAQecj'] +] + +gif = [ + ['hot_pengu/status/1142904127594401797', 'D9xpM5eW4AIXfUl'], + ['Proj_Borealis/status/1136595194621677568', 'D8X_PJAXUAAavPT'] +] + +video_m3u8 = [ + ['d0m96/status/1078373829917974528', '9q1-v9w8-ft3awgD.jpg'], + ['SpaceX/status/1138474014152712192', 'ocJJj2uu4n1kyD2Y.jpg'] +] + +gallery = [ + ['mobile_test/status/451108446603980803', [ + ['BkKovdrCUAAEz79', 'BkKovdcCEAAfoBO'] + ]], + + ['mobile_test/status/471539824713691137', [ + ['Bos--KNIQAAA7Li', 'Bos--FAIAAAWpah'], + ['Bos--IqIQAAav23'] + ]], + + ['mobile_test/status/469530783384743936', [ + ['BoQbwJAIUAA0QCY', 'BoQbwN1IMAAuTiP'], + ['BoQbwarIAAAlaE-', 'BoQbwh_IEAA27ef'] + ]] +] + class MediaTest(BaseTestCase): @parameterized.expand(poll) @@ -20,9 +51,7 @@ class MediaTest(BaseTestCase): self.assert_text(votes, Poll.votes) poll_choices = self.find_elements(Poll.choice) - for i in range(len(choices)): - v, o = choices[i] - + for i, (v, o) in enumerate(choices): choice = poll_choices[i] value = choice.find_element_by_class_name(Poll.value) option = choice.find_element_by_class_name(Poll.option) @@ -35,3 +64,49 @@ class MediaTest(BaseTestCase): self.assertIn(Poll.leader, choice_class) else: self.assertNotIn(Poll.leader, choice_class) + + @parameterized.expand(image) + def test_image(self, tweet, url): + self.open_nitter(tweet) + self.assert_element_visible(Media.container) + self.assert_element_visible(Media.image) + + image_url = self.get_image_url(Media.image + ' img') + self.assertIn(url, image_url) + + @parameterized.expand(gif) + def test_gif(self, tweet, gif_id): + self.open_nitter(tweet) + self.assert_element_visible(Media.container) + self.assert_element_visible(Media.gif) + + url = self.get_attribute('source', 'src') + thumb = self.get_attribute('video', 'poster') + self.assertIn(gif_id + '.mp4', url) + self.assertIn(gif_id + '.jpg', thumb) + + @parameterized.expand(video_m3u8) + def test_video_m3u8(self, tweet, thumb): + # no url because video playback isn't supported yet + self.open_nitter(tweet) + self.assert_element_visible(Media.container) + self.assert_element_visible(Media.video) + + video_thumb = self.get_attribute('video', 'poster') + self.assertIn(thumb, video_thumb) + + @parameterized.expand(gallery) + def test_gallery(self, tweet, rows): + self.open_nitter(tweet) + self.assert_element_visible(Media.container) + self.assert_element_visible(Media.row) + self.assert_element_visible(Media.image) + + gallery_rows = self.find_elements(Media.row) + self.assert_equal(len(rows), len(gallery_rows)) + + for i, row in enumerate(gallery_rows): + images = row.find_elements_by_css_selector('img') + self.assert_equal(len(rows[i]), len(images)) + for j, image in enumerate(images): + self.assertIn(rows[i][j], image.get_attribute('src'))