mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
sipmlify plugins and tests and remove superflous core event
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
|
||||
import deltachat
|
||||
|
||||
class SimpleEchoPlugin:
|
||||
|
||||
class EchoPlugin:
|
||||
@deltachat.hookspec.account_hookimpl
|
||||
def process_incoming_message(self, message):
|
||||
print("process_incoming message", message)
|
||||
@@ -20,6 +21,9 @@ class SimpleEchoPlugin:
|
||||
print("process_message_delivered", message)
|
||||
|
||||
|
||||
if __name__ = "__main__":
|
||||
deltachat.run_simple_cmdline(account_plugins=[SimpleEchoPlugin()])
|
||||
def main(argv=None):
|
||||
deltachat.run_cmdline(argv=argv, account_plugins=[EchoPlugin()])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
|
||||
# content of group_tracking.py
|
||||
|
||||
import sys
|
||||
import optparse
|
||||
import deltachat
|
||||
|
||||
|
||||
@@ -25,40 +23,9 @@ class GroupTrackingPlugin:
|
||||
print("*** member_removed", contact.addr, "from", chat)
|
||||
|
||||
|
||||
def main(argv):
|
||||
p = optparse.OptionParser("simple-echo")
|
||||
p.add_option("-l", action="store_true", help="show ffi")
|
||||
p.add_option("--db", type="str", help="database file")
|
||||
p.add_option("--email", type="str", help="email address")
|
||||
p.add_option("--password", type="str", help="password")
|
||||
|
||||
opts, posargs = p.parse_args(argv)
|
||||
|
||||
assert opts.db, "you must specify --db"
|
||||
ac = deltachat.Account(opts.db)
|
||||
|
||||
if opts.l:
|
||||
log = deltachat.eventlogger.FFIEventLogger(ac, "group-tracking")
|
||||
ac.add_account_plugin(log)
|
||||
|
||||
if not ac.is_configured():
|
||||
assert opts.email and opts.password, (
|
||||
"you must specify --email and --password"
|
||||
)
|
||||
ac.set_config("addr", opts.email)
|
||||
ac.set_config("mail_pw", opts.password)
|
||||
ac.set_config("mvbox_watch", "0")
|
||||
ac.set_config("sentbox_watch", "0")
|
||||
|
||||
ac.add_account_plugin(GroupTrackingPlugin())
|
||||
|
||||
# start IO threads and configure if neccessary
|
||||
ac.start()
|
||||
|
||||
print("{}: waiting for message".format(ac.get_config("addr")))
|
||||
|
||||
ac.wait_shutdown()
|
||||
def main(argv=None):
|
||||
deltachat.run_cmdline(argv=argv, account_plugins=[GroupTrackingPlugin()])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
||||
main()
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
import threading
|
||||
import pytest
|
||||
import py
|
||||
from echo_and_quit import main
|
||||
import echo_and_quit
|
||||
import group_tracking
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
@@ -21,11 +22,13 @@ def test_echo_quit_plugin(acfactory):
|
||||
|
||||
def run_bot():
|
||||
print("*"*20 + " starting bot")
|
||||
main([
|
||||
"-l",
|
||||
print("*"*20 + " bot_ac.dbpath", bot_ac.db_path)
|
||||
echo_and_quit.main([
|
||||
"echo",
|
||||
"--show-ffi",
|
||||
"--db", bot_ac.db_path,
|
||||
"--email", bot_cfg["addr"],
|
||||
"--password", bot_cfg["mail_pw"],
|
||||
"--db", bot_ac.db_path
|
||||
])
|
||||
|
||||
t = threading.Thread(target=run_bot)
|
||||
@@ -39,3 +42,32 @@ def test_echo_quit_plugin(acfactory):
|
||||
assert "hello" in reply.text
|
||||
ch1.send_text("/quit")
|
||||
t.join()
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="not implemented")
|
||||
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()
|
||||
|
||||
ac1 = acfactory.get_one_online_account()
|
||||
bot_contact = ac1.create_contact(bot_cfg["addr"])
|
||||
ch1 = ac1.create_chat_by_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()
|
||||
|
||||
Reference in New Issue
Block a user