mirror of
https://git.deluge-torrent.org/deluge
synced 2025-04-21 03:54:50 +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))
|
||||
|
||||
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]
|
||||
self.assertEquals(self.deluge_web.web_api._get_host(conn[0]), conn)
|
||||
|
||||
def test_add_host(self):
|
||||
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
|
||||
ret = self.deluge_web.web_api.add_host(conn[1], conn[2], conn[3], conn[4])
|
||||
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)
|
||||
# Remove valid host
|
||||
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
|
||||
self.assertFalse(self.deluge_web.web_api.remove_host(conn[0]))
|
||||
|
||||
|
|
|
@ -396,15 +396,11 @@ class WebApi(JSONComponent):
|
|||
component.get("Web.PluginManager").start()
|
||||
else:
|
||||
client.set_disconnect_callback(self._on_client_disconnect)
|
||||
|
||||
if component.get("DelugeWeb").config["default_daemon"]:
|
||||
# Sort out getting the default daemon here
|
||||
default = component.get("DelugeWeb").config["default_daemon"]
|
||||
host = component.get("Web")._get_host(default)
|
||||
if host:
|
||||
return self._connect_daemon(*host[1:])
|
||||
else:
|
||||
return self._connect_daemon()
|
||||
default_host_id = component.get("DelugeWeb").config["default_daemon"]
|
||||
host_info = component.get("Web")._get_host(default_host_id)
|
||||
return self._connect_daemon(*host_info[1:])
|
||||
|
||||
return defer.succeed(True)
|
||||
|
||||
|
@ -413,17 +409,21 @@ class WebApi(JSONComponent):
|
|||
return self.stop()
|
||||
|
||||
def _get_host(self, host_id):
|
||||
"""
|
||||
Return the information about a host
|
||||
"""Information about a host from supplied host id.
|
||||
|
||||
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"]:
|
||||
if host[0] == host_id:
|
||||
return host
|
||||
host_info = []
|
||||
for host_entry in self.host_list["hosts"]:
|
||||
if host_entry[0] == host_id:
|
||||
host_info = host_entry
|
||||
break
|
||||
return host_info
|
||||
|
||||
def start(self):
|
||||
self.core_config.start()
|
||||
|
@ -866,7 +866,7 @@ class WebApi(JSONComponent):
|
|||
:type host_id: string
|
||||
"""
|
||||
host = self._get_host(connection_id)
|
||||
if host is None:
|
||||
if not host:
|
||||
return False
|
||||
|
||||
self.host_list["hosts"].remove(host)
|
||||
|
|
Loading…
Add table
Reference in a new issue