Add ThreadABC._parse_participants

This commit is contained in:
Mads Marquart
2020-01-10 00:32:12 +01:00
parent 5e09cb9cab
commit da18111ed0
5 changed files with 51 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
from fbchat._group import GroupData
from fbchat import GroupData, User
def test_group_from_graphql(session):
@@ -9,9 +9,9 @@ def test_group_from_graphql(session):
"is_group_thread": True,
"all_participants": {
"nodes": [
{"messaging_actor": {"id": "1234"}},
{"messaging_actor": {"id": "2345"}},
{"messaging_actor": {"id": "3456"}},
{"messaging_actor": {"__typename": "User", "id": "1234"}},
{"messaging_actor": {"__typename": "User", "id": "2345"}},
{"messaging_actor": {"__typename": "User", "id": "3456"}},
]
},
"customization_info": {
@@ -33,7 +33,11 @@ def test_group_from_graphql(session):
last_active=None,
message_count=None,
plan=None,
participants={"1234", "2345", "3456"},
participants=[
User(session=session, id="1234"),
User(session=session, id="2345"),
User(session=session, id="3456"),
],
nicknames={},
color="#0084ff",
emoji="😀",

View File

@@ -1,6 +1,6 @@
import pytest
import fbchat
from fbchat import ThreadABC, Thread
from fbchat import ThreadABC, Thread, User, Group, Page
def test_parse_color():
@@ -58,6 +58,22 @@ def test_thread_parse_customization_info_user():
assert expected == ThreadABC._parse_customization_info(data)
def test_thread_parse_participants(session):
nodes = [
{"messaging_actor": {"__typename": "User", "id": "1234"}},
{"messaging_actor": {"__typename": "User", "id": "2345"}},
{"messaging_actor": {"__typename": "Page", "id": "3456"}},
{"messaging_actor": {"__typename": "MessageThread", "id": "4567"}},
{"messaging_actor": {"__typename": "UnavailableMessagingActor", "id": "5678"}},
]
assert [
User(session=session, id="1234"),
User(session=session, id="2345"),
Page(session=session, id="3456"),
Group(session=session, id="4567"),
] == list(ThreadABC._parse_participants(session, {"nodes": nodes}))
def test_thread_create_and_implements_thread_abc(session):
thread = Thread(session=session, id="123")
assert thread._parse_customization_info