Improved test setup
This commit is contained in:
@@ -5,20 +5,11 @@ from __future__ import unicode_literals
|
||||
import pytest
|
||||
|
||||
from os import path
|
||||
from fbchat.models import Message, Mention, EmojiSize, FBchatFacebookError, Sticker
|
||||
from utils import subset
|
||||
from fbchat.models import FBchatFacebookError, Message, Mention
|
||||
from utils import subset, STICKER_LIST, EMOJI_LIST, TEXT_LIST
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"text",
|
||||
[
|
||||
"test_send",
|
||||
"😆",
|
||||
"\\\n\t%?&'\"",
|
||||
"ˁҭʚ¹Ʋջوװ՞ޱɣࠚԹБɑȑңКએ֭ʗыԈٌʼőԈ×௴nચϚࠖణٔє܅Ԇޑط",
|
||||
"a" * 20000, # Maximum amount of characters you can send
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("text", TEXT_LIST)
|
||||
def test_send_text(client, catch_event, compare, text):
|
||||
with catch_event("onMessage") as x:
|
||||
mid = client.sendMessage(text)
|
||||
@@ -27,19 +18,7 @@ def test_send_text(client, catch_event, compare, text):
|
||||
assert subset(vars(x.res["message_object"]), uid=mid, author=client.uid, text=text)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"emoji, emoji_size",
|
||||
[
|
||||
("😆", EmojiSize.SMALL),
|
||||
("😆", EmojiSize.MEDIUM),
|
||||
("😆", EmojiSize.LARGE),
|
||||
# These fail because the emoji is made into a sticker
|
||||
# This should be fixed
|
||||
pytest.mark.xfail((None, EmojiSize.SMALL)),
|
||||
pytest.mark.xfail((None, EmojiSize.MEDIUM)),
|
||||
pytest.mark.xfail((None, EmojiSize.LARGE)),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("emoji, emoji_size", EMOJI_LIST)
|
||||
def test_send_emoji(client, catch_event, compare, emoji, emoji_size):
|
||||
with catch_event("onMessage") as x:
|
||||
mid = client.sendEmoji(emoji, emoji_size)
|
||||
@@ -54,40 +33,36 @@ def test_send_emoji(client, catch_event, compare, emoji, emoji_size):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xfail(raises=FBchatFacebookError)
|
||||
@pytest.mark.parametrize("message", [Message("a" * 20001)])
|
||||
def test_send_invalid(client, message):
|
||||
client.send(message)
|
||||
|
||||
|
||||
def test_send_mentions(client, client2, thread, catch_event, compare):
|
||||
@pytest.fixture
|
||||
def message_with_mentions(client, client2, thread):
|
||||
text = "Hi there @me, @other and @thread"
|
||||
mentions = [
|
||||
dict(thread_id=client.uid, offset=9, length=3),
|
||||
dict(thread_id=client2.uid, offset=14, length=6),
|
||||
dict(thread_id=thread["id"], offset=26, length=7),
|
||||
]
|
||||
with catch_event("onMessage") as x:
|
||||
mid = client.send(Message(text, mentions=[Mention(**d) for d in mentions]))
|
||||
return Message(text, mentions=[Mention(**d) for d in mentions])
|
||||
|
||||
assert compare(x, mid=mid, message=text)
|
||||
assert subset(vars(x.res["message_object"]), uid=mid, author=client.uid, text=text)
|
||||
|
||||
def test_send_mentions(client, catch_event, compare, message_with_mentions):
|
||||
with catch_event("onMessage") as x:
|
||||
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)
|
||||
# The mentions are not ordered by offset
|
||||
for m in x.res["message_object"].mentions:
|
||||
assert vars(m) in mentions
|
||||
assert vars(m) in [vars(x) for x in message_with_mentions.mentions]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"sticker_id",
|
||||
["767334476626295", pytest.mark.xfail("0", raises=FBchatFacebookError)],
|
||||
)
|
||||
def test_send_sticker(client, catch_event, compare, sticker_id):
|
||||
@pytest.mark.parametrize("sticker", STICKER_LIST)
|
||||
def test_send_sticker(client, catch_event, compare, sticker):
|
||||
with catch_event("onMessage") as x:
|
||||
mid = client.send(Message(sticker=Sticker(sticker_id)))
|
||||
mid = client.send(Message(sticker=sticker))
|
||||
|
||||
assert compare(x, mid=mid)
|
||||
assert subset(vars(x.res["message_object"]), uid=mid, author=client.uid)
|
||||
assert subset(vars(x.res["message_object"].sticker), uid=sticker_id)
|
||||
assert subset(vars(x.res["message_object"].sticker), uid=sticker.uid)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
Reference in New Issue
Block a user