More test improvements
This commit is contained in:
@@ -80,7 +80,7 @@ def catch_event(client2):
|
|||||||
try:
|
try:
|
||||||
# Make the client send a messages to itself, so the blocking pull request will return
|
# 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
|
# 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:
|
finally:
|
||||||
t.join()
|
t.join()
|
||||||
|
|
||||||
|
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"email": "",
|
|
||||||
"password": "",
|
|
||||||
"user_thread_id": "",
|
|
||||||
"group_thread_id": ""
|
|
||||||
}
|
|
BIN
tests/resources/audio.mp3
Normal file
BIN
tests/resources/audio.mp3
Normal file
Binary file not shown.
4
tests/resources/file.json
Normal file
4
tests/resources/file.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"some": "data",
|
||||||
|
"in": "here"
|
||||||
|
}
|
1
tests/resources/file.txt
Normal file
1
tests/resources/file.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
This is just a text file
|
BIN
tests/resources/image.gif
Normal file
BIN
tests/resources/image.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
tests/resources/image.jpg
Normal file
BIN
tests/resources/image.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
BIN
tests/resources/video.mp4
Normal file
BIN
tests/resources/video.mp4
Normal file
Binary file not shown.
@@ -59,7 +59,7 @@ def test_fetch_info(client1, group):
|
|||||||
|
|
||||||
|
|
||||||
def test_fetch_image_url(client):
|
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)
|
client.sendLocalImage(url)
|
||||||
message, = client.fetchThreadMessages(limit=1)
|
message, = client.fetchThreadMessages(limit=1)
|
||||||
|
@@ -65,6 +65,7 @@ def test_send_sticker(client, catch_event, compare, sticker):
|
|||||||
assert subset(vars(x.res["message_object"].sticker), uid=sticker.uid)
|
assert subset(vars(x.res["message_object"].sticker), uid=sticker.uid)
|
||||||
|
|
||||||
|
|
||||||
|
# Kept for backwards compatability
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"method_name, url",
|
"method_name, url",
|
||||||
[
|
[
|
||||||
@@ -72,7 +73,7 @@ def test_send_sticker(client, catch_event, compare, sticker):
|
|||||||
"sendRemoteImage",
|
"sendRemoteImage",
|
||||||
"https://github.com/carpedm20/fbchat/raw/master/tests/image.png",
|
"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):
|
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 compare(x, mid=mid, message=text)
|
||||||
assert subset(vars(x.res["message_object"]), uid=mid, author=client.uid, text=text)
|
assert subset(vars(x.res["message_object"]), uid=mid, author=client.uid, text=text)
|
||||||
assert x.res["message_object"].attachments[0]
|
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)
|
||||||
|
@@ -108,6 +108,7 @@ def load_client(n, cache):
|
|||||||
load_variable("client{}_password".format(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',
|
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),
|
session_cookies=cache.get("client{}_session".format(n), None),
|
||||||
|
max_tries=1,
|
||||||
)
|
)
|
||||||
yield client
|
yield client
|
||||||
cache.set("client{}_session".format(n), client.getSession())
|
cache.set("client{}_session".format(n), client.getSession())
|
||||||
|
Reference in New Issue
Block a user