From 41a445a989c6ffd661c1ec6618d36e4c6e85b1c6 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 28 Oct 2019 10:33:45 +0100 Subject: [PATCH] Add ShareAttachment subattachment tests --- tests/test_attachment.py | 257 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) diff --git a/tests/test_attachment.py b/tests/test_attachment.py index 52ae3e5..f94d6ca 100644 --- a/tests/test_attachment.py +++ b/tests/test_attachment.py @@ -1,4 +1,5 @@ import pytest +import datetime import fbchat from fbchat._attachment import UnsentMessage, ShareAttachment @@ -197,3 +198,259 @@ def test_share_from_graphql_video(): attachments=[], uid="ee.mid.$gAAT4Sw1WSGhzQ9uRWVtEpZHZ8ZPV", ) == ShareAttachment._from_graphql(data) + + +def test_share_with_image_subattachment(): + data = { + "description": {"text": "Abc"}, + "media": { + "animated_image": None, + "image": { + "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t1.0-9/1.jpg", + "height": 960, + "width": 720, + }, + "playable_duration_in_ms": 0, + "is_playable": False, + "playable_url": None, + }, + "source": {"text": "Def"}, + "style_list": ["attached_story", "fallback"], + "title_with_entities": {"text": ""}, + "properties": [], + "url": "https://www.facebook.com/groups/11223344/permalink/1234/", + "deduplication_key": "deadbeef123", + "action_links": [ + {"title": None, "url": None}, + {"title": None, "url": "https://www.facebook.com/groups/11223344/"}, + { + "title": "Report Post to Admin", + "url": "https://www.facebook.com/groups/11223344/members/", + }, + ], + "messaging_attribution": None, + "messenger_call_to_actions": [], + "xma_layout_info": None, + "target": { + "__typename": "Story", + "title": None, + "description": {"text": "Abc"}, + "actors": [ + { + "__typename": "User", + "name": "Def", + "id": "1111", + "short_name": "Def", + "url": "https://www.facebook.com/some-user", + "profile_picture": { + "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t1.0-1/c123.123.123.123a/s50x50/img.jpg", + "height": 50, + "width": 50, + }, + } + ], + "to": { + "__typename": "Group", + "name": "Some group", + "url": "https://www.facebook.com/groups/11223344/", + }, + "attachments": [ + { + "url": "https://www.facebook.com/photo.php?fbid=4321&set=gm.1234&type=3", + "media": { + "is_playable": False, + "image": { + "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t1.0-9/1.jpg", + "height": 960, + "width": 720, + }, + }, + } + ], + "attached_story": None, + }, + "subattachments": [ + { + "description": {"text": "Abc"}, + "media": { + "animated_image": None, + "image": { + "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t1.0-9/1.jpg", + "height": 960, + "width": 720, + }, + "playable_duration_in_ms": 0, + "is_playable": False, + "playable_url": None, + }, + "source": None, + "style_list": ["photo", "games_app", "fallback"], + "title_with_entities": {"text": ""}, + "properties": [ + {"key": "photoset_reference_token", "value": {"text": "gm.1234"}}, + {"key": "layout_x", "value": {"text": "0"}}, + {"key": "layout_y", "value": {"text": "0"}}, + {"key": "layout_w", "value": {"text": "0"}}, + {"key": "layout_h", "value": {"text": "0"}}, + ], + "url": "https://www.facebook.com/photo.php?fbid=4321&set=gm.1234&type=3", + "deduplication_key": "deadbeef456", + "action_links": [], + "messaging_attribution": None, + "messenger_call_to_actions": [], + "xma_layout_info": None, + "target": {"__typename": "Photo"}, + } + ], + } + assert ShareAttachment( + author="1111", + url="https://www.facebook.com/groups/11223344/permalink/1234/", + original_url="https://www.facebook.com/groups/11223344/permalink/1234/", + title="", + description="Abc", + source="Def", + image_url="https://scontent-arn2-1.xx.fbcdn.net/v/t1.0-9/1.jpg", + original_image_url="https://scontent-arn2-1.xx.fbcdn.net/v/t1.0-9/1.jpg", + image_width=720, + image_height=960, + attachments=[None], + uid="deadbeef123", + ) == ShareAttachment._from_graphql(data) + + +def test_share_with_video_subattachment(): + data = { + "description": {"text": "Abc"}, + "media": { + "animated_image": None, + "image": { + "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg", + "height": 540, + "width": 960, + }, + "playable_duration_in_ms": 24469, + "is_playable": True, + "playable_url": "https://video-arn2-1.xx.fbcdn.net/v/t42.9040-2/vid.mp4", + }, + "source": {"text": "Def"}, + "style_list": ["attached_story", "fallback"], + "title_with_entities": {"text": ""}, + "properties": [], + "url": "https://www.facebook.com/groups/11223344/permalink/1234/", + "deduplication_key": "deadbeef123", + "action_links": [ + {"title": None, "url": None}, + {"title": None, "url": "https://www.facebook.com/groups/11223344/"}, + {"title": None, "url": None}, + {"title": "A watch party is currently playing this video.", "url": None}, + ], + "messaging_attribution": None, + "messenger_call_to_actions": [], + "xma_layout_info": None, + "target": { + "__typename": "Story", + "title": None, + "description": {"text": "Abc"}, + "actors": [ + { + "__typename": "User", + "name": "Def", + "id": "1111", + "short_name": "Def", + "url": "https://www.facebook.com/some-user", + "profile_picture": { + "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t1.0-1/c1.0.50.50a/p50x50/profile.jpg", + "height": 50, + "width": 50, + }, + } + ], + "to": { + "__typename": "Group", + "name": "Some group", + "url": "https://www.facebook.com/groups/11223344/", + }, + "attachments": [ + { + "url": "https://www.facebook.com/some-user/videos/2222/", + "media": { + "is_playable": True, + "image": { + "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg", + "height": 540, + "width": 960, + }, + }, + } + ], + "attached_story": None, + }, + "subattachments": [ + { + "description": None, + "media": { + "animated_image": None, + "image": { + "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg", + "height": 540, + "width": 960, + }, + "playable_duration_in_ms": 24469, + "is_playable": True, + "playable_url": "https://video-arn2-1.xx.fbcdn.net/v/t42.9040-2/vid.mp4", + }, + "source": None, + "style_list": [ + "video_autoplay", + "video_inline", + "video", + "games_app", + "fallback", + ], + "title_with_entities": {"text": ""}, + "properties": [ + { + "key": "can_autoplay_result", + "value": {"text": "ugc_default_allowed"}, + } + ], + "url": "https://www.facebook.com/some-user/videos/2222/", + "deduplication_key": "deadbeef456", + "action_links": [], + "messaging_attribution": None, + "messenger_call_to_actions": [], + "xma_layout_info": None, + "target": { + "__typename": "Video", + "video_id": "2222", + "video_messenger_cta_payload": None, + }, + } + ], + } + assert ShareAttachment( + author="1111", + url="https://www.facebook.com/groups/11223344/permalink/1234/", + original_url="https://www.facebook.com/groups/11223344/permalink/1234/", + title="", + description="Abc", + source="Def", + image_url="https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg", + original_image_url="https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg", + image_width=960, + image_height=540, + attachments=[ + fbchat.VideoAttachment( + uid="2222", + duration=datetime.timedelta(seconds=24, microseconds=469000), + preview_url="https://video-arn2-1.xx.fbcdn.net/v/t42.9040-2/vid.mp4", + medium_image={ + "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg", + "width": 960, + "height": 540, + }, + ) + ], + uid="deadbeef123", + ) == ShareAttachment._from_graphql(data)