From a1fc2353279be0fdec91913a71f6c34cbe3ebec5 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 23 Jan 2020 14:22:36 +0100 Subject: [PATCH] Refactor models file structure --- fbchat/__init__.py | 30 ++++++++++++++++++------- fbchat/_client.py | 6 ++--- fbchat/_events/__init__.py | 2 +- fbchat/_events/_client_payload.py | 20 ++++++++--------- fbchat/_events/_common.py | 2 +- fbchat/_events/_delta_class.py | 16 ++++++------- fbchat/_events/_delta_type.py | 30 ++++++++++++------------- fbchat/_models/__init__.py | 8 +++++++ fbchat/{ => _models}/_attachment.py | 4 ++-- fbchat/{ => _models}/_file.py | 4 ++-- fbchat/{ => _models}/_location.py | 4 ++-- fbchat/{ => _models}/_message.py | 15 +++---------- fbchat/{ => _models}/_plan.py | 4 ++-- fbchat/{ => _models}/_poll.py | 4 ++-- fbchat/{ => _models}/_quick_reply.py | 2 +- fbchat/{ => _models}/_sticker.py | 2 +- fbchat/_threads/_abc.py | 31 +++++++++----------------- fbchat/_threads/_group.py | 6 ++--- fbchat/_threads/_page.py | 6 ++--- fbchat/_threads/_user.py | 8 +++---- tests/{ => models}/test_attachment.py | 7 +++--- tests/{ => models}/test_file.py | 10 ++------- tests/{ => models}/test_location.py | 2 +- tests/{ => models}/test_message.py | 2 +- tests/{ => models}/test_plan.py | 2 +- tests/{ => models}/test_poll.py | 2 +- tests/{ => models}/test_quick_reply.py | 4 ++-- tests/{ => models}/test_sticker.py | 2 +- 28 files changed, 116 insertions(+), 119 deletions(-) create mode 100644 fbchat/_models/__init__.py rename fbchat/{ => _models}/_attachment.py (97%) rename fbchat/{ => _models}/_file.py (99%) rename fbchat/{ => _models}/_location.py (97%) rename fbchat/{ => _models}/_message.py (98%) rename fbchat/{ => _models}/_plan.py (98%) rename fbchat/{ => _models}/_poll.py (98%) rename fbchat/{ => _models}/_quick_reply.py (98%) rename fbchat/{ => _models}/_sticker.py (97%) rename tests/{ => models}/test_attachment.py (98%) rename tests/{ => models}/test_file.py (98%) rename tests/{ => models}/test_location.py (98%) rename tests/{ => models}/test_message.py (98%) rename tests/{ => models}/test_plan.py (99%) rename tests/{ => models}/test_poll.py (98%) rename tests/{ => models}/test_quick_reply.py (93%) rename tests/{ => models}/test_sticker.py (98%) diff --git a/fbchat/__init__.py b/fbchat/__init__.py index c701749..c290856 100644 --- a/fbchat/__init__.py +++ b/fbchat/__init__.py @@ -39,20 +39,34 @@ from ._threads import ( Page, PageData, ) -from ._message import EmojiSize, Mention, Message, MessageData -from ._attachment import Attachment, UnsentMessage, ShareAttachment -from ._sticker import Sticker -from ._location import LocationAttachment, LiveLocationAttachment -from ._file import FileAttachment, AudioAttachment, ImageAttachment, VideoAttachment -from ._quick_reply import ( + +# Models +from ._models import ( + Attachment, + UnsentMessage, + ShareAttachment, + LocationAttachment, + LiveLocationAttachment, + Sticker, + FileAttachment, + AudioAttachment, + ImageAttachment, + VideoAttachment, + Poll, + PollOption, + GuestStatus, + Plan, + PlanData, QuickReply, QuickReplyText, QuickReplyLocation, QuickReplyPhoneNumber, QuickReplyEmail, + EmojiSize, + Mention, + Message, + MessageData, ) -from ._poll import Poll, PollOption -from ._plan import GuestStatus, Plan, PlanData # Events from ._events import ( diff --git a/fbchat/_client.py b/fbchat/_client.py index 698caff..466406b 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -2,7 +2,7 @@ import attr import datetime from ._common import log, attrs_default -from . import _exception, _util, _graphql, _session, _threads, _message +from . import _exception, _util, _graphql, _session, _threads, _models from typing import Sequence, Iterable, Tuple, Optional, Set @@ -495,7 +495,7 @@ class Client: data = self._get_private_data() return [j["display_email"] for j in data["all_emails"]] - def mark_as_delivered(self, message: _message.Message): + def mark_as_delivered(self, message: _models.Message): """Mark a message as delivered. Warning: @@ -605,7 +605,7 @@ class Client: "/ajax/mercury/delete_threads.php?dpr=1", data_delete ) - def delete_messages(self, messages: Iterable[_message.Message]): + def delete_messages(self, messages: Iterable[_models.Message]): """Bulk delete specified messages. Args: diff --git a/fbchat/_events/__init__.py b/fbchat/_events/__init__.py index 9806ccb..e7bbed5 100644 --- a/fbchat/_events/__init__.py +++ b/fbchat/_events/__init__.py @@ -6,7 +6,7 @@ from ._client_payload import * from ._delta_class import * from ._delta_type import * -from .. import _exception, _util, _threads +from .. import _exception, _threads from typing import Mapping diff --git a/fbchat/_events/_client_payload.py b/fbchat/_events/_client_payload.py index 6a12e1d..435876d 100644 --- a/fbchat/_events/_client_payload.py +++ b/fbchat/_events/_client_payload.py @@ -1,7 +1,7 @@ import attr import datetime from ._common import attrs_event, UnknownEvent, ThreadEvent -from .. import _exception, _util, _threads, _message +from .. import _exception, _util, _threads, _models from typing import Optional @@ -11,7 +11,7 @@ class ReactionEvent(ThreadEvent): """Somebody reacted to a message.""" #: Message that the user reacted to - message = attr.ib(type=_message.Message) + message = attr.ib(type="_models.Message") reaction = attr.ib(type=Optional[str]) """The reaction. @@ -27,7 +27,7 @@ class ReactionEvent(ThreadEvent): return cls( author=_threads.User(session=session, id=str(data["userId"])), thread=thread, - message=_message.Message(thread=thread, id=data["messageId"]), + message=_models.Message(thread=thread, id=data["messageId"]), reaction=data["reaction"] if data["action"] == 0 else None, ) @@ -58,7 +58,7 @@ class LiveLocationEvent(ThreadEvent): thread = cls._get_thread(session, data) for location_data in data["messageLiveLocations"]: - message = _message.Message(thread=thread, id=data["messageId"]) + message = _models.Message(thread=thread, id=data["messageId"]) author = _threads.User(session=session, id=str(location_data["senderId"])) location = _location.LiveLocationAttachment._from_pull(location_data) @@ -70,7 +70,7 @@ class UnsendEvent(ThreadEvent): """Somebody unsent a message (which deletes it for everyone).""" #: The unsent message - message = attr.ib(type=_message.Message) + message = attr.ib(type="_models.Message") #: When the message was unsent at = attr.ib(type=datetime.datetime) @@ -80,7 +80,7 @@ class UnsendEvent(ThreadEvent): return cls( author=_threads.User(session=session, id=str(data["senderID"])), thread=thread, - message=_message.Message(thread=thread, id=data["messageID"]), + message=_models.Message(thread=thread, id=data["messageID"]), at=_util.millis_to_datetime(data["deletionTimestamp"]), ) @@ -90,9 +90,9 @@ class MessageReplyEvent(ThreadEvent): """Somebody replied to a message.""" #: The sent message - message = attr.ib(type=_message.MessageData) + message = attr.ib(type="_models.MessageData") #: The message that was replied to - replied_to = attr.ib(type=_message.MessageData) + replied_to = attr.ib(type="_models.MessageData") @classmethod def _parse(cls, session, data): @@ -101,8 +101,8 @@ class MessageReplyEvent(ThreadEvent): return cls( author=_threads.User(session=session, id=str(metadata["actorFbId"])), thread=thread, - message=_message.MessageData._from_reply(thread, data["message"]), - replied_to=_message.MessageData._from_reply( + message=_models.MessageData._from_reply(thread, data["message"]), + replied_to=_models.MessageData._from_reply( thread, data["repliedToMessage"] ), ) diff --git a/fbchat/_events/_common.py b/fbchat/_events/_common.py index 46de65a..e93d09b 100644 --- a/fbchat/_events/_common.py +++ b/fbchat/_events/_common.py @@ -1,7 +1,7 @@ import attr import abc from .._common import kw_only -from .. import _exception, _util, _threads, _message +from .. import _exception, _util, _threads from typing import Any diff --git a/fbchat/_events/_delta_class.py b/fbchat/_events/_delta_class.py index 7e496a0..6aa40e8 100644 --- a/fbchat/_events/_delta_class.py +++ b/fbchat/_events/_delta_class.py @@ -1,7 +1,7 @@ import attr import datetime from ._common import attrs_event, Event, UnknownEvent, ThreadEvent -from .. import _util, _threads, _message +from .. import _util, _threads, _models from typing import Sequence, Optional @@ -37,7 +37,7 @@ class PersonRemoved(ThreadEvent): thread = attr.ib(type="_threads.Group") # Set the correct type #: Person who got removed - removed = attr.ib(type=_message.Message) + removed = attr.ib(type="_models.Message") #: When the person were removed at = attr.ib(type=datetime.datetime) @@ -79,14 +79,14 @@ class UnfetchedThreadEvent(Event): #: The thread the message was sent to thread = attr.ib(type="_threads.ThreadABC") #: The message - message = attr.ib(type=Optional[_message.Message]) + message = attr.ib(type=Optional["_models.Message"]) @classmethod def _parse(cls, session, data): thread = ThreadEvent._get_thread(session, data) message = None if "messageId" in data: - message = _message.Message(thread=thread, id=data["messageId"]) + message = _models.Message(thread=thread, id=data["messageId"]) return cls(thread=thread, message=message) @@ -95,7 +95,7 @@ class MessagesDelivered(ThreadEvent): """Somebody marked messages as delivered in a thread.""" #: The messages that were marked as delivered - messages = attr.ib(type=Sequence[_message.Message]) + messages = attr.ib(type=Sequence["_models.Message"]) #: When the messages were delivered at = attr.ib(type=datetime.datetime) @@ -106,7 +106,7 @@ class MessagesDelivered(ThreadEvent): author = _threads.User(session=session, id=data["actorFbId"]) else: author = thread - messages = [_message.Message(thread=thread, id=x) for x in data["messageIds"]] + messages = [_models.Message(thread=thread, id=x) for x in data["messageIds"]] at = _util.millis_to_datetime(int(data["deliveredWatermarkTimestampMs"])) return cls(author=author, thread=thread, messages=messages, at=at) @@ -145,14 +145,14 @@ class MessageEvent(ThreadEvent): """Somebody sent a message to a thread.""" #: The sent message - message = attr.ib(type=_message.Message) + message = attr.ib(type="_models.Message") #: When the threads were read at = attr.ib(type=datetime.datetime) @classmethod def _parse(cls, session, data): author, thread, at = cls._parse_metadata(session, data) - message = _message.MessageData._from_pull( + message = _models.MessageData._from_pull( thread, data, author=author.id, created_at=at, ) return cls(author=author, thread=thread, message=message, at=at) diff --git a/fbchat/_events/_delta_type.py b/fbchat/_events/_delta_type.py index 2376098..e22e1ee 100644 --- a/fbchat/_events/_delta_type.py +++ b/fbchat/_events/_delta_type.py @@ -1,7 +1,7 @@ import attr import datetime from ._common import attrs_event, Event, UnknownEvent, ThreadEvent -from .. import _util, _threads, _poll, _plan +from .. import _util, _threads, _models from typing import Sequence, Optional @@ -155,7 +155,7 @@ class PollCreated(ThreadEvent): """Somebody created a group poll.""" #: The new poll - poll = attr.ib(type=_poll.Poll) + poll = attr.ib(type="_models.Poll") #: When the poll was created at = attr.ib(type=datetime.datetime) @@ -163,7 +163,7 @@ class PollCreated(ThreadEvent): def _parse(cls, session, data): author, thread, at = cls._parse_metadata(session, data) poll_data = _util.parse_json(data["untypedData"]["question_json"]) - poll = _poll.Poll._from_graphql(session, poll_data) + poll = _models.Poll._from_graphql(session, poll_data) return cls(author=author, thread=thread, poll=poll, at=at) @@ -172,7 +172,7 @@ class PollVoted(ThreadEvent): """Somebody voted in a group poll.""" #: The updated poll - poll = attr.ib(type=_poll.Poll) + poll = attr.ib(type="_models.Poll") #: Ids of the voted options added_ids = attr.ib(type=Sequence[str]) #: Ids of the un-voted options @@ -184,7 +184,7 @@ class PollVoted(ThreadEvent): def _parse(cls, session, data): author, thread, at = cls._parse_metadata(session, data) poll_data = _util.parse_json(data["untypedData"]["question_json"]) - poll = _poll.Poll._from_graphql(session, poll_data) + poll = _models.Poll._from_graphql(session, poll_data) added_ids = _util.parse_json(data["untypedData"]["added_option_ids"]) removed_ids = _util.parse_json(data["untypedData"]["removed_option_ids"]) return cls( @@ -202,14 +202,14 @@ class PlanCreated(ThreadEvent): """Somebody created a plan in a group.""" #: The new plan - plan = attr.ib(type=_plan.PlanData) + plan = attr.ib(type="_models.PlanData") #: When the plan was created at = attr.ib(type=datetime.datetime) @classmethod def _parse(cls, session, data): author, thread, at = cls._parse_metadata(session, data) - plan = _plan.PlanData._from_pull(session, data["untypedData"]) + plan = _models.PlanData._from_pull(session, data["untypedData"]) return cls(author=author, thread=thread, plan=plan, at=at) @@ -218,14 +218,14 @@ class PlanEnded(ThreadEvent): """A plan ended.""" #: The ended plan - plan = attr.ib(type=_plan.PlanData) + plan = attr.ib(type="_models.PlanData") #: When the plan ended at = attr.ib(type=datetime.datetime) @classmethod def _parse(cls, session, data): author, thread, at = cls._parse_metadata(session, data) - plan = _plan.PlanData._from_pull(session, data["untypedData"]) + plan = _models.PlanData._from_pull(session, data["untypedData"]) return cls(author=author, thread=thread, plan=plan, at=at) @@ -234,14 +234,14 @@ class PlanEdited(ThreadEvent): """Somebody changed a plan in a group.""" #: The updated plan - plan = attr.ib(type=_plan.PlanData) + plan = attr.ib(type="_models.PlanData") #: When the plan was updated at = attr.ib(type=datetime.datetime) @classmethod def _parse(cls, session, data): author, thread, at = cls._parse_metadata(session, data) - plan = _plan.PlanData._from_pull(session, data["untypedData"]) + plan = _models.PlanData._from_pull(session, data["untypedData"]) return cls(author=author, thread=thread, plan=plan, at=at) @@ -250,14 +250,14 @@ class PlanDeleted(ThreadEvent): """Somebody removed a plan in a group.""" #: The removed plan - plan = attr.ib(type=_plan.PlanData) + plan = attr.ib(type="_models.PlanData") #: When the plan was removed at = attr.ib(type=datetime.datetime) @classmethod def _parse(cls, session, data): author, thread, at = cls._parse_metadata(session, data) - plan = _plan.PlanData._from_pull(session, data["untypedData"]) + plan = _models.PlanData._from_pull(session, data["untypedData"]) return cls(author=author, thread=thread, plan=plan, at=at) @@ -266,7 +266,7 @@ class PlanResponded(ThreadEvent): """Somebody responded to a plan in a group.""" #: The plan that was responded to - plan = attr.ib(type=_plan.PlanData) + plan = attr.ib(type="_models.PlanData") #: Whether the author will go to the plan or not take_part = attr.ib(type=bool) #: When the plan was removed @@ -275,7 +275,7 @@ class PlanResponded(ThreadEvent): @classmethod def _parse(cls, session, data): author, thread, at = cls._parse_metadata(session, data) - plan = _plan.PlanData._from_pull(session, data["untypedData"]) + plan = _models.PlanData._from_pull(session, data["untypedData"]) take_part = data["untypedData"]["guest_status"] == "GOING" return cls(author=author, thread=thread, plan=plan, take_part=take_part, at=at) diff --git a/fbchat/_models/__init__.py b/fbchat/_models/__init__.py new file mode 100644 index 0000000..de13669 --- /dev/null +++ b/fbchat/_models/__init__.py @@ -0,0 +1,8 @@ +from ._attachment import * +from ._file import * +from ._location import * +from ._plan import * +from ._poll import * +from ._quick_reply import * +from ._sticker import * +from ._message import * diff --git a/fbchat/_attachment.py b/fbchat/_models/_attachment.py similarity index 97% rename from fbchat/_attachment.py rename to fbchat/_models/_attachment.py index 90473ff..c68fa64 100644 --- a/fbchat/_attachment.py +++ b/fbchat/_models/_attachment.py @@ -1,6 +1,6 @@ import attr -from ._common import attrs_default, Image -from . import _util +from .._common import attrs_default, Image +from .. import _util from typing import Sequence diff --git a/fbchat/_file.py b/fbchat/_models/_file.py similarity index 99% rename from fbchat/_file.py rename to fbchat/_models/_file.py index 035616b..03243e7 100644 --- a/fbchat/_file.py +++ b/fbchat/_models/_file.py @@ -1,8 +1,8 @@ import attr import datetime -from ._common import attrs_default, Image -from . import _util from ._attachment import Attachment +from .._common import attrs_default, Image +from .. import _util from typing import Set diff --git a/fbchat/_location.py b/fbchat/_models/_location.py similarity index 97% rename from fbchat/_location.py rename to fbchat/_models/_location.py index b374db3..7172819 100644 --- a/fbchat/_location.py +++ b/fbchat/_models/_location.py @@ -1,7 +1,7 @@ import attr -from ._common import attrs_default, Image from ._attachment import Attachment -from . import _util +from .._common import attrs_default, Image +from .. import _util @attrs_default diff --git a/fbchat/_message.py b/fbchat/_models/_message.py similarity index 98% rename from fbchat/_message.py rename to fbchat/_models/_message.py index 6d70d3e..8ea4318 100644 --- a/fbchat/_message.py +++ b/fbchat/_models/_message.py @@ -2,18 +2,9 @@ import attr import datetime import enum from string import Formatter -from ._common import log, attrs_default -from . import ( - _exception, - _util, - _session, - _attachment, - _location, - _file, - _quick_reply, - _sticker, - _threads, -) +from . import _attachment, _location, _file, _quick_reply, _sticker +from .._common import log, attrs_default +from .. import _exception, _util, _session, _threads from typing import Optional, Mapping, Sequence diff --git a/fbchat/_plan.py b/fbchat/_models/_plan.py similarity index 98% rename from fbchat/_plan.py rename to fbchat/_models/_plan.py index f317f9e..8d5289f 100644 --- a/fbchat/_plan.py +++ b/fbchat/_models/_plan.py @@ -1,8 +1,8 @@ import attr import datetime import enum -from ._common import attrs_default -from . import _exception, _util, _session +from .._common import attrs_default +from .. import _exception, _util, _session from typing import Mapping, Sequence diff --git a/fbchat/_poll.py b/fbchat/_models/_poll.py similarity index 98% rename from fbchat/_poll.py rename to fbchat/_models/_poll.py index 0dd3e09..aeb605a 100644 --- a/fbchat/_poll.py +++ b/fbchat/_models/_poll.py @@ -1,6 +1,6 @@ import attr -from ._common import attrs_default -from . import _exception, _session +from .._common import attrs_default +from .. import _exception, _session from typing import Iterable, Sequence diff --git a/fbchat/_quick_reply.py b/fbchat/_models/_quick_reply.py similarity index 98% rename from fbchat/_quick_reply.py rename to fbchat/_models/_quick_reply.py index 294944f..a833b28 100644 --- a/fbchat/_quick_reply.py +++ b/fbchat/_models/_quick_reply.py @@ -1,6 +1,6 @@ import attr -from ._common import attrs_default from ._attachment import Attachment +from .._common import attrs_default from typing import Any diff --git a/fbchat/_sticker.py b/fbchat/_models/_sticker.py similarity index 97% rename from fbchat/_sticker.py rename to fbchat/_models/_sticker.py index dd7c1bc..6505b51 100644 --- a/fbchat/_sticker.py +++ b/fbchat/_models/_sticker.py @@ -1,6 +1,6 @@ import attr -from ._common import attrs_default, Image from ._attachment import Attachment +from .._common import attrs_default, Image @attrs_default diff --git a/fbchat/_threads/_abc.py b/fbchat/_threads/_abc.py index f818b90..8adb500 100644 --- a/fbchat/_threads/_abc.py +++ b/fbchat/_threads/_abc.py @@ -4,16 +4,7 @@ import collections import datetime import enum from .._common import log, attrs_default, Image -from .. import ( - _util, - _exception, - _session, - _graphql, - _attachment, - _file, - _plan, - _message, -) +from .. import _util, _exception, _session, _graphql, _models from typing import MutableMapping, Mapping, Any, Iterable, Tuple, Optional @@ -111,7 +102,7 @@ class ThreadABC(metaclass=abc.ABCMeta): def send_text( self, text: str, - mentions: Iterable["_message.Mention"] = None, + mentions: Iterable["_models.Mention"] = None, files: Iterable[Tuple[str, str]] = None, reply_to_id: str = None, ) -> str: @@ -149,7 +140,7 @@ class ThreadABC(metaclass=abc.ABCMeta): return self.session._do_send_request(data) - def send_emoji(self, emoji: str, size: "_message.EmojiSize") -> str: + def send_emoji(self, emoji: str, size: "_models.EmojiSize") -> str: """Send an emoji to the thread. Args: @@ -316,14 +307,14 @@ class ThreadABC(metaclass=abc.ABCMeta): # For now, we just create a new thread: thread = self.__class__(session=self.session, id=self.id) snippets = [ - _message.MessageSnippet._parse(thread, snippet) + _models.MessageSnippet._parse(thread, snippet) for snippet in result["snippets"] ] return (result["num_total_snippets"], snippets) def search_messages( self, query: str, limit: int - ) -> Iterable["_message.MessageSnippet"]: + ) -> Iterable["_models.MessageSnippet"]: """Find and get message IDs by query. Warning! If someone send a message to the thread that matches the query, while @@ -378,11 +369,11 @@ class ThreadABC(metaclass=abc.ABCMeta): # For now, we just create a new thread: thread = self.__class__(session=self.session, id=self.id) return [ - _message.MessageData._from_graphql(thread, message, read_receipts) + _models.MessageData._from_graphql(thread, message, read_receipts) for message in j["message_thread"]["messages"]["nodes"] ] - def fetch_messages(self, limit: Optional[int]) -> Iterable["_message.Message"]: + def fetch_messages(self, limit: Optional[int]) -> Iterable["_models.Message"]: """Fetch messages in a thread. The returned messages are ordered by most recent first. @@ -437,9 +428,9 @@ class ThreadABC(metaclass=abc.ABCMeta): node = edge["node"] type_ = node["__typename"] if type_ == "MessageImage": - rtn.append(_file.ImageAttachment._from_list(node)) + rtn.append(_models.ImageAttachment._from_list(node)) elif type_ == "MessageVideo": - rtn.append(_file.VideoAttachment._from_list(node)) + rtn.append(_models.VideoAttachment._from_list(node)) else: log.warning("Unknown image type %s, data: %s", type_, edge) rtn.append(None) @@ -447,7 +438,7 @@ class ThreadABC(metaclass=abc.ABCMeta): # result["page_info"]["has_next_page"] is not correct when limit > 12 return (result["page_info"]["end_cursor"], rtn) - def fetch_images(self, limit: Optional[int]) -> Iterable[_attachment.Attachment]: + def fetch_images(self, limit: Optional[int]) -> Iterable["_models.Attachment"]: """Fetch images/videos posted in the thread. Args: @@ -618,7 +609,7 @@ class ThreadABC(metaclass=abc.ABCMeta): Example: >>> thread.create_plan(...) """ - return _plan.Plan._create(self, name, at, location_name, location_id) + return _models.Plan._create(self, name, at, location_name, location_id) def create_poll(self, question: str, options=Mapping[str, bool]): """Create poll in a thread. diff --git a/fbchat/_threads/_group.py b/fbchat/_threads/_group.py index d99592a..3877a8d 100644 --- a/fbchat/_threads/_group.py +++ b/fbchat/_threads/_group.py @@ -3,7 +3,7 @@ import datetime from ._abc import ThreadABC from . import _user from .._common import attrs_default, Image -from .. import _util, _session, _graphql, _plan +from .. import _util, _session, _graphql, _models from typing import Sequence, Iterable, Set, Mapping @@ -184,7 +184,7 @@ class GroupData(Group): #: Number of messages in the group message_count = attr.ib(None, type=int) #: Set `Plan` - plan = attr.ib(None, type=_plan.PlanData) + plan = attr.ib(None, type="_models.PlanData") #: The group thread's participant user ids participants = attr.ib(factory=set, type=Set[str]) #: A dictionary, containing user nicknames mapped to their IDs @@ -214,7 +214,7 @@ class GroupData(Group): ) plan = None if data.get("event_reminders") and data["event_reminders"].get("nodes"): - plan = _plan.PlanData._from_graphql( + plan = _models.PlanData._from_graphql( session, data["event_reminders"]["nodes"][0] ) diff --git a/fbchat/_threads/_page.py b/fbchat/_threads/_page.py index 67db734..d0feeee 100644 --- a/fbchat/_threads/_page.py +++ b/fbchat/_threads/_page.py @@ -2,7 +2,7 @@ import attr import datetime from ._abc import ThreadABC from .._common import attrs_default, Image -from .. import _session, _plan +from .. import _session, _models @attrs_default @@ -40,7 +40,7 @@ class PageData(Page): #: Number of messages in the thread message_count = attr.ib(None, type=int) #: Set `Plan` - plan = attr.ib(None, type=_plan.PlanData) + plan = attr.ib(None, type="_models.PlanData") #: The page's custom URL url = attr.ib(None, type=str) #: The name of the page's location city @@ -60,7 +60,7 @@ class PageData(Page): data["city"] = {} plan = None if data.get("event_reminders") and data["event_reminders"].get("nodes"): - plan = _plan.PlanData._from_graphql( + plan = _models.PlanData._from_graphql( session, data["event_reminders"]["nodes"][0] ) diff --git a/fbchat/_threads/_user.py b/fbchat/_threads/_user.py index d910851..0295d16 100644 --- a/fbchat/_threads/_user.py +++ b/fbchat/_threads/_user.py @@ -2,7 +2,7 @@ import attr import datetime from ._abc import ThreadABC from .._common import log, attrs_default, Image -from .. import _util, _session, _plan +from .. import _util, _session, _models GENDERS = { @@ -114,7 +114,7 @@ class UserData(User): #: Number of messages in the thread message_count = attr.ib(None, type=int) #: Set `Plan` - plan = attr.ib(None, type=_plan.PlanData) + plan = attr.ib(None, type="_models.PlanData") #: The profile URL. ``None`` for Messenger-only users url = attr.ib(None, type=str) #: The user's gender @@ -145,7 +145,7 @@ class UserData(User): plan = None if data.get("event_reminders") and data["event_reminders"].get("nodes"): - plan = _plan.PlanData._from_graphql( + plan = _models.PlanData._from_graphql( session, data["event_reminders"]["nodes"][0] ) @@ -180,7 +180,7 @@ class UserData(User): plan = None if data["event_reminders"]["nodes"]: - plan = _plan.PlanData._from_graphql( + plan = _models.PlanData._from_graphql( session, data["event_reminders"]["nodes"][0] ) diff --git a/tests/test_attachment.py b/tests/models/test_attachment.py similarity index 98% rename from tests/test_attachment.py rename to tests/models/test_attachment.py index 9f9cab3..ae3206e 100644 --- a/tests/test_attachment.py +++ b/tests/models/test_attachment.py @@ -1,7 +1,8 @@ import pytest import datetime import fbchat -from fbchat._attachment import UnsentMessage, ShareAttachment +from fbchat import UnsentMessage, ShareAttachment +from fbchat._models._message import graphql_to_extensible_attachment def test_parse_unsent_message(): @@ -25,9 +26,7 @@ def test_parse_unsent_message(): }, "genie_attachment": {"genie_message": None}, } - assert UnsentMessage( - id="ee.mid.$xyz" - ) == fbchat._message.graphql_to_extensible_attachment(data) + assert UnsentMessage(id="ee.mid.$xyz") == graphql_to_extensible_attachment(data) def test_share_from_graphql_minimal(): diff --git a/tests/test_file.py b/tests/models/test_file.py similarity index 98% rename from tests/test_file.py rename to tests/models/test_file.py index 730a6ca..26df1c7 100644 --- a/tests/test_file.py +++ b/tests/models/test_file.py @@ -1,13 +1,7 @@ import datetime import fbchat -from fbchat._file import ( - FileAttachment, - AudioAttachment, - ImageAttachment, - VideoAttachment, - graphql_to_attachment, - graphql_to_subattachment, -) +from fbchat import FileAttachment, AudioAttachment, ImageAttachment, VideoAttachment +from fbchat._models._file import graphql_to_attachment, graphql_to_subattachment def test_imageattachment_from_list(): diff --git a/tests/test_location.py b/tests/models/test_location.py similarity index 98% rename from tests/test_location.py rename to tests/models/test_location.py index 9b117a2..c8454b2 100644 --- a/tests/test_location.py +++ b/tests/models/test_location.py @@ -1,7 +1,7 @@ import pytest import datetime import fbchat -from fbchat._location import LocationAttachment, LiveLocationAttachment +from fbchat import LocationAttachment, LiveLocationAttachment def test_location_attachment_from_graphql(): diff --git a/tests/test_message.py b/tests/models/test_message.py similarity index 98% rename from tests/test_message.py rename to tests/models/test_message.py index e08514f..b142f73 100644 --- a/tests/test_message.py +++ b/tests/models/test_message.py @@ -1,7 +1,7 @@ import pytest import fbchat from fbchat import EmojiSize, Mention, Message, MessageData -from fbchat._message import graphql_to_extensible_attachment +from fbchat._models._message import graphql_to_extensible_attachment @pytest.mark.parametrize( diff --git a/tests/test_plan.py b/tests/models/test_plan.py similarity index 99% rename from tests/test_plan.py rename to tests/models/test_plan.py index bde11c9..781ac8e 100644 --- a/tests/test_plan.py +++ b/tests/models/test_plan.py @@ -1,5 +1,5 @@ import datetime -from fbchat._plan import GuestStatus, PlanData +from fbchat import GuestStatus, PlanData def test_plan_properties(session): diff --git a/tests/test_poll.py b/tests/models/test_poll.py similarity index 98% rename from tests/test_poll.py rename to tests/models/test_poll.py index fa64bca..90fadf0 100644 --- a/tests/test_poll.py +++ b/tests/models/test_poll.py @@ -1,4 +1,4 @@ -from fbchat._poll import Poll, PollOption +from fbchat import Poll, PollOption def test_poll_option_from_graphql_unvoted(): diff --git a/tests/test_quick_reply.py b/tests/models/test_quick_reply.py similarity index 93% rename from tests/test_quick_reply.py rename to tests/models/test_quick_reply.py index ff2a19e..ef63ca1 100644 --- a/tests/test_quick_reply.py +++ b/tests/models/test_quick_reply.py @@ -1,10 +1,10 @@ -from fbchat._quick_reply import ( +from fbchat import ( QuickReplyText, QuickReplyLocation, QuickReplyPhoneNumber, QuickReplyEmail, - graphql_to_quick_reply, ) +from fbchat._models._quick_reply import graphql_to_quick_reply def test_parse_minimal(): diff --git a/tests/test_sticker.py b/tests/models/test_sticker.py similarity index 98% rename from tests/test_sticker.py rename to tests/models/test_sticker.py index 6943943..90de3a2 100644 --- a/tests/test_sticker.py +++ b/tests/models/test_sticker.py @@ -1,6 +1,6 @@ import pytest import fbchat -from fbchat._sticker import Sticker +from fbchat import Sticker def test_from_graphql_none():