Add Image model

This commit is contained in:
Mads Marquart
2019-10-28 11:21:46 +01:00
parent 074c271fb8
commit 637ea97ffe
16 changed files with 207 additions and 276 deletions

View File

@@ -72,10 +72,8 @@ def test_share_from_graphql_link():
title="a.com",
description="",
source="a.com",
image_url=None,
image=None,
original_image_url=None,
image_width=None,
image_height=None,
attachments=[],
uid="ee.mid.$xyz",
) == ShareAttachment._from_graphql(data)
@@ -125,10 +123,10 @@ def test_share_from_graphql_link_with_image():
" Share photos and videos, send messages and get updates."
),
source=None,
image_url="https://www.facebook.com/rsrc.php/v3/x.png",
image=fbchat.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",
image_width=325,
image_height=325,
attachments=[],
uid="deadbeef123",
) == ShareAttachment._from_graphql(data)
@@ -187,14 +185,14 @@ def test_share_from_graphql_video():
" Subscribe to the official Rick As..."
),
source="youtube.com",
image_url=(
"https://external-arn2-1.xx.fbcdn.net/safe_image.php?d=xyz123"
image=fbchat.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"
"%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",
image_width=960,
image_height=540,
attachments=[],
uid="ee.mid.$gAAT4Sw1WSGhzQ9uRWVtEpZHZ8ZPV",
) == ShareAttachment._from_graphql(data)
@@ -310,10 +308,12 @@ def test_share_with_image_subattachment():
title="",
description="Abc",
source="Def",
image_url="https://scontent-arn2-1.xx.fbcdn.net/v/t1.0-9/1.jpg",
image=fbchat.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",
image_width=720,
image_height=960,
attachments=[None],
uid="deadbeef123",
) == ShareAttachment._from_graphql(data)
@@ -436,20 +436,22 @@ def test_share_with_video_subattachment():
title="",
description="Abc",
source="Def",
image_url="https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg",
image=fbchat.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",
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,
},
medium_image=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg",
width=960,
height=540,
),
)
],
uid="deadbeef123",

View File

@@ -33,17 +33,17 @@ def test_imageattachment_from_list():
uid="1234",
width=2833,
height=1367,
thumbnail_url="https://scontent-arn2-1.xx.fbcdn.net/v/s261x260/1.jpg",
preview={
"uri": "https://scontent-arn2-1.xx.fbcdn.net/v/2.jpg",
"width": 960,
"height": 463,
},
large_preview={
"uri": "https://scontent-arn2-1.xx.fbcdn.net/v/s2048x2048/3.jpg",
"width": 2048,
"height": 988,
},
thumbnail=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/s261x260/1.jpg"
),
preview=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/2.jpg", width=960, height=463
),
large_preview=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/s2048x2048/3.jpg",
width=2048,
height=988,
),
) == ImageAttachment._from_list({"node": data})
@@ -71,19 +71,19 @@ def test_videoattachment_from_list():
uid="1234",
width=640,
height=368,
small_image={
"uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t15.3394-10/p261x260/1.jpg"
},
medium_image={
"uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t15.3394-10/2.jpg",
"width": 640,
"height": 368,
},
large_image={
"uri": "https://scontent-arn2-1.xx.fbcdn.net/v/t15.3394-10/3.jpg",
"width": 640,
"height": 368,
},
small_image=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/t15.3394-10/p261x260/1.jpg"
),
medium_image=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/t15.3394-10/2.jpg",
width=640,
height=368,
),
large_image=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/t15.3394-10/3.jpg",
width=640,
height=368,
),
) == VideoAttachment._from_list({"node": data})
@@ -170,17 +170,15 @@ def test_graphql_to_attachment_image1():
width=None,
height=None,
is_animated=False,
thumbnail_url="https://scontent-arn2-1.xx.fbcdn.net/v/p50x50/3.png",
preview={
"uri": "https://scontent-arn2-1.xx.fbcdn.net/v/1.png",
"width": 128,
"height": 128,
},
large_preview={
"uri": "https://scontent-arn2-1.xx.fbcdn.net/v/2.png",
"width": 128,
"height": 128,
},
thumbnail=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/p50x50/3.png"
),
preview=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/1.png", width=128, height=128
),
large_preview=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/2.png", width=128, height=128
),
) == graphql_to_attachment(data)
@@ -209,12 +207,12 @@ def test_graphql_to_attachment_image2():
width=None,
height=None,
is_animated=True,
preview={"uri": "https://cdn.fbsbx.com/v/1.gif", "width": 128, "height": 128},
animated_preview={
"uri": "https://cdn.fbsbx.com/v/1.gif",
"width": 128,
"height": 128,
},
preview=fbchat.Image(
url="https://cdn.fbsbx.com/v/1.gif", width=128, height=128
),
animated_preview=fbchat.Image(
url="https://cdn.fbsbx.com/v/1.gif", width=128, height=128
),
) == graphql_to_attachment(data)
@@ -251,21 +249,19 @@ def test_graphql_to_attachment_video():
height=None,
duration=datetime.timedelta(seconds=6),
preview_url="https://video-arn2-1.xx.fbcdn.net/v/video-4321.mp4",
small_image={
"uri": "https://scontent-arn2-1.xx.fbcdn.net/v/s168x128/1.jpg",
"width": 168,
"height": 96,
},
medium_image={
"uri": "https://scontent-arn2-1.xx.fbcdn.net/v/p261x260/3.jpg",
"width": 452,
"height": 260,
},
large_image={
"uri": "https://scontent-arn2-1.xx.fbcdn.net/v/2.jpg",
"width": 640,
"height": 368,
},
small_image=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/s168x128/1.jpg",
width=168,
height=96,
),
medium_image=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/p261x260/3.jpg",
width=452,
height=260,
),
large_image=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/2.jpg", width=640, height=368
),
) == graphql_to_attachment(data)
@@ -350,9 +346,9 @@ def test_graphql_to_subattachment_video():
uid="1234",
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,
},
medium_image=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/t15.5256-10/p180x540/1.jpg",
width=960,
height=540,
),
) == graphql_to_subattachment(data)

