Add tests for retweeted tweets & quoted tweets
This commit is contained in:
parent
d2dcd0fa7e
commit
cfe9c29a14
3 changed files with 71 additions and 14 deletions
|
|
@ -861,7 +861,8 @@ video_without_bitrate_mock = [
|
|||
}
|
||||
]
|
||||
|
||||
# contains tweets with "retweeted_status" keys containing the retweeted tweet
|
||||
# contains tweets with a "retweeted_status" key containing the retweeted tweet.
|
||||
# the "retweet" cannot add hashtags, URLs or other details, see https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/overview/entities-object#retweets-quote
|
||||
retweet_mock = [
|
||||
{
|
||||
"contributors": None,
|
||||
|
|
@ -1280,6 +1281,8 @@ retweet_mock = [
|
|||
},
|
||||
]
|
||||
|
||||
# contains tweets with a "quoted_status" key containing the quoted tweet.
|
||||
# quoted tweets can add hashtags, URL's and other details as it adds content "on top" of the quoted tweet see https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/overview/entities-object#retweets-quotes
|
||||
quoted_mock = [
|
||||
{
|
||||
"contributors": None,
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ from newsreader.news.collection.tests.factories import TwitterProfileFactory
|
|||
from newsreader.news.collection.tests.twitter.builder.mocks import (
|
||||
gif_mock,
|
||||
image_mock,
|
||||
quoted_mock,
|
||||
retweet_mock,
|
||||
simple_mock,
|
||||
video_mock,
|
||||
video_without_bitrate_mock,
|
||||
|
|
@ -201,25 +203,70 @@ class TwitterBuilderTestCase(TestCase):
|
|||
|
||||
self.assertIn("@Xenosystems https://t.co/wxvioLCJ6h", post.body)
|
||||
|
||||
@skip("Not implemented")
|
||||
def test_retweet_post(self):
|
||||
pass
|
||||
builder = TwitterBuilder
|
||||
|
||||
profile = TwitterProfileFactory(screen_name="RobertsSpaceInd")
|
||||
mock_stream = MagicMock(rule=profile)
|
||||
|
||||
with builder((retweet_mock, mock_stream)) as builder:
|
||||
builder.save()
|
||||
|
||||
posts = {post.remote_identifier: post for post in Post.objects.all()}
|
||||
|
||||
self.assertCountEqual(
|
||||
("1291117030486106112", "1288825524878336000"), posts.keys()
|
||||
)
|
||||
|
||||
post = posts["1291117030486106112"]
|
||||
|
||||
self.assertIn(
|
||||
fix_text(
|
||||
"RT @Narayan_N7: New video! #StarCitizen 3.9 vs. 3.10 comparison!\nSo,"
|
||||
" the patch 3.10 came out, which brought us quite a lot of changes!\ud83d\ude42\nPle\u2026"
|
||||
),
|
||||
post.body,
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
fix_text(
|
||||
"Original tweet: New video! #StarCitizen 3.9 vs. 3.10 comparison!\nSo, the patch"
|
||||
" 3.10 came out, which brought us quite a lot of changes!\ud83d\ude42\nPlease,"
|
||||
" share it with your friends!\ud83d\ude4f\n\nEnjoy watching and stay safe!"
|
||||
" \u2764\ufe0f\u263a\ufe0f\n@RobertsSpaceInd\n\n@CloudImperium\n\nhttps://t.co/j4QahHzbw4"
|
||||
),
|
||||
post.body,
|
||||
)
|
||||
|
||||
@skip("Not implemented")
|
||||
def test_quoted_post(self):
|
||||
pass
|
||||
builder = TwitterBuilder
|
||||
|
||||
@skip("Not implemented")
|
||||
def test_images_in_quoted_post(self):
|
||||
pass
|
||||
profile = TwitterProfileFactory(screen_name="RobertsSpaceInd")
|
||||
mock_stream = MagicMock(rule=profile)
|
||||
|
||||
@skip("Not implemented")
|
||||
def test_videos_in_quoted_post(self):
|
||||
pass
|
||||
with builder((quoted_mock, mock_stream)) as builder:
|
||||
builder.save()
|
||||
|
||||
@skip("Not implemented")
|
||||
def test_GIFs_in_quoted_post(self):
|
||||
pass
|
||||
posts = {post.remote_identifier: post for post in Post.objects.all()}
|
||||
|
||||
self.assertCountEqual(
|
||||
("1290801039075979264", "1289320160021495809"), posts.keys()
|
||||
)
|
||||
|
||||
post = posts["1290801039075979264"]
|
||||
|
||||
self.assertIn(
|
||||
fix_text("Bonne nuit \ud83c\udf3a\ud83d\udeeb https://t.co/WyznJwCJLp"),
|
||||
post.body,
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
fix_text(
|
||||
"Quoted tweet: #Starcitizen Le jeu est beau. Bonne nuit"
|
||||
" @RobertsSpaceInd https://t.co/xCXun68V3r"
|
||||
),
|
||||
post.body,
|
||||
)
|
||||
|
||||
@skip("Not implemented")
|
||||
def test_empty_data(self):
|
||||
|
|
|
|||
|
|
@ -84,6 +84,13 @@ class TwitterBuilder(Builder):
|
|||
)
|
||||
body += html_fragment
|
||||
|
||||
if "retweeted_status" in post:
|
||||
original_post = post["retweeted_status"]
|
||||
body += format_html(f"Original tweet: {original_post['full_text']}")
|
||||
if "quoted_status" in post:
|
||||
original_post = post["quoted_status"]
|
||||
body += format_html(f"Quoted tweet: {original_post['full_text']}")
|
||||
|
||||
body += format_html(post["full_text"])
|
||||
|
||||
data = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue