mirror of
https://github.com/chatmail/core.git
synced 2026-04-06 23:52:11 +03:00
refactor bot-setup and testing into a helper function
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
|
||||
import threading
|
||||
import pytest
|
||||
import py
|
||||
import echo_and_quit
|
||||
@@ -18,56 +17,32 @@ def datadir():
|
||||
|
||||
|
||||
def test_echo_quit_plugin(acfactory):
|
||||
bot_ac, bot_cfg = acfactory.get_online_config()
|
||||
|
||||
def run_bot():
|
||||
print("*"*20 + " starting bot")
|
||||
echo_and_quit.main([
|
||||
"echo",
|
||||
"--show-ffi",
|
||||
"--db", bot_ac.db_path,
|
||||
"--email", bot_cfg["addr"],
|
||||
"--password", bot_cfg["mail_pw"],
|
||||
])
|
||||
|
||||
t = threading.Thread(target=run_bot)
|
||||
t.start()
|
||||
botproc = acfactory.run_bot_process(echo_and_quit)
|
||||
|
||||
ac1 = acfactory.get_one_online_account()
|
||||
bot_contact = ac1.create_contact(bot_cfg["addr"])
|
||||
bot_contact = ac1.create_contact(botproc.addr)
|
||||
ch1 = ac1.create_chat_by_contact(bot_contact)
|
||||
ch1.send_text("hello")
|
||||
reply = ac1._evtracker.wait_next_incoming_message()
|
||||
assert "hello" in reply.text
|
||||
assert reply.chat == ch1
|
||||
ch1.send_text("/quit")
|
||||
t.join()
|
||||
botproc.wait()
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="not implemented")
|
||||
@pytest.mark.skip(reason="botproc-matching not implementing")
|
||||
def test_group_tracking_plugin(acfactory):
|
||||
bot_ac, bot_cfg = acfactory.get_online_config()
|
||||
|
||||
def run_bot():
|
||||
print("*"*20 + " starting bot")
|
||||
print("*"*20 + " bot_ac.dbpath", bot_ac.db_path)
|
||||
group_tracking.main([
|
||||
"group-tracking",
|
||||
"--show-ffi", bot_ac.db_path,
|
||||
"--db", bot_ac.db_path,
|
||||
"--email", bot_cfg["addr"],
|
||||
"--password", bot_cfg["mail_pw"],
|
||||
])
|
||||
|
||||
t = threading.Thread(target=run_bot)
|
||||
t.setDaemon(1)
|
||||
t.start()
|
||||
botproc = acfactory.run_bot_process(group_tracking)
|
||||
|
||||
ac1 = acfactory.get_one_online_account()
|
||||
bot_contact = ac1.create_contact(bot_cfg["addr"])
|
||||
ch1 = ac1.create_chat_by_contact(bot_contact)
|
||||
bot_contact = ac1.create_contact(botproc.addr)
|
||||
ch1 = ac1.create_group_chat("bot test group")
|
||||
ch1.add_contact(bot_contact)
|
||||
ch1.send_text("hello")
|
||||
ch1.add_contact(ac1.create_contact("x@example.org"))
|
||||
|
||||
# XXX wait for bot to receive things
|
||||
t.join()
|
||||
botproc.fnmatch_lines("""
|
||||
*member_added x@example.org*
|
||||
""")
|
||||
|
||||
botproc.kill()
|
||||
|
||||
Reference in New Issue
Block a user