View File

@@ -1,5 +1,6 @@
import pytest
import datetime
import fbchat
from fbchat._location import LocationAttachment, LiveLocationAttachment
@@ -34,9 +35,11 @@ def test_location_attachment_from_graphql():
"subattachments": [],
}
expected = LocationAttachment(latitude=55.4, longitude=12.4322, uid=400828513928715)
expected.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"
expected.image_width = 545
expected.image_height = 280
expected.image = fbchat.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,
)
expected.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"
assert expected == LocationAttachment._from_graphql(data)

View File

@@ -1,3 +1,4 @@
import fbchat
from fbchat._page import Page
@@ -12,7 +13,7 @@ def test_page_from_graphql():
}
assert Page(
uid="123456",
photo="https://scontent-arn2-1.xx.fbcdn.net/v/...",
photo=fbchat.Image(url="https://scontent-arn2-1.xx.fbcdn.net/v/..."),
name="Some school",
url="https://www.facebook.com/some-school/",
city=None,

View File

@@ -1,4 +1,5 @@
import pytest
import fbchat
from fbchat._sticker import Sticker
@@ -20,9 +21,11 @@ def test_from_graphql_normal():
frames_per_row=None,
frames_per_col=None,
frame_rate=None,
url="https://scontent-arn2-1.xx.fbcdn.net/v/redacted.png",
width=274,
height=274,
image=fbchat.Image(
url="https://scontent-arn2-1.xx.fbcdn.net/v/redacted.png",
width=274,
height=274,
),
label="Like, thumbs up",
) == Sticker._from_graphql(
{
@@ -54,9 +57,11 @@ def test_from_graphql_animated():
frames_per_row=2,
frames_per_col=2,
frame_rate=142,
url="https://scontent-arn2-1.fbcdn.net/v/redacted1.png",
width=240,
height=293,
image=fbchat.Image(
url="https://scontent-arn2-1.fbcdn.net/v/redacted1.png",
width=240,
height=293,
),
label="Love, cat with heart",
) == Sticker._from_graphql(
{

View File

@@ -1,5 +1,6 @@
import pytest
import datetime
import fbchat
from fbchat._user import User, ActiveStatus
@@ -17,7 +18,7 @@ def test_user_from_graphql():
}
assert User(
uid="1234",
photo="https://scontent-arn2-1.xx.fbcdn.net/v/...",
photo=fbchat.Image(url="https://scontent-arn2-1.xx.fbcdn.net/v/..."),
name="Abc Def Ghi",
url="https://www.facebook.com/profile.php?id=1234",
first_name="Abc",
@@ -137,7 +138,7 @@ def test_user_from_thread_fetch():
}
assert User(
uid="1234",
photo="https://scontent-arn2-1.xx.fbcdn.net/v/...",
photo=fbchat.Image(url="https://scontent-arn2-1.xx.fbcdn.net/v/..."),
name="Abc Def Ghi",
last_active=datetime.datetime(2017, 7, 14, 2, 40, tzinfo=datetime.timezone.utc),
message_count=1111,
@@ -175,7 +176,7 @@ def test_user_from_all_fetch():
}
assert User(
uid="1234",
photo="https://scontent-arn2-1.xx.fbcdn.net/v/...",
photo=fbchat.Image(url="https://scontent-arn2-1.xx.fbcdn.net/v/..."),
name="Abc Def Ghi",
url="https://www.facebook.com/profile.php?id=1234",
first_name="Abc",