Merge branch 'hackrush_max_key'
This commit is contained in:
commit
9d7067f3b7
4 changed files with 36 additions and 1 deletions
|
@ -12,6 +12,10 @@ at anytime.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
||||||
|
### Added
|
||||||
|
* Added validation of currencies.
|
||||||
|
*
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,6 +8,7 @@ import yaml
|
||||||
import envparse
|
import envparse
|
||||||
from appdirs import user_data_dir, user_config_dir
|
from appdirs import user_data_dir, user_config_dir
|
||||||
from lbrynet.core import utils
|
from lbrynet.core import utils
|
||||||
|
from lbrynet.core.Error import InvalidCurrencyError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
|
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
|
||||||
|
@ -351,6 +352,10 @@ class Config(object):
|
||||||
assert name not in self._fixed_defaults, \
|
assert name not in self._fixed_defaults, \
|
||||||
ValueError('{} is not an editable setting'.format(name))
|
ValueError('{} is not an editable setting'.format(name))
|
||||||
|
|
||||||
|
def _validate_currency(self, currency):
|
||||||
|
if currency not in self._fixed_defaults['CURRENCIES'].keys():
|
||||||
|
raise InvalidCurrencyError(currency)
|
||||||
|
|
||||||
def get(self, name, data_type=None):
|
def get(self, name, data_type=None):
|
||||||
"""Get a config value
|
"""Get a config value
|
||||||
|
|
||||||
|
@ -388,6 +393,10 @@ class Config(object):
|
||||||
data types (e.g. PERSISTED values to save to a file, CLI values from parsed
|
data types (e.g. PERSISTED values to save to a file, CLI values from parsed
|
||||||
command-line options, etc), you can specify that with the data_types param
|
command-line options, etc), you can specify that with the data_types param
|
||||||
"""
|
"""
|
||||||
|
if name == "max_key_fee":
|
||||||
|
currency = str(value["currency"]).upper()
|
||||||
|
self._validate_currency(currency)
|
||||||
|
|
||||||
self._assert_editable_setting(name)
|
self._assert_editable_setting(name)
|
||||||
for data_type in data_types:
|
for data_type in data_types:
|
||||||
self._assert_valid_data_type(data_type)
|
self._assert_valid_data_type(data_type)
|
||||||
|
|
|
@ -139,3 +139,9 @@ class InvalidAuthenticationToken(Exception):
|
||||||
|
|
||||||
class NegotiationError(Exception):
|
class NegotiationError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class InvalidCurrencyError(Exception):
|
||||||
|
def __init__(self, currency):
|
||||||
|
self.currency = currency
|
||||||
|
Exception.__init__(
|
||||||
|
self, 'Invalid currency: {} is not a supported currency.'.format(currency))
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
from lbrynet import conf
|
from lbrynet import conf
|
||||||
|
from lbrynet.core.Error import InvalidCurrencyError
|
||||||
|
|
||||||
class SettingsTest(unittest.TestCase):
|
class SettingsTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -54,6 +55,21 @@ class SettingsTest(unittest.TestCase):
|
||||||
settings.set('test', 'runtime_takes_precedence', data_types=(conf.TYPE_RUNTIME,))
|
settings.set('test', 'runtime_takes_precedence', data_types=(conf.TYPE_RUNTIME,))
|
||||||
self.assertEqual('runtime_takes_precedence', settings['test'])
|
self.assertEqual('runtime_takes_precedence', settings['test'])
|
||||||
|
|
||||||
|
def test_max_key_fee_set(self):
|
||||||
|
fixed_default = {'CURRENCIES':{'BTC':{'type':'crypto'}}}
|
||||||
|
adjustable_settings = {'max_key_fee': (json.loads, {'currency':'USD', 'amount':1})}
|
||||||
|
env = conf.Env(**adjustable_settings)
|
||||||
|
settings = conf.Config(fixed_default, adjustable_settings, environment=env)
|
||||||
|
|
||||||
|
with self.assertRaises(InvalidCurrencyError):
|
||||||
|
settings.set('max_key_fee', {'currency':'USD', 'amount':1})
|
||||||
|
|
||||||
|
valid_setting= {'currency':'BTC', 'amount':1}
|
||||||
|
settings.set('max_key_fee', valid_setting )
|
||||||
|
out = settings.get('max_key_fee')
|
||||||
|
self.assertEqual(out, valid_setting)
|
||||||
|
|
||||||
|
|
||||||
def test_data_dir(self):
|
def test_data_dir(self):
|
||||||
# check if these directories are returned as string and not unicode
|
# check if these directories are returned as string and not unicode
|
||||||
# otherwise there will be problems when calling os.path.join on
|
# otherwise there will be problems when calling os.path.join on
|
||||||
|
|
Loading…
Reference in a new issue