Allow specifying class variables in init
This commit is contained in:
@@ -37,10 +37,7 @@ class ShareAttachment(Attachment):
|
|||||||
#: URL of the original image if Facebook uses ``safe_image``
|
#: URL of the original image if Facebook uses ``safe_image``
|
||||||
original_image_url = attr.ib(None)
|
original_image_url = attr.ib(None)
|
||||||
#: List of additional attachments
|
#: List of additional attachments
|
||||||
attachments = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
|
attachments = attr.ib(factory=list)
|
||||||
|
|
||||||
# Put here for backwards compatibility, so that the init argument order is preserved
|
|
||||||
uid = attr.ib(None)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _from_graphql(cls, data):
|
def _from_graphql(cls, data):
|
||||||
|
@@ -17,9 +17,6 @@ class FileAttachment(Attachment):
|
|||||||
#: Whether Facebook determines that this file may be harmful
|
#: Whether Facebook determines that this file may be harmful
|
||||||
is_malicious = attr.ib(None)
|
is_malicious = attr.ib(None)
|
||||||
|
|
||||||
# Put here for backwards compatibility, so that the init argument order is preserved
|
|
||||||
uid = attr.ib(None)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _from_graphql(cls, data):
|
def _from_graphql(cls, data):
|
||||||
return cls(
|
return cls(
|
||||||
@@ -43,9 +40,6 @@ class AudioAttachment(Attachment):
|
|||||||
#: Audio type
|
#: Audio type
|
||||||
audio_type = attr.ib(None)
|
audio_type = attr.ib(None)
|
||||||
|
|
||||||
# Put here for backwards compatibility, so that the init argument order is preserved
|
|
||||||
uid = attr.ib(None)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _from_graphql(cls, data):
|
def _from_graphql(cls, data):
|
||||||
return cls(
|
return cls(
|
||||||
|
@@ -11,21 +11,19 @@ class Group(Thread):
|
|||||||
type = ThreadType.GROUP
|
type = ThreadType.GROUP
|
||||||
|
|
||||||
#: Unique list (set) of the group thread's participant user IDs
|
#: Unique list (set) of the group thread's participant user IDs
|
||||||
participants = attr.ib(factory=set, converter=lambda x: set() if x is None else x)
|
participants = attr.ib(factory=set)
|
||||||
#: A dictionary, containing user nicknames mapped to their IDs
|
#: A dictionary, containing user nicknames mapped to their IDs
|
||||||
nicknames = attr.ib(factory=dict, converter=lambda x: {} if x is None else x)
|
nicknames = attr.ib(factory=dict)
|
||||||
#: A :class:`ThreadColor`. The groups's message color
|
#: A :class:`ThreadColor`. The groups's message color
|
||||||
color = attr.ib(None)
|
color = attr.ib(None)
|
||||||
#: The groups's default emoji
|
#: The groups's default emoji
|
||||||
emoji = attr.ib(None)
|
emoji = attr.ib(None)
|
||||||
# Set containing user IDs of thread admins
|
# Set containing user IDs of thread admins
|
||||||
admins = attr.ib(factory=set, converter=lambda x: set() if x is None else x)
|
admins = attr.ib(factory=set)
|
||||||
# True if users need approval to join
|
# True if users need approval to join
|
||||||
approval_mode = attr.ib(None)
|
approval_mode = attr.ib(None)
|
||||||
# Set containing user IDs requesting to join
|
# Set containing user IDs requesting to join
|
||||||
approval_requests = attr.ib(
|
approval_requests = attr.ib(factory=set)
|
||||||
factory=set, converter=lambda x: set() if x is None else x
|
|
||||||
)
|
|
||||||
# Link for joining group
|
# Link for joining group
|
||||||
join_link = attr.ib(None)
|
join_link = attr.ib(None)
|
||||||
|
|
||||||
|
@@ -16,15 +16,12 @@ class LocationAttachment(Attachment):
|
|||||||
#: Longitude of the location
|
#: Longitude of the location
|
||||||
longitude = attr.ib(None)
|
longitude = attr.ib(None)
|
||||||
#: Image showing the map of the location
|
#: Image showing the map of the location
|
||||||
image = attr.ib(None, init=False)
|
image = attr.ib(None)
|
||||||
#: URL to Bing maps with the location
|
#: URL to Bing maps with the location
|
||||||
url = attr.ib(None, init=False)
|
url = attr.ib(None)
|
||||||
# Address of the location
|
# Address of the location
|
||||||
address = attr.ib(None)
|
address = attr.ib(None)
|
||||||
|
|
||||||
# Put here for backwards compatibility, so that the init argument order is preserved
|
|
||||||
uid = attr.ib(None)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _from_graphql(cls, data):
|
def _from_graphql(cls, data):
|
||||||
url = data.get("url")
|
url = data.get("url")
|
||||||
|
@@ -61,35 +61,35 @@ class Message:
|
|||||||
#: The actual message
|
#: The actual message
|
||||||
text = attr.ib(None)
|
text = attr.ib(None)
|
||||||
#: A list of :class:`Mention` objects
|
#: A list of :class:`Mention` objects
|
||||||
mentions = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
|
mentions = attr.ib(factory=list)
|
||||||
#: A :class:`EmojiSize`. Size of a sent emoji
|
#: A :class:`EmojiSize`. Size of a sent emoji
|
||||||
emoji_size = attr.ib(None)
|
emoji_size = attr.ib(None)
|
||||||
#: The message ID
|
#: The message ID
|
||||||
uid = attr.ib(None, init=False)
|
uid = attr.ib(None)
|
||||||
#: ID of the sender
|
#: ID of the sender
|
||||||
author = attr.ib(None, init=False)
|
author = attr.ib(None)
|
||||||
#: Datetime of when the message was sent
|
#: Datetime of when the message was sent
|
||||||
created_at = attr.ib(None, init=False)
|
created_at = attr.ib(None)
|
||||||
#: Whether the message is read
|
#: Whether the message is read
|
||||||
is_read = attr.ib(None, init=False)
|
is_read = attr.ib(None)
|
||||||
#: A list of people IDs who read the message, works only with :func:`fbchat.Client.fetch_thread_messages`
|
#: A list of people IDs who read the message, works only with :func:`fbchat.Client.fetch_thread_messages`
|
||||||
read_by = attr.ib(factory=list, init=False)
|
read_by = attr.ib(factory=list)
|
||||||
#: A dictionary with user's IDs as keys, and their :class:`MessageReaction` as values
|
#: A dictionary with user's IDs as keys, and their :class:`MessageReaction` as values
|
||||||
reactions = attr.ib(factory=dict, init=False)
|
reactions = attr.ib(factory=dict)
|
||||||
#: A :class:`Sticker`
|
#: A :class:`Sticker`
|
||||||
sticker = attr.ib(None)
|
sticker = attr.ib(None)
|
||||||
#: A list of attachments
|
#: A list of attachments
|
||||||
attachments = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
|
attachments = attr.ib(factory=list)
|
||||||
#: A list of :class:`QuickReply`
|
#: A list of :class:`QuickReply`
|
||||||
quick_replies = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
|
quick_replies = attr.ib(factory=list)
|
||||||
#: Whether the message is unsent (deleted for everyone)
|
#: Whether the message is unsent (deleted for everyone)
|
||||||
unsent = attr.ib(False, init=False)
|
unsent = attr.ib(False)
|
||||||
#: Message ID you want to reply to
|
#: Message ID you want to reply to
|
||||||
reply_to_id = attr.ib(None)
|
reply_to_id = attr.ib(None)
|
||||||
#: Replied message
|
#: Replied message
|
||||||
replied_to = attr.ib(None, init=False)
|
replied_to = attr.ib(None)
|
||||||
#: Whether the message was forwarded
|
#: Whether the message was forwarded
|
||||||
forwarded = attr.ib(False, init=False)
|
forwarded = attr.ib(False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def format_mentions(cls, text, *args, **kwargs):
|
def format_mentions(cls, text, *args, **kwargs):
|
||||||
|
@@ -14,20 +14,20 @@ class GuestStatus(Enum):
|
|||||||
class Plan:
|
class Plan:
|
||||||
"""Represents a plan."""
|
"""Represents a plan."""
|
||||||
|
|
||||||
#: ID of the plan
|
|
||||||
uid = attr.ib(None, init=False)
|
|
||||||
#: Plan time (datetime), only precise down to the minute
|
#: Plan time (datetime), only precise down to the minute
|
||||||
time = attr.ib()
|
time = attr.ib()
|
||||||
#: Plan title
|
#: Plan title
|
||||||
title = attr.ib()
|
title = attr.ib()
|
||||||
|
#: ID of the plan
|
||||||
|
uid = attr.ib(None)
|
||||||
#: Plan location name
|
#: Plan location name
|
||||||
location = attr.ib(None, converter=lambda x: x or "")
|
location = attr.ib(None, converter=lambda x: x or "")
|
||||||
#: Plan location ID
|
#: Plan location ID
|
||||||
location_id = attr.ib(None, converter=lambda x: x or "")
|
location_id = attr.ib(None, converter=lambda x: x or "")
|
||||||
#: ID of the plan creator
|
#: ID of the plan creator
|
||||||
author_id = attr.ib(None, init=False)
|
author_id = attr.ib(None)
|
||||||
#: Dictionary of `User` IDs mapped to their `GuestStatus`
|
#: Dictionary of `User` IDs mapped to their `GuestStatus`
|
||||||
guests = attr.ib(None, init=False)
|
guests = attr.ib(None)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def going(self):
|
def going(self):
|
||||||
|
@@ -34,14 +34,17 @@ def test_location_attachment_from_graphql():
|
|||||||
"target": {"__typename": "MessageLocation"},
|
"target": {"__typename": "MessageLocation"},
|
||||||
"subattachments": [],
|
"subattachments": [],
|
||||||
}
|
}
|
||||||
expected = LocationAttachment(latitude=55.4, longitude=12.4322, uid=400828513928715)
|
assert LocationAttachment(
|
||||||
expected.image = fbchat.Image(
|
uid=400828513928715,
|
||||||
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",
|
latitude=55.4,
|
||||||
width=545,
|
longitude=12.4322,
|
||||||
height=280,
|
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",
|
||||||
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"
|
width=545,
|
||||||
assert expected == LocationAttachment._from_graphql(data)
|
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)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="need to gather test data")
|
@pytest.mark.skip(reason="need to gather test data")
|
||||||
@@ -76,16 +79,15 @@ def test_live_location_from_graphql_expired():
|
|||||||
},
|
},
|
||||||
"subattachments": [],
|
"subattachments": [],
|
||||||
}
|
}
|
||||||
expected = LiveLocationAttachment(
|
assert LiveLocationAttachment(
|
||||||
uid=2254535444791641,
|
uid=2254535444791641,
|
||||||
name="Location-sharing ended",
|
name="Location-sharing ended",
|
||||||
expires_at=datetime.datetime(
|
expires_at=datetime.datetime(
|
||||||
2019, 1, 4, 18, 25, 45, tzinfo=datetime.timezone.utc
|
2019, 1, 4, 18, 25, 45, tzinfo=datetime.timezone.utc
|
||||||
),
|
),
|
||||||
is_expired=True,
|
is_expired=True,
|
||||||
)
|
url="https://www.facebook.com/",
|
||||||
expected.url = "https://www.facebook.com/"
|
) == LiveLocationAttachment._from_graphql(data)
|
||||||
assert expected == LiveLocationAttachment._from_graphql(data)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="need to gather test data")
|
@pytest.mark.skip(reason="need to gather test data")
|
||||||
|
Reference in New Issue
Block a user