forked from LBRYCommunity/lbry-sdk
Updated unittest for saving of server lists in the conf file
This commit is contained in:
parent
2e3ceedc17
commit
5926b17871
2 changed files with 18 additions and 14 deletions
|
@ -538,7 +538,6 @@ class Config(object):
|
|||
path = conf_file
|
||||
else:
|
||||
path = self.get_conf_filename()
|
||||
|
||||
ext = os.path.splitext(path)[1]
|
||||
decoder = settings_decoders.get(ext, False)
|
||||
assert decoder is not False, 'Unknown settings format %s' % ext
|
||||
|
@ -645,6 +644,8 @@ def get_default_env():
|
|||
for k, v in ADJUSTABLE_SETTINGS.iteritems():
|
||||
if len(v) == 3:
|
||||
env_defaults[k] = (v[0], None, v[2])
|
||||
elif len(v) == 4:
|
||||
env_defaults[k] = (v[0], None, v[2], v[3])
|
||||
else:
|
||||
env_defaults[k] = (v[0], None)
|
||||
return Env(**env_defaults)
|
||||
|
|
|
@ -4,6 +4,8 @@ import json
|
|||
from twisted.trial import unittest
|
||||
from lbrynet import conf
|
||||
from lbrynet.core.Error import InvalidCurrencyError
|
||||
from lbrynet.tests import mocks
|
||||
from lbrynet.tests.util import create_conf_file
|
||||
|
||||
class SettingsTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
@ -78,17 +80,18 @@ class SettingsTest(unittest.TestCase):
|
|||
self.assertEqual(str, type(conf.default_data_dir))
|
||||
self.assertEqual(str, type(conf.default_lbryum_dir))
|
||||
|
||||
def test_conversion_reversal(self):
|
||||
# simulate decoding, conversion, conversion reversal and encoding of
|
||||
# server list settings from the config file.
|
||||
settings = self.get_mock_config_instance()
|
||||
encoder = conf.settings_encoders['.yml']
|
||||
decoder = conf.settings_decoders['.yml']
|
||||
conf_file_entry = "lbryum_servers: ['localhost:5001', 'localhost:5002']"
|
||||
decoded = decoder(conf_file_entry)
|
||||
converted = settings._convert_conf_file_lists(decoded)
|
||||
converted_reversed = settings._convert_conf_file_lists_reverse(converted)
|
||||
encoded = encoder(converted_reversed)
|
||||
self.assertEqual(conf_file_entry, encoded.strip())
|
||||
self.assertEqual(decoded, converted_reversed)
|
||||
def test_load_save_load_config_file(self):
|
||||
#settings = self.get_mock_config_instance()
|
||||
conf_entry = 'lbryum_servers: ["localhost:50001", "localhost:50002"]\n'
|
||||
conf_temp = create_conf_file(conf_entry)
|
||||
conf.conf_file = conf_temp
|
||||
adjustable_settings={'data_dir': (str, conf.default_data_dir),
|
||||
'lbryum_servers': (list, [('localhost', 5001)],
|
||||
conf.server_list, conf.server_list_reverse)}
|
||||
env = conf.Env(**adjustable_settings)
|
||||
settings = conf.Config({}, adjustable_settings, environment=env)
|
||||
conf.settings = settings
|
||||
settings.load_conf_file_settings()
|
||||
settings.save_conf_file_settings()
|
||||
settings.load_conf_file_settings()
|
||||
|
||||
|
|
Loading…
Reference in a new issue