Format using black
(without string normalization)
This commit is contained in:
@@ -17,17 +17,21 @@ def user(client2):
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def group(pytestconfig):
|
||||
return {"id": load_variable("group_id", pytestconfig.cache), "type": ThreadType.GROUP}
|
||||
return {
|
||||
"id": load_variable("group_id", pytestconfig.cache),
|
||||
"type": ThreadType.GROUP,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", params=[
|
||||
"user", "group", pytest.param("none", marks=[pytest.mark.xfail()])
|
||||
])
|
||||
@pytest.fixture(
|
||||
scope="session",
|
||||
params=["user", "group", pytest.param("none", marks=[pytest.mark.xfail()])],
|
||||
)
|
||||
def thread(request, user, group):
|
||||
return {
|
||||
"user": user,
|
||||
"group": group,
|
||||
"none": {"id": "0", "type": ThreadType.GROUP}
|
||||
"none": {"id": "0", "type": ThreadType.GROUP},
|
||||
}[request.param]
|
||||
|
||||
|
||||
|
@@ -48,7 +48,9 @@ def test_fetch_message_mentions(client, thread, message_with_mentions):
|
||||
mid = client.send(message_with_mentions)
|
||||
message, = client.fetchThreadMessages(limit=1)
|
||||
|
||||
assert subset(vars(message), uid=mid, author=client.uid, text=message_with_mentions.text)
|
||||
assert subset(
|
||||
vars(message), uid=mid, author=client.uid, text=message_with_mentions.text
|
||||
)
|
||||
# The mentions are not ordered by offset
|
||||
for m in message.mentions:
|
||||
assert vars(m) in [vars(x) for x in message_with_mentions.mentions]
|
||||
@@ -58,7 +60,9 @@ def test_fetch_message_info_mentions(client, thread, message_with_mentions):
|
||||
mid = client.send(message_with_mentions)
|
||||
message = client.fetchMessageInfo(mid, thread_id=thread["id"])
|
||||
|
||||
assert subset(vars(message), uid=mid, author=client.uid, text=message_with_mentions.text)
|
||||
assert subset(
|
||||
vars(message), uid=mid, author=client.uid, text=message_with_mentions.text
|
||||
)
|
||||
# The mentions are not ordered by offset
|
||||
for m in message.mentions:
|
||||
assert vars(m) in [vars(x) for x in message_with_mentions.mentions]
|
||||
|
@@ -9,17 +9,17 @@ from utils import random_hex, subset
|
||||
from time import time
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", params=[
|
||||
Plan(int(time()) + 100, random_hex()),
|
||||
pytest.param(
|
||||
Plan(int(time()), random_hex()),
|
||||
marks=[pytest.mark.xfail(raises=FBchatFacebookError)]
|
||||
),
|
||||
pytest.param(
|
||||
Plan(0, None),
|
||||
marks=[pytest.mark.xfail()],
|
||||
),
|
||||
])
|
||||
@pytest.fixture(
|
||||
scope="module",
|
||||
params=[
|
||||
Plan(int(time()) + 100, random_hex()),
|
||||
pytest.param(
|
||||
Plan(int(time()), random_hex()),
|
||||
marks=[pytest.mark.xfail(raises=FBchatFacebookError)],
|
||||
),
|
||||
pytest.param(Plan(0, None), marks=[pytest.mark.xfail()]),
|
||||
],
|
||||
)
|
||||
def plan_data(request, client, user, thread, catch_event, compare):
|
||||
with catch_event("onPlanCreated") as x:
|
||||
client.createPlan(request.param, thread["id"])
|
||||
@@ -50,15 +50,14 @@ def test_fetch_plan_info(client, catch_event, plan_data):
|
||||
event, plan = plan_data
|
||||
fetched_plan = client.fetchPlanInfo(plan.uid)
|
||||
assert subset(
|
||||
vars(fetched_plan),
|
||||
time=plan.time,
|
||||
title=plan.title,
|
||||
author_id=int(client.uid),
|
||||
vars(fetched_plan), time=plan.time, title=plan.title, author_id=int(client.uid)
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("take_part", [False, True])
|
||||
def test_change_plan_participation(client, thread, catch_event, compare, plan_data, take_part):
|
||||
def test_change_plan_participation(
|
||||
client, thread, catch_event, compare, plan_data, take_part
|
||||
):
|
||||
event, plan = plan_data
|
||||
with catch_event("onPlanParticipation") as x:
|
||||
client.changePlanParticipation(plan, take_part=take_part)
|
||||
@@ -94,18 +93,22 @@ def test_on_plan_ended(client, thread, catch_event, compare):
|
||||
with catch_event("onPlanEnded") as x:
|
||||
client.createPlan(Plan(int(time()) + 120, "Wait for ending"))
|
||||
x.wait(180)
|
||||
assert subset(x.res, thread_id=client.uid if thread["type"] == ThreadType.USER else thread["id"], thread_type=thread["type"])
|
||||
assert subset(
|
||||
x.res,
|
||||
thread_id=client.uid if thread["type"] == ThreadType.USER else thread["id"],
|
||||
thread_type=thread["type"],
|
||||
)
|
||||
|
||||
|
||||
#createPlan(self, plan, thread_id=None)
|
||||
#editPlan(self, plan, new_plan)
|
||||
#deletePlan(self, plan)
|
||||
#changePlanParticipation(self, plan, take_part=True)
|
||||
# createPlan(self, plan, thread_id=None)
|
||||
# editPlan(self, plan, new_plan)
|
||||
# deletePlan(self, plan)
|
||||
# changePlanParticipation(self, plan, take_part=True)
|
||||
|
||||
#onPlanCreated(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||
#onPlanEnded(self, mid=None, plan=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||
#onPlanEdited(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||
#onPlanDeleted(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||
#onPlanParticipation(self, mid=None, plan=None, take_part=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||
# onPlanCreated(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||
# onPlanEnded(self, mid=None, plan=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||
# onPlanEdited(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||
# onPlanDeleted(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||
# onPlanParticipation(self, mid=None, plan=None, take_part=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||
|
||||
#fetchPlanInfo(self, plan_id)
|
||||
# fetchPlanInfo(self, plan_id)
|
||||
|
@@ -8,28 +8,40 @@ from fbchat.models import Poll, PollOption, ThreadType
|
||||
from utils import random_hex, subset
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", params=[
|
||||
Poll(title=random_hex(), options=[]),
|
||||
Poll(title=random_hex(), options=[
|
||||
PollOption(random_hex(), vote=True),
|
||||
PollOption(random_hex(), vote=True),
|
||||
]),
|
||||
Poll(title=random_hex(), options=[
|
||||
PollOption(random_hex(), vote=False),
|
||||
PollOption(random_hex(), vote=False),
|
||||
]),
|
||||
Poll(title=random_hex(), options=[
|
||||
PollOption(random_hex(), vote=True),
|
||||
PollOption(random_hex(), vote=True),
|
||||
PollOption(random_hex(), vote=False),
|
||||
PollOption(random_hex(), vote=False),
|
||||
PollOption(random_hex()),
|
||||
PollOption(random_hex()),
|
||||
]),
|
||||
pytest.param(
|
||||
Poll(title=None, options=[]), marks=[pytest.mark.xfail(raises=ValueError)]
|
||||
),
|
||||
])
|
||||
@pytest.fixture(
|
||||
scope="module",
|
||||
params=[
|
||||
Poll(title=random_hex(), options=[]),
|
||||
Poll(
|
||||
title=random_hex(),
|
||||
options=[
|
||||
PollOption(random_hex(), vote=True),
|
||||
PollOption(random_hex(), vote=True),
|
||||
],
|
||||
),
|
||||
Poll(
|
||||
title=random_hex(),
|
||||
options=[
|
||||
PollOption(random_hex(), vote=False),
|
||||
PollOption(random_hex(), vote=False),
|
||||
],
|
||||
),
|
||||
Poll(
|
||||
title=random_hex(),
|
||||
options=[
|
||||
PollOption(random_hex(), vote=True),
|
||||
PollOption(random_hex(), vote=True),
|
||||
PollOption(random_hex(), vote=False),
|
||||
PollOption(random_hex(), vote=False),
|
||||
PollOption(random_hex()),
|
||||
PollOption(random_hex()),
|
||||
],
|
||||
),
|
||||
pytest.param(
|
||||
Poll(title=None, options=[]), marks=[pytest.mark.xfail(raises=ValueError)]
|
||||
),
|
||||
],
|
||||
)
|
||||
def poll_data(request, client1, group, catch_event):
|
||||
with catch_event("onPollCreated") as x:
|
||||
client1.createPoll(request.param, thread_id=group["id"])
|
||||
@@ -45,11 +57,17 @@ def test_create_poll(client1, group, catch_event, poll_data):
|
||||
thread_id=group["id"],
|
||||
thread_type=ThreadType.GROUP,
|
||||
)
|
||||
assert subset(vars(event["poll"]), title=poll.title, options_count=len(poll.options))
|
||||
for recv_option in event["poll"].options: # The recieved options may not be the full list
|
||||
assert subset(
|
||||
vars(event["poll"]), title=poll.title, options_count=len(poll.options)
|
||||
)
|
||||
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))
|
||||
voters = [client1.uid] if old_option.vote else []
|
||||
assert subset(vars(recv_option), voters=voters, votes_count=len(voters), vote=False)
|
||||
assert subset(
|
||||
vars(recv_option), voters=voters, votes_count=len(voters), vote=False
|
||||
)
|
||||
|
||||
|
||||
def test_fetch_poll_options(client1, group, catch_event, poll_data):
|
||||
@@ -62,11 +80,15 @@ def test_fetch_poll_options(client1, group, catch_event, poll_data):
|
||||
@pytest.mark.trylast
|
||||
def test_update_poll_vote(client1, group, catch_event, poll_data):
|
||||
event, poll, options = poll_data
|
||||
new_vote_ids = [o.uid for o in options[0:len(options):2] if not o.vote]
|
||||
re_vote_ids = [o.uid for o in options[0:len(options):2] if o.vote]
|
||||
new_vote_ids = [o.uid for o in options[0 : len(options) : 2] if not o.vote]
|
||||
re_vote_ids = [o.uid for o in options[0 : len(options) : 2] if o.vote]
|
||||
new_options = [random_hex(), random_hex()]
|
||||
with catch_event("onPollVoted") as x:
|
||||
client1.updatePollVote(event["poll"].uid, option_ids=new_vote_ids + re_vote_ids, new_options=new_options)
|
||||
client1.updatePollVote(
|
||||
event["poll"].uid,
|
||||
option_ids=new_vote_ids + re_vote_ids,
|
||||
new_options=new_options,
|
||||
)
|
||||
|
||||
assert subset(
|
||||
x.res,
|
||||
@@ -74,8 +96,12 @@ def test_update_poll_vote(client1, group, catch_event, poll_data):
|
||||
thread_id=group["id"],
|
||||
thread_type=ThreadType.GROUP,
|
||||
)
|
||||
assert subset(vars(x.res["poll"]), title=poll.title, options_count=len(options + new_options))
|
||||
assert subset(
|
||||
vars(x.res["poll"]), title=poll.title, options_count=len(options + new_options)
|
||||
)
|
||||
for o in new_vote_ids:
|
||||
assert o in x.res["added_options"]
|
||||
assert len(x.res["added_options"]) == len(new_vote_ids) + len(new_options)
|
||||
assert set(x.res["removed_options"]) == set(o.uid for o in options if o.vote and o.uid not in re_vote_ids)
|
||||
assert set(x.res["removed_options"]) == set(
|
||||
o.uid for o in options if o.vote and o.uid not in re_vote_ids
|
||||
)
|
||||
|
@@ -38,7 +38,12 @@ def test_send_mentions(client, catch_event, compare, message_with_mentions):
|
||||
mid = client.send(message_with_mentions)
|
||||
|
||||
assert compare(x, mid=mid, message=message_with_mentions.text)
|
||||
assert subset(vars(x.res["message_object"]), uid=mid, author=client.uid, text=message_with_mentions.text)
|
||||
assert subset(
|
||||
vars(x.res["message_object"]),
|
||||
uid=mid,
|
||||
author=client.uid,
|
||||
text=message_with_mentions.text,
|
||||
)
|
||||
# The mentions are not ordered by offset
|
||||
for m in x.res["message_object"].mentions:
|
||||
assert vars(m) in [vars(x) for x in message_with_mentions.mentions]
|
||||
@@ -76,7 +81,15 @@ def test_send_images(client, catch_event, compare, method_name, url):
|
||||
|
||||
|
||||
def test_send_local_files(client, catch_event, compare):
|
||||
files = ["image.png", "image.jpg", "image.gif", "file.json", "file.txt", "audio.mp3", "video.mp4"]
|
||||
files = [
|
||||
"image.png",
|
||||
"image.jpg",
|
||||
"image.gif",
|
||||
"file.json",
|
||||
"file.txt",
|
||||
"audio.mp3",
|
||||
"video.mp4",
|
||||
]
|
||||
text = "Files sent locally"
|
||||
with catch_event("onMessage") as x:
|
||||
mid = client.sendLocalFiles(
|
||||
@@ -95,7 +108,10 @@ def test_send_remote_files(client, catch_event, compare):
|
||||
text = "Files sent from remote"
|
||||
with catch_event("onMessage") as x:
|
||||
mid = client.sendRemoteFiles(
|
||||
["https://github.com/carpedm20/fbchat/raw/master/tests/{}".format(f) for f in files],
|
||||
[
|
||||
"https://github.com/carpedm20/fbchat/raw/master/tests/{}".format(f)
|
||||
for f in files
|
||||
],
|
||||
message=Message(text),
|
||||
)
|
||||
|
||||
|
@@ -67,14 +67,19 @@ def test_change_nickname(client, client_all, catch_event, compare):
|
||||
assert compare(x, changed_for=client_all.uid, new_nickname=nickname)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("emoji", [
|
||||
"😀",
|
||||
"😂",
|
||||
"😕",
|
||||
"😍",
|
||||
pytest.param("🙃", marks=[pytest.mark.xfail(raises=FBchatFacebookError)]),
|
||||
pytest.param("not an emoji", marks=[pytest.mark.xfail(raises=FBchatFacebookError)]),
|
||||
])
|
||||
@pytest.mark.parametrize(
|
||||
"emoji",
|
||||
[
|
||||
"😀",
|
||||
"😂",
|
||||
"😕",
|
||||
"😍",
|
||||
pytest.param("🙃", marks=[pytest.mark.xfail(raises=FBchatFacebookError)]),
|
||||
pytest.param(
|
||||
"not an emoji", marks=[pytest.mark.xfail(raises=FBchatFacebookError)]
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_change_emoji(client, catch_event, compare, emoji):
|
||||
with catch_event("onEmojiChange") as x:
|
||||
client.changeThreadEmoji(emoji)
|
||||
@@ -85,7 +90,9 @@ def test_change_image_local(client1, group, catch_event):
|
||||
url = path.join(path.dirname(__file__), "resources", "image.png")
|
||||
with catch_event("onImageChange") as x:
|
||||
image_id = client1.changeGroupImageLocal(url, group["id"])
|
||||
assert subset(x.res, new_image=image_id, author_id=client1.uid, thread_id=group["id"])
|
||||
assert subset(
|
||||
x.res, new_image=image_id, author_id=client1.uid, thread_id=group["id"]
|
||||
)
|
||||
|
||||
|
||||
# To be changed when merged into master
|
||||
@@ -93,7 +100,9 @@ def test_change_image_remote(client1, group, catch_event):
|
||||
url = "https://github.com/carpedm20/fbchat/raw/master/tests/image.png"
|
||||
with catch_event("onImageChange") as x:
|
||||
image_id = client1.changeGroupImageRemote(url, group["id"])
|
||||
assert subset(x.res, new_image=image_id, author_id=client1.uid, thread_id=group["id"])
|
||||
assert subset(
|
||||
x.res, new_image=image_id, author_id=client1.uid, thread_id=group["id"]
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -138,6 +147,7 @@ def test_change_approval_mode(client1, group, catch_event, require_admin_approva
|
||||
thread_id=group["id"],
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mute_time", [0, 10, 100, 1000, -1])
|
||||
def test_mute_thread(client, mute_time):
|
||||
assert client.muteThread(mute_time)
|
||||
|
Reference in New Issue
Block a user