Add ShareAttachment subattachment tests

This commit is contained in:
Mads Marquart
2019-10-28 10:33:45 +01:00
parent 80c7fff571
commit 41a445a989

View File

@@ -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)