From 5c1ec8dbb30f315473d7523062bd386f72838ecc Mon Sep 17 00:00:00 2001 From: Martijn Voncken Date: Sat, 16 Aug 2008 15:35:37 +0000 Subject: [PATCH] move client tests --- deluge/tests/test_client.py | 83 +++++++++++++++++++++++++++++++++++++ deluge/ui/client.py | 82 ------------------------------------ 2 files changed, 83 insertions(+), 82 deletions(-) create mode 100644 deluge/tests/test_client.py diff --git a/deluge/tests/test_client.py b/deluge/tests/test_client.py new file mode 100644 index 000000000..d533f7a20 --- /dev/null +++ b/deluge/tests/test_client.py @@ -0,0 +1,83 @@ +#------------------------------------------------------------------------------ +#tests: +#------------------------------------------------------------------------------ + +from deluge.ui.client import aclient, sclient + +def test_introspection(): + print("*start introspection test*") + sclient.set_core_uri() + print("list_methods", sclient.list_methods()) + print("sig of block_ip_range", sclient.methodSignature('block_ip_range')) + print("doc of block_ip_range", sclient.methodHelp('block_ip_range')) + +def test_sync(): + print("*start sync test*") + sclient.set_core_uri() + + #get list of torrents and display the 1st. + torrent_ids = sclient.get_session_state() + print("session_state():", torrent_ids) + print("get_torrent_status(%s):" % torrent_ids[0], + sclient.get_torrent_status(torrent_ids[0], [])) + + sclient.pause_torrent(torrent_ids) + + print("paused:", [ + sclient.get_torrent_status(id, ['paused'])['paused'] + for id in torrent_ids]) + + sclient.resume_torrent(torrent_ids) + print("resumed:", [ + sclient.get_torrent_status(id, ['paused'])['paused'] + for id in torrent_ids]) + +def test_async(): + print("*start async test*") + torrent_ids = [] + + #callbacks: + def cb_session_state(temp_torrent_list): + print("session_state:" , temp_torrent_list) + torrent_ids.extend(temp_torrent_list) + + def cb_torrent_status_full(status): + print("\ntorrent_status_full=", status) + + def cb_torrent_status_paused(torrent_state): + print("paused=%s" % torrent_state['paused']) + + #/callbacks + + aclient.set_core_uri() + aclient.get_session_state(cb_session_state) + + print("force_call 1") + aclient.force_call(block=True) + print("end force_call 1:", len(torrent_ids)) + + + #has_callback+multicall + aclient.pause_torrent(torrent_ids) + aclient.force_call(block=True) + for id in torrent_ids: + aclient.get_torrent_status(cb_torrent_status_paused, id , ['paused']) + + aclient.get_torrent_status(cb_torrent_status_full, torrent_ids[0], []) + + print("force_call 2") + aclient.force_call(block=True) + print("end force-call 2") + + + + print("resume:") + aclient.resume_torrent(torrent_ids) + for id in torrent_ids: + aclient.get_torrent_status(cb_torrent_status_paused, id , ['paused']) + + aclient.force_call(block=True) + +test_introspection() +test_sync() +test_async() diff --git a/deluge/ui/client.py b/deluge/ui/client.py index 09e5a13c4..68fb5c989 100644 --- a/deluge/ui/client.py +++ b/deluge/ui/client.py @@ -313,85 +313,3 @@ class AClient(BaseClient): sclient = SClient() aclient = AClient() -#------------------------------------------------------------------------------ -#tests: -#------------------------------------------------------------------------------ - -def test_introspection(): - print("*start introspection test*") - sclient.set_core_uri() - print("list_methods", sclient.list_methods()) - print("sig of block_ip_range", sclient.methodSignature('block_ip_range')) - print("doc of block_ip_range", sclient.methodHelp('block_ip_range')) - -def test_sync(): - print("*start sync test*") - sclient.set_core_uri() - - #get list of torrents and display the 1st. - torrent_ids = sclient.get_session_state() - print("session_state():", torrent_ids) - print("get_torrent_status(%s):" % torrent_ids[0], - sclient.get_torrent_status(torrent_ids[0], [])) - - sclient.pause_torrent(torrent_ids) - - print("paused:", [ - sclient.get_torrent_status(id, ['paused'])['paused'] - for id in torrent_ids]) - - sclient.resume_torrent(torrent_ids) - print("resumed:", [ - sclient.get_torrent_status(id, ['paused'])['paused'] - for id in torrent_ids]) - -def test_async(): - print("*start async test*") - torrent_ids = [] - - #callbacks: - def cb_session_state(temp_torrent_list): - print("session_state:" , temp_torrent_list) - torrent_ids.extend(temp_torrent_list) - - def cb_torrent_status_full(status): - print("\ntorrent_status_full=", status) - - def cb_torrent_status_paused(torrent_state): - print("paused=%s" % torrent_state['paused']) - - #/callbacks - - aclient.set_core_uri() - aclient.get_session_state(cb_session_state) - - print("force_call 1") - aclient.force_call(block=True) - print("end force_call 1:", len(torrent_ids)) - - - #has_callback+multicall - aclient.pause_torrent(torrent_ids) - aclient.force_call(block=True) - for id in torrent_ids: - aclient.get_torrent_status(cb_torrent_status_paused, id , ['paused']) - - aclient.get_torrent_status(cb_torrent_status_full, torrent_ids[0], []) - - print("force_call 2") - aclient.force_call(block=True) - print("end force-call 2") - - - - print("resume:") - aclient.resume_torrent(torrent_ids) - for id in torrent_ids: - aclient.get_torrent_status(cb_torrent_status_paused, id , ['paused']) - - aclient.force_call(block=True) - -if __name__ == "__main__": - test_introspection() - test_sync() - test_async()