Add session attribute to Group/User/Page/Thread

This commit is contained in:
Mads Marquart
2020-01-08 23:07:13 +01:00
parent a5abb05ab3
commit 0531a9e482
9 changed files with 71 additions and 30 deletions

View File

@@ -6,6 +6,11 @@ from contextlib import contextmanager
from fbchat import ThreadType, Message, Mention
@pytest.fixture(scope="session")
def session():
return object() # TODO: Add a mocked session
@pytest.fixture(scope="session")
def user(client2):
return {"id": client2.id, "type": ThreadType.USER}

View File

@@ -1,7 +1,7 @@
from fbchat._group import Group
def test_group_from_graphql():
def test_group_from_graphql(session):
data = {
"name": "Group ABC",
"thread_key": {"thread_fbid": "11223344"},
@@ -26,6 +26,7 @@ def test_group_from_graphql():
"event_reminders": {"nodes": []},
}
assert Group(
session=session,
id="11223344",
photo=None,
name="Group ABC",
@@ -40,4 +41,4 @@ def test_group_from_graphql():
approval_mode=False,
approval_requests=set(),
join_link="",
) == Group._from_graphql(data)
) == Group._from_graphql(session, data)

View File

@@ -2,7 +2,7 @@ import fbchat
from fbchat._page import Page
def test_page_from_graphql():
def test_page_from_graphql(session):
data = {
"id": "123456",
"name": "Some school",
@@ -12,10 +12,11 @@ def test_page_from_graphql():
"city": None,
}
assert Page(
session=session,
id="123456",
photo=fbchat.Image(url="https://scontent-arn2-1.xx.fbcdn.net/v/..."),
name="Some school",
url="https://www.facebook.com/some-school/",
city=None,
category="SCHOOL",
) == Page._from_graphql(data)
) == Page._from_graphql(session, data)

View File

@@ -4,7 +4,7 @@ import fbchat
from fbchat._user import User, ActiveStatus
def test_user_from_graphql():
def test_user_from_graphql(session):
data = {
"id": "1234",
"name": "Abc Def Ghi",
@@ -17,6 +17,7 @@ def test_user_from_graphql():
"viewer_affinity": 0.4560002,
}
assert User(
session=session,
id="1234",
photo=fbchat.Image(url="https://scontent-arn2-1.xx.fbcdn.net/v/..."),
name="Abc Def Ghi",
@@ -25,10 +26,10 @@ def test_user_from_graphql():
last_name="Ghi",
is_friend=True,
gender="female_singular",
) == User._from_graphql(data)
) == User._from_graphql(session, data)
def test_user_from_thread_fetch():
def test_user_from_thread_fetch(session):
data = {
"thread_key": {"thread_fbid": None, "other_user_id": "1234"},
"name": None,
@@ -137,6 +138,7 @@ def test_user_from_thread_fetch():
"delivery_receipts": ...,
}
assert User(
session=session,
id="1234",
photo=fbchat.Image(url="https://scontent-arn2-1.xx.fbcdn.net/v/..."),
name="Abc Def Ghi",
@@ -151,10 +153,10 @@ def test_user_from_thread_fetch():
own_nickname="B",
color=None,
emoji=None,
) == User._from_thread_fetch(data)
) == User._from_thread_fetch(session, data)
def test_user_from_all_fetch():
def test_user_from_all_fetch(session):
data = {
"id": "1234",
"name": "Abc Def Ghi",
@@ -175,6 +177,7 @@ def test_user_from_all_fetch():
"is_blocked": False,
}
assert User(
session=session,
id="1234",
photo=fbchat.Image(url="https://scontent-arn2-1.xx.fbcdn.net/v/..."),
name="Abc Def Ghi",
@@ -182,7 +185,7 @@ def test_user_from_all_fetch():
first_name="Abc",
is_friend=True,
gender="female_singular",
) == User._from_all_fetch(data)
) == User._from_all_fetch(session, data)
@pytest.mark.skip(reason="can't gather test data, the pulling is broken")