diff --git a/tests/conftest.py b/tests/conftest.py index 879e3dc..01cdf4e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -80,7 +80,7 @@ def catch_event(client2): try: # Make the client send a messages to itself, so the blocking pull request will return # This is probably not safe, since the client is making two requests simultaneously - client2.sendMessage("Shutdown", client2.uid) + client2.sendMessage(random_hex(), client2.uid) finally: t.join() diff --git a/tests/data.json b/tests/data.json deleted file mode 100644 index d20c682..0000000 --- a/tests/data.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "email": "", - "password": "", - "user_thread_id": "", - "group_thread_id": "" -} diff --git a/tests/resources/audio.mp3 b/tests/resources/audio.mp3 new file mode 100644 index 0000000..084a7d1 Binary files /dev/null and b/tests/resources/audio.mp3 differ diff --git a/tests/resources/file.json b/tests/resources/file.json new file mode 100644 index 0000000..c4036cf --- /dev/null +++ b/tests/resources/file.json @@ -0,0 +1,4 @@ +{ + "some": "data", + "in": "here" +} diff --git a/tests/resources/file.txt b/tests/resources/file.txt new file mode 100644 index 0000000..0204d00 --- /dev/null +++ b/tests/resources/file.txt @@ -0,0 +1 @@ +This is just a text file diff --git a/tests/resources/image.gif b/tests/resources/image.gif new file mode 100644 index 0000000..3db1c95 Binary files /dev/null and b/tests/resources/image.gif differ diff --git a/tests/resources/image.jpg b/tests/resources/image.jpg new file mode 100644 index 0000000..2cbbff0 Binary files /dev/null and b/tests/resources/image.jpg differ diff --git a/tests/image.png b/tests/resources/image.png similarity index 100% rename from tests/image.png rename to tests/resources/image.png diff --git a/tests/resources/video.mp4 b/tests/resources/video.mp4 new file mode 100644 index 0000000..02c2060 Binary files /dev/null and b/tests/resources/video.mp4 differ diff --git a/tests/test_fetch.py b/tests/test_fetch.py index 3ce870c..04fe26a 100644 --- a/tests/test_fetch.py +++ b/tests/test_fetch.py @@ -59,7 +59,7 @@ def test_fetch_info(client1, group): def test_fetch_image_url(client): - url = path.join(path.dirname(__file__), "image.png") + url = path.join(path.dirname(__file__), "resources", "image.png") client.sendLocalImage(url) message, = client.fetchThreadMessages(limit=1) diff --git a/tests/test_send.py b/tests/test_send.py index f957775..92b986c 100644 --- a/tests/test_send.py +++ b/tests/test_send.py @@ -65,6 +65,7 @@ def test_send_sticker(client, catch_event, compare, sticker): assert subset(vars(x.res["message_object"].sticker), uid=sticker.uid) +# Kept for backwards compatability @pytest.mark.parametrize( "method_name, url", [ @@ -72,7 +73,7 @@ def test_send_sticker(client, catch_event, compare, sticker): "sendRemoteImage", "https://github.com/carpedm20/fbchat/raw/master/tests/image.png", ), - ("sendLocalImage", path.join(path.dirname(__file__), "image.png")), + ("sendLocalImage", path.join(path.dirname(__file__), "resources", "image.png")), ], ) def test_send_images(client, catch_event, compare, method_name, url): @@ -83,3 +84,32 @@ def test_send_images(client, catch_event, compare, method_name, url): assert compare(x, mid=mid, message=text) assert subset(vars(x.res["message_object"]), uid=mid, author=client.uid, text=text) assert x.res["message_object"].attachments[0] + + +def test_send_local_files(client, catch_event, compare): + 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( + [path.join(path.dirname(__file__), "resources", x) for x in files], + message=Message(text), + ) + + assert compare(x, mid=mid, message=text) + assert subset(vars(x.res["message_object"]), uid=mid, author=client.uid, text=text) + assert len(x.res["message_object"].attachments) == len(files) + + +# To be changed when merged into master +def test_send_remote_files(client, catch_event, compare): + files = ["image.png", "data.json"] + text = "Files sent from remote" + with catch_event("onMessage") as x: + mid = client.sendRemoteFiles( + ["https://github.com/carpedm20/fbchat/raw/master/tests/{}".format(x) for x in files], + message=Message(text), + ) + + assert compare(x, mid=mid, message=text) + assert subset(vars(x.res["message_object"]), uid=mid, author=client.uid, text=text) + assert len(x.res["message_object"].attachments) == len(files) diff --git a/tests/utils.py b/tests/utils.py index cbef21f..51364cb 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -108,6 +108,7 @@ def load_client(n, cache): load_variable("client{}_password".format(n), cache), user_agent='Mozilla/5.0 (Windows NT 6.3; WOW64; ; NCT50_AAP285C84A1328) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36', session_cookies=cache.get("client{}_session".format(n), None), + max_tries=1, ) yield client cache.set("client{}_session".format(n), client.getSession())