Пример #1
0
def test_graphql_to_attachment_video():
    data = {
        "__typename": "MessageVideo",
        "attribution_app": None,
        "attribution_metadata": None,
        "filename": "video-4321.mp4",
        "playable_url": "https://video-arn2-1.xx.fbcdn.net/v/video-4321.mp4",
        "chat_image": {
            "height": 96,
            "width": 168,
            "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/s168x128/1.jpg",
        },
        "legacy_attachment_id": "1234",
        "video_type": "FILE_ATTACHMENT",
        "original_dimensions": {
            "x": 640,
            "y": 368
        },
        "playable_duration_in_ms": 6000,
        "large_image": {
            "height": 368,
            "width": 640,
            "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/2.jpg",
        },
        "inbox_image": {
            "height": 260,
            "width": 452,
            "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/p261x260/3.jpg",
        },
    }
    assert VideoAttachment(
        id="1234",
        width=None,
        height=None,
        duration=datetime.timedelta(seconds=6),
        preview_url="https://video-arn2-1.xx.fbcdn.net/v/video-4321.mp4",
        previews={
            Image(
                url="https://scontent-arn2-1.xx.fbcdn.net/v/s168x128/1.jpg",
                width=168,
                height=96,
            ),
            Image(
                url="https://scontent-arn2-1.xx.fbcdn.net/v/p261x260/3.jpg",
                width=452,
                height=260,
            ),
            Image(
                url="https://scontent-arn2-1.xx.fbcdn.net/v/2.jpg",
                width=640,
                height=368,
            ),
        },
    ) == graphql_to_attachment(data)
Пример #2
0
def test_graphql_to_attachment_image2():
    data = {
        "__typename": "MessageAnimatedImage",
        "attribution_app": None,
        "attribution_metadata": None,
        "filename": "gif-1234",
        "animated_image": {
            "uri": "https://cdn.fbsbx.com/v/1.gif",
            "height": 128,
            "width": 128,
        },
        "legacy_attachment_id": "1234",
        "preview_image": {
            "uri": "https://cdn.fbsbx.com/v/1.gif",
            "height": 128,
            "width": 128,
        },
        "original_dimensions": {
            "x": 128,
            "y": 128
        },
    }
    assert ImageAttachment(
        id="1234",
        original_extension="gif",
        width=None,
        height=None,
        is_animated=True,
        previews={
            Image(url="https://cdn.fbsbx.com/v/1.gif", width=128, height=128)
        },
    ) == graphql_to_attachment(data)
Пример #3
0
def test_videoattachment_from_list():
    data = {
        "__typename": "MessageVideo",
        "id": "bWVzc2...",
        "legacy_attachment_id": "1234",
        "image": {
            "uri":
            "https://scontent-arn2-1.xx.fbcdn.net/v/t15.3394-10/p261x260/1.jpg"
        },
        "image1": {
            "height": 368,
            "width": 640,
            "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t15.3394-10/2.jpg",
        },
        "image2": {
            "height": 368,
            "width": 640,
            "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t15.3394-10/3.jpg",
        },
        "original_dimensions": {
            "x": 640,
            "y": 368
        },
    }
    assert VideoAttachment(
        id="1234",
        width=640,
        height=368,
        previews={
            Image(
                url=
                "https://scontent-arn2-1.xx.fbcdn.net/v/t15.3394-10/p261x260/1.jpg"
            ),
            Image(
                url="https://scontent-arn2-1.xx.fbcdn.net/v/t15.3394-10/2.jpg",
                width=640,
                height=368,
            ),
            Image(
                url="https://scontent-arn2-1.xx.fbcdn.net/v/t15.3394-10/3.jpg",
                width=640,
                height=368,
            ),
        },
    ) == VideoAttachment._from_list(data)
Пример #4
0
def test_graphql_to_attachment_image1():
    data = {
        "__typename": "MessageImage",
        "attribution_app": None,
        "attribution_metadata": None,
        "filename": "image-1234",
        "preview": {
            "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/1.png",
            "height": 128,
            "width": 128,
        },
        "large_preview": {
            "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/1.png",
            "height": 128,
            "width": 128,
        },
        "thumbnail": {
            "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/p50x50/2.png"
        },
        "photo_encodings": [],
        "legacy_attachment_id": "1234",
        "original_dimensions": {
            "x": 128,
            "y": 128
        },
        "original_extension": "png",
        "render_as_sticker": False,
        "blurred_image_uri": None,
    }
    assert ImageAttachment(
        id="1234",
        original_extension="png",
        width=None,
        height=None,
        is_animated=False,
        previews={
            Image(url="https://scontent-arn2-1.xx.fbcdn.net/v/p50x50/2.png"),
            Image(
                url="https://scontent-arn2-1.xx.fbcdn.net/v/1.png",
                width=128,
                height=128,
            ),
        },
    ) == graphql_to_attachment(data)
