aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Smoker <classicsc@users.noreply.github.com>2017-02-28 19:39:24 -0800
committerSamuel Smoker <classicsc@users.noreply.github.com>2017-02-28 19:39:24 -0800
commit81c8a802ac1a234ee3ba05917ab88bb4f422c028 (patch)
tree700f3a15062ebe72c7337c751a1bd20d82239038
parent5e35e16d2ecb7cd2e27b259aa3da5b67a1d4ca4c (diff)
downloadsyncthingmanager-81c8a802ac1a234ee3ba05917ab88bb4f422c028.tar.xz
syncthingmanager-81c8a802ac1a234ee3ba05917ab88bb4f422c028.zip
Fix and test address methods
Diffstat (limited to '')
-rw-r--r--syncthingmanager/__init__.py16
-rw-r--r--syncthingmanager/tests/test_stman.py18
2 files changed, 30 insertions, 4 deletions
diff --git a/syncthingmanager/__init__.py b/syncthingmanager/__init__.py
index da8e219..0973446 100644
--- a/syncthingmanager/__init__.py
+++ b/syncthingmanager/__init__.py
@@ -193,15 +193,23 @@ class SyncthingManager(Syncthing):
address(str): a tcp://address to add.
"""
info = self.device_info(devicestr)
- base_addresses = self.system.config()['devices'][info['index']]['addresses']
- self.edit_device(devicestr, addresses, base_addresses.append(address))
+ try:
+ addresses = self.system.config()['devices'][info['index']]['addresses']
+ except TypeError:
+ raise SyncthingManagerError('Device not configured: ' + devicestr)
+ addresses.append(address)
+ self.edit_device(devicestr, 'addresses', addresses)
def device_remove_address(self, devicestr, address):
"""The inverse of device_add_address."""
info = self.device_info(devicestr)
- base_addresses = self.system.config()['devices'][info['index']]['addresses']
try:
- self.edit_device(devicestr, 'addresses', base_addresses.remove('address'))
+ addresses = self.system.config()['devices'][info['index']]['addresses']
+ except TypeError:
+ raise SyncthingManagerError('Device not configured: ' + devicestr)
+ try:
+ addresses.remove(address)
+ self.edit_device(devicestr, 'addresses', addresses)
except ValueError:
pass
diff --git a/syncthingmanager/tests/test_stman.py b/syncthingmanager/tests/test_stman.py
index 6d6d996..b2139f1 100644
--- a/syncthingmanager/tests/test_stman.py
+++ b/syncthingmanager/tests/test_stman.py
@@ -50,6 +50,24 @@ def test_edit_device(s):
assert b['compression'] == 'always'
assert b['addresses'] == address
+def test_device_add_address(s):
+ cfg = s.system.config()
+ a = next(filter(lambda x: x['name'] == 'SyncthingManagerTestDevice1', cfg['devices']))
+ s.device_add_address('SyncthingManagerTestDevice1', 'tcp://127.0.0.2:8384')
+ cfg = s.system.config()
+ b = next(filter(lambda x: x['name'] == 'SyncthingManagerTestDevice1', cfg['devices']))
+ assert 'tcp://127.0.0.2:8384' not in a['addresses']
+ assert 'tcp://127.0.0.2:8384' in b['addresses']
+
+def test_device_remove_address(s):
+ cfg = s.system.config()
+ a = next(filter(lambda x: x['name'] == 'SyncthingManagerTestDevice1', cfg['devices']))
+ s.device_remove_address('SyncthingManagerTestDevice1', 'localhost')
+ cfg = s.system.config()
+ b = next(filter(lambda x: x['name'] == 'SyncthingManagerTestDevice1', cfg['devices']))
+ assert 'localhost' in a['addresses']
+ assert 'localhost' not in b['addresses']
+
def test_device_change_name(s):
cfg = s.system.config()
a = next(filter(lambda x: x['name'] == 'SyncthingManagerTestDevice1', cfg['devices']))