Add animated_gif test scenario

This commit is contained in:
Sonny Bakker 2020-09-09 21:49:48 +02:00
parent 30ed1c13f9
commit d2dcd0fa7e
3 changed files with 39 additions and 3 deletions

View file

@ -1,5 +1,9 @@
# retrieved with:
# curl -X GET -H "Authorization: Bearer <TOKEN>" "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&tweet_mode=extended" | python3 -m json.tool --sort-keys
#
# see https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/overview/tweet-object
# and https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/overview/extended-entities-object
# for more information about tweet objects
simple_mock = [
{
@ -200,6 +204,8 @@ simple_mock = [
},
]
# contains tweets with "extended_entities" keys which contains native media objects
# which are in this case of the type "photo"
image_mock = [
{
"contributors": None,
@ -367,6 +373,8 @@ image_mock = [
}
]
# contains tweets with "extended_entities" keys which contains native media objects
# which are in this case of the type "video"
video_mock = [
{
"contributors": None,
@ -853,6 +861,7 @@ video_without_bitrate_mock = [
}
]
# contains tweets with "retweeted_status" keys containing the retweeted tweet
retweet_mock = [
{
"contributors": None,
@ -1774,6 +1783,8 @@ quoted_mock = [
},
]
# contains tweets with "extended_entities" keys which contains native media objects
# which are in this case of the type "animated_gif"
gif_mock = [
{
"contributors": None,

View file

@ -12,6 +12,7 @@ from ftfy import fix_text
from newsreader.news.collection.tests.factories import TwitterProfileFactory
from newsreader.news.collection.tests.twitter.builder.mocks import (
gif_mock,
image_mock,
simple_mock,
video_mock,
@ -175,9 +176,30 @@ class TwitterBuilderTestCase(TestCase):
count=1,
)
@skip("Not implemented")
def test_GIFs_in_post(self):
pass
builder = TwitterBuilder
profile = TwitterProfileFactory(screen_name="RobertsSpaceInd")
mock_stream = MagicMock(rule=profile)
with builder((gif_mock, mock_stream)) as builder:
builder.save()
posts = {post.remote_identifier: post for post in Post.objects.all()}
self.assertCountEqual(
("1289337776140296193", "1288965215648849920"), posts.keys()
)
post = posts["1289337776140296193"]
self.assertInHTML(
"""<div><video controls muted><source src="https://video.twimg.com/tweet_video/EeSl3sPUcAAyE4J.mp4" type="video/mp4" /></video></div>""",
post.body,
count=1,
)
self.assertIn("@Xenosystems https://t.co/wxvioLCJ6h", post.body)
@skip("Not implemented")
def test_retweet_post(self):

View file

@ -58,7 +58,10 @@ class TwitterBuilder(Builder):
body += html_fragment
elif media_type == TwitterPostTypeChoices.video:
elif media_type in (
TwitterPostTypeChoices.video,
TwitterPostTypeChoices.animated_gif,
):
meta_data = media_entity["video_info"]
videos = sorted(