Updated unittest for saving of server lists in the conf file

This commit is contained in:
jleute 2018-05-19 01:32:51 +02:00
parent 348544428f
commit b543c04572
3 changed files with 22 additions and 14 deletions

View file

@ -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)

View file

@ -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()

View file

@ -19,6 +19,10 @@ DEFAULT_ISO_TIME = time.mktime(DEFAULT_TIMESTAMP.timetuple())
log = logging.getLogger("lbrynet.tests.util")
def create_conf_file(entry):
with tempfile.NamedTemporaryFile(delete=False, suffix='.yml') as conf:
conf.write(entry)
return conf.name
def mk_db_and_blob_dir():
db_dir = tempfile.mkdtemp()