mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-07 08:58:38 +00:00
[WebUI] Refactor json_api._get_host
This commit is contained in:
parent
9f187ed027
commit
fa309d0d18
2 changed files with 20 additions and 20 deletions
|
@ -139,13 +139,13 @@ class WebAPITestCase(BaseTestCase, DaemonBase):
|
||||||
self.assertEquals(status, tuple(status))
|
self.assertEquals(status, tuple(status))
|
||||||
|
|
||||||
def test_get_host(self):
|
def test_get_host(self):
|
||||||
self.assertEquals(self.deluge_web.web_api._get_host("invalid_id"), None)
|
self.assertFalse(self.deluge_web.web_api._get_host("invalid_id"))
|
||||||
conn = self.deluge_web.web_api.host_list["hosts"][0]
|
conn = self.deluge_web.web_api.host_list["hosts"][0]
|
||||||
self.assertEquals(self.deluge_web.web_api._get_host(conn[0]), conn)
|
self.assertEquals(self.deluge_web.web_api._get_host(conn[0]), conn)
|
||||||
|
|
||||||
def test_add_host(self):
|
def test_add_host(self):
|
||||||
conn = [None, '', 0, '', '']
|
conn = [None, '', 0, '', '']
|
||||||
self.assertEquals(self.deluge_web.web_api._get_host(conn[0]), None)
|
self.assertFalse(self.deluge_web.web_api._get_host(conn[0]))
|
||||||
# Add valid host
|
# Add valid host
|
||||||
ret = self.deluge_web.web_api.add_host(conn[1], conn[2], conn[3], conn[4])
|
ret = self.deluge_web.web_api.add_host(conn[1], conn[2], conn[3], conn[4])
|
||||||
self.assertEquals(ret[0], True)
|
self.assertEquals(ret[0], True)
|
||||||
|
@ -167,7 +167,7 @@ class WebAPITestCase(BaseTestCase, DaemonBase):
|
||||||
self.assertEquals(self.deluge_web.web_api._get_host(conn[0]), conn)
|
self.assertEquals(self.deluge_web.web_api._get_host(conn[0]), conn)
|
||||||
# Remove valid host
|
# Remove valid host
|
||||||
self.assertTrue(self.deluge_web.web_api.remove_host(conn[0]))
|
self.assertTrue(self.deluge_web.web_api.remove_host(conn[0]))
|
||||||
self.assertEquals(self.deluge_web.web_api._get_host(conn[0]), None)
|
self.assertFalse(self.deluge_web.web_api._get_host(conn[0]))
|
||||||
# Remove non-existing host
|
# Remove non-existing host
|
||||||
self.assertFalse(self.deluge_web.web_api.remove_host(conn[0]))
|
self.assertFalse(self.deluge_web.web_api.remove_host(conn[0]))
|
||||||
|
|
||||||
|
|
|
@ -396,15 +396,11 @@ class WebApi(JSONComponent):
|
||||||
component.get("Web.PluginManager").start()
|
component.get("Web.PluginManager").start()
|
||||||
else:
|
else:
|
||||||
client.set_disconnect_callback(self._on_client_disconnect)
|
client.set_disconnect_callback(self._on_client_disconnect)
|
||||||
|
|
||||||
if component.get("DelugeWeb").config["default_daemon"]:
|
if component.get("DelugeWeb").config["default_daemon"]:
|
||||||
# Sort out getting the default daemon here
|
# Sort out getting the default daemon here
|
||||||
default = component.get("DelugeWeb").config["default_daemon"]
|
default_host_id = component.get("DelugeWeb").config["default_daemon"]
|
||||||
host = component.get("Web")._get_host(default)
|
host_info = component.get("Web")._get_host(default_host_id)
|
||||||
if host:
|
return self._connect_daemon(*host_info[1:])
|
||||||
return self._connect_daemon(*host[1:])
|
|
||||||
else:
|
|
||||||
return self._connect_daemon()
|
|
||||||
|
|
||||||
return defer.succeed(True)
|
return defer.succeed(True)
|
||||||
|
|
||||||
|
@ -413,17 +409,21 @@ class WebApi(JSONComponent):
|
||||||
return self.stop()
|
return self.stop()
|
||||||
|
|
||||||
def _get_host(self, host_id):
|
def _get_host(self, host_id):
|
||||||
"""
|
"""Information about a host from supplied host id.
|
||||||
Return the information about a host
|
|
||||||
|
Args:
|
||||||
|
host_id (str): The id of the host.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: The host information, empty list if not found.
|
||||||
|
|
||||||
:param host_id: the id of the host
|
|
||||||
:type host_id: string
|
|
||||||
:returns: the host information
|
|
||||||
:rtype: list
|
|
||||||
"""
|
"""
|
||||||
for host in self.host_list["hosts"]:
|
host_info = []
|
||||||
if host[0] == host_id:
|
for host_entry in self.host_list["hosts"]:
|
||||||
return host
|
if host_entry[0] == host_id:
|
||||||
|
host_info = host_entry
|
||||||
|
break
|
||||||
|
return host_info
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.core_config.start()
|
self.core_config.start()
|
||||||
|
@ -866,7 +866,7 @@ class WebApi(JSONComponent):
|
||||||
:type host_id: string
|
:type host_id: string
|
||||||
"""
|
"""
|
||||||
host = self._get_host(connection_id)
|
host = self._get_host(connection_id)
|
||||||
if host is None:
|
if not host:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.host_list["hosts"].remove(host)
|
self.host_list["hosts"].remove(host)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue