From 078bf9fc16ff00368378545c7c94f10766febd54 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 7 May 2020 12:26:39 +0200 Subject: [PATCH] Add send online tests --- fbchat/_threads/_abc.py | 2 +- tests/online/conftest.py | 18 +++++++++++++++++ tests/online/test_send.py | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/online/test_send.py diff --git a/fbchat/_threads/_abc.py b/fbchat/_threads/_abc.py index 042856e..60a5dd0 100644 --- a/fbchat/_threads/_abc.py +++ b/fbchat/_threads/_abc.py @@ -211,7 +211,7 @@ class ThreadABC(metaclass=abc.ABCMeta): Example: Send a pinned location in Beijing, China. - >>> thread.send_location(39.9390731, 116.117273) + >>> thread.send_pinned_location(39.9390731, 116.117273) """ self._send_location(False, latitude=latitude, longitude=longitude) diff --git a/tests/online/conftest.py b/tests/online/conftest.py index 33cea7b..e8d6394 100644 --- a/tests/online/conftest.py +++ b/tests/online/conftest.py @@ -44,6 +44,24 @@ def group(pytestconfig, session): return fbchat.Group(session=session, id=group_id) +@pytest.fixture( + scope="session", + params=[ + "user", + "group", + "self", + pytest.param("invalid", marks=[pytest.mark.xfail()]), + ], +) +def any_thread(request, session, user, group): + return { + "user": user, + "group": group, + "self": session.user, + "invalid": fbchat.Thread(session=session, id="0"), + }[request.param] + + @pytest.fixture def listener(session): return fbchat.Listener(session=session, chat_on=False, foreground=False) diff --git a/tests/online/test_send.py b/tests/online/test_send.py new file mode 100644 index 0000000..7a7bc2a --- /dev/null +++ b/tests/online/test_send.py @@ -0,0 +1,42 @@ +import pytest +import fbchat + +pytestmark = pytest.mark.online + + +# TODO: Verify return values + + +def test_wave(any_thread): + assert any_thread.wave(True) + assert any_thread.wave(False) + + +def test_send_text(any_thread): + assert any_thread.send_text("Test") + + +def test_send_text_with_mention(any_thread): + mention = fbchat.Mention(thread_id=any_thread.id, offset=5, length=8) + assert any_thread.send_text("Test @mention", mentions=[mention]) + + +def test_send_emoji(any_thread): + assert any_thread.send_emoji("😀", size=fbchat.EmojiSize.LARGE) + + +def test_send_sticker(any_thread): + assert any_thread.send_sticker("1889713947839631") + + +def test_send_location(any_thread): + any_thread.send_location(51.5287718, -0.2416815) + + +def test_send_pinned_location(any_thread): + any_thread.send_pinned_location(39.9390731, 116.117273) + + +@pytest.mark.skip(reason="need a way to use the uploaded files from test_client.py") +def test_send_files(any_thread): + pass