From a97ef67411f3bb459c66204c689877ce4c1723d6 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 15 Dec 2019 15:26:53 +0100 Subject: [PATCH] Backport e348425 --- fbchat/_client.py | 28 +++++++++++++++------------- tests/test_fetch.py | 8 ++++---- tests/test_message_management.py | 2 +- tests/test_polls.py | 2 +- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/fbchat/_client.py b/fbchat/_client.py index 7c8b7ee..42b0dba 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -280,7 +280,7 @@ class Client(object): def _forcedFetch(self, thread_id, mid): params = {"thread_and_message_id": {"thread_id": thread_id, "message_id": mid}} - j, = self.graphql_requests(_graphql.from_doc_id("1768656253222505", params)) + (j,) = self.graphql_requests(_graphql.from_doc_id("1768656253222505", params)) return j def fetchThreads(self, thread_location, before=None, after=None, limit=None): @@ -404,7 +404,7 @@ class Client(object): FBchatException: If request failed """ params = {"search": name, "limit": limit} - j, = self.graphql_requests(_graphql.from_query(_graphql.SEARCH_USER, params)) + (j,) = self.graphql_requests(_graphql.from_query(_graphql.SEARCH_USER, params)) return [User._from_graphql(node) for node in j[name]["users"]["nodes"]] @@ -421,7 +421,7 @@ class Client(object): FBchatException: If request failed """ params = {"search": name, "limit": limit} - j, = self.graphql_requests(_graphql.from_query(_graphql.SEARCH_PAGE, params)) + (j,) = self.graphql_requests(_graphql.from_query(_graphql.SEARCH_PAGE, params)) return [Page._from_graphql(node) for node in j[name]["pages"]["nodes"]] @@ -439,7 +439,7 @@ class Client(object): FBchatException: If request failed """ params = {"search": name, "limit": limit} - j, = self.graphql_requests(_graphql.from_query(_graphql.SEARCH_GROUP, params)) + (j,) = self.graphql_requests(_graphql.from_query(_graphql.SEARCH_GROUP, params)) return [Group._from_graphql(node) for node in j["viewer"]["groups"]["nodes"]] @@ -457,7 +457,9 @@ class Client(object): FBchatException: If request failed """ params = {"search": name, "limit": limit} - j, = self.graphql_requests(_graphql.from_query(_graphql.SEARCH_THREAD, params)) + (j,) = self.graphql_requests( + _graphql.from_query(_graphql.SEARCH_THREAD, params) + ) rtn = [] for node in j[name]["threads"]["nodes"]: @@ -764,7 +766,7 @@ class Client(object): "load_read_receipts": True, "before": before, } - j, = self.graphql_requests(_graphql.from_doc_id("1860982147341344", params)) + (j,) = self.graphql_requests(_graphql.from_doc_id("1860982147341344", params)) if j.get("message_thread") is None: raise FBchatException("Could not fetch thread {}: {}".format(thread_id, j)) @@ -823,7 +825,7 @@ class Client(object): "includeDeliveryReceipts": True, "includeSeqID": False, } - j, = self.graphql_requests(_graphql.from_doc_id("1349387578499440", params)) + (j,) = self.graphql_requests(_graphql.from_doc_id("1349387578499440", params)) rtn = [] for node in j["viewer"]["message_threads"]["nodes"]: @@ -943,7 +945,7 @@ class Client(object): return Plan._from_fetch(j) def _getPrivateData(self): - j, = self.graphql_requests(_graphql.from_doc_id("1868889766468115", {})) + (j,) = self.graphql_requests(_graphql.from_doc_id("1868889766468115", {})) return j["viewer"] def getPhoneNumbers(self): @@ -994,7 +996,7 @@ class Client(object): thread_id, thread_type = self._getThread(thread_id, None) data = {"id": thread_id, "first": 48} thread_id = str(thread_id) - j, = self.graphql_requests(_graphql.from_query_id("515216185516880", data)) + (j,) = self.graphql_requests(_graphql.from_query_id("515216185516880", data)) while True: try: i = j[thread_id]["message_shared_media"]["edges"][0] @@ -1005,7 +1007,7 @@ class Client(object): data["after"] = j[thread_id]["message_shared_media"][ "page_info" ].get("end_cursor") - j, = self.graphql_requests( + (j,) = self.graphql_requests( _graphql.from_query_id("515216185516880", data) ) continue @@ -1534,7 +1536,7 @@ class Client(object): "response": "ACCEPT" if approve else "DENY", "surface": "ADMIN_MODEL_APPROVAL_CENTER", } - j, = self.graphql_requests( + (j,) = self.graphql_requests( _graphql.from_doc_id("1574519202665847", {"data": data}) ) @@ -1589,7 +1591,7 @@ class Client(object): Raises: FBchatException: If request failed """ - (image_id, mimetype), = self._upload(get_files_from_urls([image_url])) + ((image_id, mimetype),) = self._upload(get_files_from_urls([image_url])) return self._changeGroupImage(image_id, thread_id) def changeGroupImageLocal(self, image_path, thread_id=None): @@ -1603,7 +1605,7 @@ class Client(object): FBchatException: If request failed """ with get_files_from_paths([image_path]) as files: - (image_id, mimetype), = self._upload(files) + ((image_id, mimetype),) = self._upload(files) return self._changeGroupImage(image_id, thread_id) diff --git a/tests/test_fetch.py b/tests/test_fetch.py index d509fad..2c30900 100644 --- a/tests/test_fetch.py +++ b/tests/test_fetch.py @@ -27,7 +27,7 @@ def test_fetch_threads(client1): @pytest.mark.parametrize("emoji, emoji_size", EMOJI_LIST) def test_fetch_message_emoji(client, emoji, emoji_size): mid = client.sendEmoji(emoji, emoji_size) - message, = client.fetchThreadMessages(limit=1) + (message,) = client.fetchThreadMessages(limit=1) assert subset( vars(message), uid=mid, author=client.uid, text=emoji, emoji_size=emoji_size @@ -46,7 +46,7 @@ def test_fetch_message_info_emoji(client, thread, emoji, emoji_size): def test_fetch_message_mentions(client, thread, message_with_mentions): mid = client.send(message_with_mentions) - message, = client.fetchThreadMessages(limit=1) + (message,) = client.fetchThreadMessages(limit=1) assert subset( vars(message), uid=mid, author=client.uid, text=message_with_mentions.text @@ -71,7 +71,7 @@ def test_fetch_message_info_mentions(client, thread, message_with_mentions): @pytest.mark.parametrize("sticker", STICKER_LIST) def test_fetch_message_sticker(client, sticker): mid = client.send(Message(sticker=sticker)) - message, = client.fetchThreadMessages(limit=1) + (message,) = client.fetchThreadMessages(limit=1) assert subset(vars(message), uid=mid, author=client.uid) assert subset(vars(message.sticker), uid=sticker.uid) @@ -96,6 +96,6 @@ def test_fetch_info(client1, group): def test_fetch_image_url(client): client.sendLocalFiles([path.join(path.dirname(__file__), "resources", "image.png")]) - message, = client.fetchThreadMessages(limit=1) + (message,) = client.fetchThreadMessages(limit=1) assert client.fetchImageUrl(message.attachments[0].uid) diff --git a/tests/test_message_management.py b/tests/test_message_management.py index 00291ee..96f4537 100644 --- a/tests/test_message_management.py +++ b/tests/test_message_management.py @@ -19,5 +19,5 @@ def test_delete_messages(client): mid1 = client.sendMessage(text1) mid2 = client.sendMessage(text2) client.deleteMessages(mid2) - message, = client.fetchThreadMessages(limit=1) + (message,) = client.fetchThreadMessages(limit=1) assert subset(vars(message), uid=mid1, author=client.uid, text=text1) diff --git a/tests/test_polls.py b/tests/test_polls.py index 32c2457..17d9005 100644 --- a/tests/test_polls.py +++ b/tests/test_polls.py @@ -63,7 +63,7 @@ def test_create_poll(client1, group, catch_event, poll_data): for recv_option in event[ "poll" ].options: # The recieved options may not be the full list - old_option, = list(filter(lambda o: o.text == recv_option.text, poll.options)) + (old_option,) = list(filter(lambda o: o.text == recv_option.text, poll.options)) voters = [client1.uid] if old_option.vote else [] assert subset( vars(recv_option), voters=voters, votes_count=len(voters), vote=False