Пример #5
0
def test_imageattachment_from_list():
    data = {
        "__typename": "MessageImage",
        "id": "bWVzc2...",
        "legacy_attachment_id": "1234",
        "image": {
            "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/s261x260/1.jpg"
        },
        "image1": {
            "height": 463,
            "width": 960,
            "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/2.jpg",
        },
        "image2": {
            "height": 988,
            "width": 2048,
            "uri": "https://scontent-arn2-1.xx.fbcdn.net/v/s2048x2048/3.jpg",
        },
        "original_dimensions": {
            "x": 2833,
            "y": 1367
        },
        "photo_encodings": [],
    }
    assert ImageAttachment(
        id="1234",
        width=2833,
        height=1367,
        previews={
            Image(url="https://scontent-arn2-1.xx.fbcdn.net/v/s261x260/1.jpg"),
            Image(
                url="https://scontent-arn2-1.xx.fbcdn.net/v/2.jpg",
                width=960,
                height=463,
            ),
            Image(
                url="https://scontent-arn2-1.xx.fbcdn.net/v/s2048x2048/3.jpg",
                width=2048,
                height=988,
            ),
        },
    ) == ImageAttachment._from_list(data)
Пример #6
0
def test_share_from_graphql_link_with_image():
    data = {
        "description": {
            "text":
            ("Create an account or log in to Facebook."
             " Connect with friends, family and other people you know."
             " Share photos and videos, send messages and get updates.")
        },
        "media": {
            "animated_image": None,
            "image": {
                "uri": "https://www.facebook.com/rsrc.php/v3/x.png",
                "height": 325,
                "width": 325,
            },
            "playable_duration_in_ms": 0,
            "is_playable": False,
            "playable_url": None,
        },
        "source": None,
        "style_list": ["share", "fallback"],
        "title_with_entities": {
            "text": "Facebook – log in or sign up"
        },
        "properties": [],
        "url": "http://facebook.com/",
        "deduplication_key": "deadbeef123",
        "action_links": [],
        "messaging_attribution": None,
        "messenger_call_to_actions": [],
        "xma_layout_info": None,
        "target": {
            "__typename": "ExternalUrl"
        },
        "subattachments": [],
    }
    assert ShareAttachment(
        author=None,
        url="http://facebook.com/",
        original_url="http://facebook.com/",
        title="Facebook – log in or sign up",
        description=(
            "Create an account or log in to Facebook."
            " Connect with friends, family and other people you know."
            " Share photos and videos, send messages and get updates."),
        source=None,
        image=Image(url="https://www.facebook.com/rsrc.php/v3/x.png",
                    width=325,
                    height=325),
        original_image_url="https://www.facebook.com/rsrc.php/v3/x.png",
        attachments=[],
        id="deadbeef123",
    ) == ShareAttachment._from_graphql(data)
Пример #7
0
def test_location_attachment_from_graphql():
    data = {
        "description": {"text": ""},
        "media": {
            "animated_image": None,
            "image": {
                "uri": "https://external-arn2-1.xx.fbcdn.net/static_map.php?v=1020&osm_provider=2&size=545x280&zoom=15&markers=55.40000000%2C12.43220000&language=en",
                "height": 280,
                "width": 545,
            },
            "playable_duration_in_ms": 0,
            "is_playable": False,
            "playable_url": None,
        },
        "source": None,
        "style_list": ["message_location", "fallback"],
        "title_with_entities": {"text": "Your location"},
        "properties": [
            {"key": "width", "value": {"text": "545"}},
            {"key": "height", "value": {"text": "280"}},
        ],
        "url": "https://l.facebook.com/l.php?u=https%3A%2F%2Fwww.bing.com%2Fmaps%2Fdefault.aspx%3Fv%3D2%26pc%3DFACEBK%26mid%3D8100%26where1%3D55.4%252C%2B12.4322%26FORM%3DFBKPL1%26mkt%3Den-GB&h=a&s=1",
        "deduplication_key": "400828513928715",
        "action_links": [],
        "messaging_attribution": None,
        "messenger_call_to_actions": [],
        "xma_layout_info": None,
        "target": {"__typename": "MessageLocation"},
        "subattachments": [],
    }
    assert LocationAttachment(
        id=400828513928715,
        latitude=55.4,
        longitude=12.4322,
        image=Image(
            url="https://external-arn2-1.xx.fbcdn.net/static_map.php?v=1020&osm_provider=2&size=545x280&zoom=15&markers=55.40000000%2C12.43220000&language=en",
            width=545,
            height=280,
        ),
        url="https://l.facebook.com/l.php?u=https%3A%2F%2Fwww.bing.com%2Fmaps%2Fdefault.aspx%3Fv%3D2%26pc%3DFACEBK%26mid%3D8100%26where1%3D55.4%252C%2B12.4322%26FORM%3DFBKPL1%26mkt%3Den-GB&h=a&s=1",
    ) == LocationAttachment._from_graphql(data)
Пример #8
0
def test_graphql_to_subattachment_video():
    data = {
        "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-username/videos/1234/",
        "deduplication_key":
        "ddb7...",
        "action_links": [],
        "messaging_attribution":
        None,
        "messenger_call_to_actions": [],
        "xma_layout_info":
        None,
        "target": {
            "__typename": "Video",
            "video_id": "1234",
            "video_messenger_cta_payload": None,
        },
    }
    assert VideoAttachment(
        id="1234",
        duration=datetime.timedelta(seconds=24, microseconds=469000),
        preview_url="https://video-arn2-1.xx.fbcdn.net/v/t42.9040-2/vid.mp4",
        previews={
            Image(
                url=
                "https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg",
                width=960,
                height=540,
            )
        },
    ) == graphql_to_subattachment(data)
Пример #9
0
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=Image(
            url=
            "https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg",
            width=960,
            height=540,
        ),
        original_image_url=
        "https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg",
        attachments=[
            fbchat.VideoAttachment(
                id="2222",
                duration=datetime.timedelta(seconds=24, microseconds=469000),
                preview_url=
                "https://video-arn2-1.xx.fbcdn.net/v/t42.9040-2/vid.mp4",
                previews={
                    Image(
                        url=
                        "https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg",
                        width=960,
                        height=540,
                    )
                },
            )
        ],
        id="deadbeef123",
    ) == ShareAttachment._from_graphql(data)
Пример #10
0
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=Image(
            url="https://scontent-arn2-1.xx.fbcdn.net/v/t1.0-9/1.jpg",
            width=720,
            height=960,
        ),
        original_image_url=
        "https://scontent-arn2-1.xx.fbcdn.net/v/t1.0-9/1.jpg",
        attachments=[None],
        id="deadbeef123",
    ) == ShareAttachment._from_graphql(data)
Пример #11
0
def test_share_from_graphql_video():
    data = {
        "description": {
            "text":
            ("Rick Astley's official music video for “Never Gonna Give You Up”"
             " Listen to Rick Astley: https://RickAstley.lnk.to/_listenYD"
             " Subscribe to the official Rick As...")
        },
        "media": {
            "animated_image": None,
            "image": {
                "uri":
                ("https://external-arn2-1.xx.fbcdn.net/safe_image.php?d=xyz123"
                 "&w=960&h=540&url=https%3A%2F%2Fi.ytimg.com%2Fvi%2FdQw4w9WgXcQ"
                 "%2Fmaxresdefault.jpg&sx=0&sy=0&sw=1280&sh=720&_nc_hash=abc123"
                 ),
                "height":
                540,
                "width":
                960,
            },
            "playable_duration_in_ms": 0,
            "is_playable": True,
            "playable_url":
            "https://www.youtube.com/embed/dQw4w9WgXcQ?autoplay=1",
        },
        "source": {
            "text": "youtube.com"
        },
        "style_list": ["share", "fallback"],
        "title_with_entities": {
            "text": "Rick Astley - Never Gonna Give You Up (Video)"
        },
        "properties": [
            {
                "key": "width",
                "value": {
                    "text": "1280"
                }
            },
            {
                "key": "height",
                "value": {
                    "text": "720"
                }
            },
        ],
        "url":
        "https://l.facebook.com/l.php?u=https%3A%2F%2Fyoutu.be%2FdQw4w9WgXcQ",
        "deduplication_key":
        "ee.mid.$gAAT4Sw1WSGhzQ9uRWVtEpZHZ8ZPV",
        "action_links": [{
            "title": "About this website",
            "url": None
        }],
        "messaging_attribution":
        None,
        "messenger_call_to_actions": [],
        "xma_layout_info":
        None,
        "target": {
            "__typename": "ExternalUrl"
        },
        "subattachments": [],
    }
    assert ShareAttachment(
        author=None,
        url=
        "https://l.facebook.com/l.php?u=https%3A%2F%2Fyoutu.be%2FdQw4w9WgXcQ",
        original_url="https://youtu.be/dQw4w9WgXcQ",
        title="Rick Astley - Never Gonna Give You Up (Video)",
        description=(
            "Rick Astley's official music video for “Never Gonna Give You Up”"
            " Listen to Rick Astley: https://RickAstley.lnk.to/_listenYD"
            " Subscribe to the official Rick As..."),
        source="youtube.com",
        image=Image(
            url="https://external-arn2-1.xx.fbcdn.net/safe_image.php?d=xyz123"
            "&w=960&h=540&url=https%3A%2F%2Fi.ytimg.com%2Fvi%2FdQw4w9WgXcQ"
            "%2Fmaxresdefault.jpg&sx=0&sy=0&sw=1280&sh=720&_nc_hash=abc123",
            width=960,
            height=540,
        ),
        original_image_url=
        "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
        attachments=[],
        id="ee.mid.$gAAT4Sw1WSGhzQ9uRWVtEpZHZ8ZPV",
    ) == ShareAttachment._from_graphql(data)