update tests
This commit is contained in:
parent
f96a59680a
commit
13dc94a687
|
@ -1 +1 @@
|
||||||
{"unicode1_master_slaves_requires.options.unicode.unicode": [], "unicode1_master_slaves_requires.options.unicode.unicode1": [], "unicode1_master_slaves_requires.options.unicode.unicode2": []}
|
{"unicode1_master_slaves_requires.options.unicode.unicode": [], "unicode1_master_slaves_requires.options.unicode.unicode1": [], "unicode1_master_slaves_requires.options.unicode.unicode2": [], "unicode1_master_slaves_requires.options.unicode.unicode3": []}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"unicode1_master_slaves_requires_slave.options.unicode1.unicode1": [], "unicode1_master_slaves_requires_slave.options.unicode1.unicode2": []}
|
{"unicode1_master_slaves_requires_slave.options.unicode1.unicode1": [], "unicode1_master_slaves_requires_slave.options.unicode1.unicode2": [], "unicode1_master_slaves_requires_slave.options.unicode1.unicode3": []}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"unicode1_master_slaves_requires_slave_value.options.unicode1.unicode1": ["test", "pas test"], "unicode1_master_slaves_requires_slave_value.options.unicode1.unicode2": ["super1", null]}
|
{"unicode1_master_slaves_requires_slave_value.options.unicode1.unicode1": ["test", "pas test"], "unicode1_master_slaves_requires_slave_value.options.unicode1.unicode2": ["super1", null], "unicode1_master_slaves_requires_slave_value.options.unicode1.unicode3": ["super1", null]}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"unicode1_master_slaves_requires_slaves.options.unicode1.unicode1": [], "unicode1_master_slaves_requires_slaves.options.unicode1.unicode2": []}
|
{"unicode1_master_slaves_requires_slaves.options.unicode1.unicode1": [], "unicode1_master_slaves_requires_slaves.options.unicode1.unicode2": [], "unicode1_master_slaves_requires_slaves.options.unicode1.unicode3": []}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{"options.unicode": "val"}
|
|
@ -0,0 +1,5 @@
|
||||||
|
{"cmd": "config.option('options.unicode').value.set('val')",
|
||||||
|
"body": {"updates": [{"action": "modify",
|
||||||
|
"name": "options.unicode",
|
||||||
|
"value": "val"}]}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{"updates": ["options.unicode"],
|
||||||
|
"model": [{"key": "options.unicode",
|
||||||
|
"owner": "user",
|
||||||
|
"value": "val"}]}
|
|
@ -1 +1 @@
|
||||||
{"options.unicode.unicode": [], "options.unicode.unicode1": [], "options.unicode.unicode2": []}
|
{"options.unicode.unicode": [], "options.unicode.unicode1": [], "options.unicode.unicode2": [], "options.unicode.unicode3": []}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"options.unicode1.unicode1": [], "options.unicode1.unicode2": []}
|
{"options.unicode1.unicode1": [], "options.unicode1.unicode2": [], "options.unicode1.unicode3": []}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"options.unicode1.unicode1": ["test", "pas test"], "options.unicode1.unicode2": ["super1", null]}
|
{"options.unicode1.unicode1": ["test", "pas test"], "options.unicode1.unicode2": ["super1", null], "options.unicode1.unicode3": ["super1", null]}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"options.unicode1.unicode1": [], "options.unicode1.unicode2": []}
|
{"options.unicode1.unicode1": [], "options.unicode1.unicode2": [], "options.unicode1.unicode3": []}
|
||||||
|
|
|
@ -11,12 +11,12 @@ from tiramisu_json_api import Config
|
||||||
# warnings.simplefilter("always", ValueWarning)
|
# warnings.simplefilter("always", ValueWarning)
|
||||||
|
|
||||||
|
|
||||||
def list_data():
|
def list_data(ext='.json'):
|
||||||
datadir = join(normpath(dirname(abspath(__file__))), 'data')
|
datadir = join(normpath(dirname(abspath(__file__))), 'data')
|
||||||
filenames = listdir(datadir)
|
filenames = listdir(datadir)
|
||||||
filenames.sort()
|
filenames.sort()
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
if filename.endswith('.json'):
|
if filename.endswith(ext):
|
||||||
yield join(datadir, filename)
|
yield join(datadir, filename)
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,8 +24,6 @@ def test_dict():
|
||||||
debug = False
|
debug = False
|
||||||
# debug = True
|
# debug = True
|
||||||
for filename in list_data():
|
for filename in list_data():
|
||||||
if 'master' in filename:
|
|
||||||
continue
|
|
||||||
if debug:
|
if debug:
|
||||||
print('test_jsons', filename)
|
print('test_jsons', filename)
|
||||||
with open(filename, 'r') as fh:
|
with open(filename, 'r') as fh:
|
||||||
|
@ -33,7 +31,13 @@ def test_dict():
|
||||||
#
|
#
|
||||||
config = Config(json)
|
config = Config(json)
|
||||||
with open(filename[:-4] + 'dict', 'r') as fh:
|
with open(filename[:-4] + 'dict', 'r') as fh:
|
||||||
assert loads(fh.read()) == config.value.dict()
|
dico = loads(fh.read())
|
||||||
|
if debug:
|
||||||
|
from pprint import pprint
|
||||||
|
pprint(dico)
|
||||||
|
print('-----')
|
||||||
|
pprint(config.value.dict())
|
||||||
|
assert dico == config.value.dict()
|
||||||
|
|
||||||
|
|
||||||
def test_get():
|
def test_get():
|
||||||
|
@ -106,3 +110,39 @@ def test_info():
|
||||||
if info == 'type' and value in ['filename', 'ip', 'email', 'username']:
|
if info == 'type' and value in ['filename', 'ip', 'email', 'username']:
|
||||||
continue
|
continue
|
||||||
assert getattr(config.option(key).option, info)() == value, 'error for {} in {}'.format(info, filename)
|
assert getattr(config.option(key).option, info)() == value, 'error for {} in {}'.format(info, filename)
|
||||||
|
|
||||||
|
|
||||||
|
def test_mod():
|
||||||
|
debug = False
|
||||||
|
# debug = True
|
||||||
|
for filename in list_data('.mod1'):
|
||||||
|
if 'master' in filename:
|
||||||
|
continue
|
||||||
|
if debug:
|
||||||
|
print('test_mod', filename)
|
||||||
|
with open(filename[:-4] + 'json', 'r') as fh:
|
||||||
|
json = loads(fh.read())
|
||||||
|
#
|
||||||
|
config = Config(json)
|
||||||
|
with open(filename) as fh:
|
||||||
|
mod = loads(fh.read())
|
||||||
|
eval(mod['cmd'])
|
||||||
|
#
|
||||||
|
if debug:
|
||||||
|
from pprint import pprint
|
||||||
|
pprint(config.updates)
|
||||||
|
print('----------------')
|
||||||
|
pprint(mod['body']['updates'])
|
||||||
|
assert config.updates == mod['body']['updates']
|
||||||
|
#
|
||||||
|
with open(filename[:-4] + 'dict1', 'r') as fh:
|
||||||
|
dico1 = loads(fh.read())
|
||||||
|
assert dico1 == config.value.dict()
|
||||||
|
#
|
||||||
|
with open(filename[:-4] + 'updates1', 'r') as fh:
|
||||||
|
data = loads(fh.read())
|
||||||
|
if debug:
|
||||||
|
from pprint import pprint
|
||||||
|
pprint(data)
|
||||||
|
config.updates_data(data)
|
||||||
|
assert dico1 == config.value.dict()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from typing import Optional, Dict, List, Any
|
from typing import Optional, Dict, List, Any
|
||||||
|
from copy import copy
|
||||||
import warnings
|
import warnings
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -126,22 +127,30 @@ class _Value:
|
||||||
schema: Dict,
|
schema: Dict,
|
||||||
root: str,
|
root: str,
|
||||||
fullpath: bool,
|
fullpath: bool,
|
||||||
withwarning: bool):
|
withwarning: bool,
|
||||||
|
parent_key: str=None) -> None:
|
||||||
|
len_master = None
|
||||||
for key, option in schema['properties'].items():
|
for key, option in schema['properties'].items():
|
||||||
hidden = self.temp.get(key, {}).get('hidden', None)
|
hidden = self.temp.get(key, {}).get('hidden', None)
|
||||||
model_display = not self.model.get(key, {}).get('hidden', False) and \
|
model_display = not self.model.get(key, {}).get('hidden', False) and \
|
||||||
self.model.get(key, {}).get('display', True)
|
self.model.get(key, {}).get('display', True)
|
||||||
|
|
||||||
if hidden is False or (hidden is None and model_display is True):
|
if hidden is False or (hidden is None and model_display is True):
|
||||||
if option['type'] == 'object':
|
if option['type'] in ['object', 'array']:
|
||||||
self._dict_walk(ret,
|
self._dict_walk(ret,
|
||||||
option,
|
option,
|
||||||
root,
|
root,
|
||||||
fullpath,
|
fullpath,
|
||||||
withwarning)
|
withwarning,
|
||||||
|
key)
|
||||||
else:
|
else:
|
||||||
value = self.config.get_value(key)
|
value = self.config.get_value(key, len_master)
|
||||||
|
if parent_key is not None and schema.get('type') == 'array' and len_master is None:
|
||||||
|
len_master = len(value)
|
||||||
self._display_warnings(key, value, option['type'], option['name'], withwarning)
|
self._display_warnings(key, value, option['type'], option['name'], withwarning)
|
||||||
ret[key] = value
|
ret[key] = value
|
||||||
|
elif parent_key is not None and schema.get('type') == 'array' and len_master is None:
|
||||||
|
break
|
||||||
|
|
||||||
def dict(self,
|
def dict(self,
|
||||||
fullpath: bool=False,
|
fullpath: bool=False,
|
||||||
|
@ -470,7 +479,7 @@ class Config:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
json):
|
json):
|
||||||
self.model_ori = json['model']
|
self.model_ori = json['model']
|
||||||
self.model = {option['key']: option for option in json['model']}
|
self.model = self.gen_model(json['model'])
|
||||||
self.form = {}
|
self.form = {}
|
||||||
for option in json['form']:
|
for option in json['form']:
|
||||||
if 'key' in option:
|
if 'key' in option:
|
||||||
|
@ -486,6 +495,23 @@ class Config:
|
||||||
else:
|
else:
|
||||||
self.root = ''
|
self.root = ''
|
||||||
|
|
||||||
|
def gen_model(self,
|
||||||
|
model) -> List[Dict]:
|
||||||
|
ret = {}
|
||||||
|
for option in model:
|
||||||
|
key = option['key']
|
||||||
|
if 'index' in option:
|
||||||
|
if key not in ret:
|
||||||
|
ret[key] = copy(option)
|
||||||
|
ret[key]['value'] = {ret[key]['index']: (ret[key]['value'], ret[key]['owner'])}
|
||||||
|
del ret[key]['index']
|
||||||
|
del ret[key]['owner']
|
||||||
|
elif option.get('hidden') is not True:
|
||||||
|
ret[key]['value'][option['index']] = (option['value'], option['owner'])
|
||||||
|
else:
|
||||||
|
ret[key] = option
|
||||||
|
return ret
|
||||||
|
|
||||||
def __getattr__(self,
|
def __getattr__(self,
|
||||||
subfunc: str) -> Any:
|
subfunc: str) -> Any:
|
||||||
if subfunc == 'property':
|
if subfunc == 'property':
|
||||||
|
@ -603,13 +629,29 @@ class Config:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def get_value(self,
|
def get_value(self,
|
||||||
path: str) -> Any:
|
path: str,
|
||||||
|
len_master: int=None) -> Any:
|
||||||
|
if len_master is None:
|
||||||
if 'value' in self.temp.get(path, {}):
|
if 'value' in self.temp.get(path, {}):
|
||||||
value = self.temp[path]['value']
|
value = self.temp[path]['value']
|
||||||
else:
|
else:
|
||||||
value = self.model.get(path, {}).get('value')
|
value = self.model.get(path, {}).get('value')
|
||||||
if value is None and self.get_schema(path).get('isMulti', False):
|
if value is None and self.get_schema(path).get('isMulti', False):
|
||||||
value = []
|
value = []
|
||||||
|
else:
|
||||||
|
value = self.temp.get(path)
|
||||||
|
if value is None:
|
||||||
|
value = self.model.get(path)
|
||||||
|
if value is None:
|
||||||
|
value = [None] * len_master
|
||||||
|
else:
|
||||||
|
val = []
|
||||||
|
for index in range(len_master):
|
||||||
|
if index in value['value']:
|
||||||
|
val.append(value['value'][index][0])
|
||||||
|
else:
|
||||||
|
val.append(None)
|
||||||
|
value = val
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def get_owner(self,
|
def get_owner(self,
|
||||||
|
@ -676,14 +718,9 @@ class Config:
|
||||||
match = True
|
match = True
|
||||||
if match:
|
if match:
|
||||||
if remote:
|
if remote:
|
||||||
ret = self.send_data({'updates': self.updates,
|
self.updates_data(self.send_data({'updates': self.updates,
|
||||||
'model': self.model_ori})
|
'model': self.model_ori}))
|
||||||
self.updates = []
|
|
||||||
self.temp.clear()
|
|
||||||
# FIXME remove old key ?
|
|
||||||
for model in ret['model']:
|
|
||||||
self.model[model['key']] = model
|
|
||||||
self.model_ori = ret['model']
|
|
||||||
else:
|
else:
|
||||||
self.temp.setdefault(path, {})['owner'] = 'tmp'
|
self.temp.setdefault(path, {})['owner'] = 'tmp'
|
||||||
self.temp[path]['value'] = value
|
self.temp[path]['value'] = value
|
||||||
|
@ -691,6 +728,14 @@ class Config:
|
||||||
self.set_not_equal(path, value)
|
self.set_not_equal(path, value)
|
||||||
self.do_copy(path, value)
|
self.do_copy(path, value)
|
||||||
|
|
||||||
|
def updates_data(self, data):
|
||||||
|
self.updates = []
|
||||||
|
self.temp.clear()
|
||||||
|
# FIXME remove old key ?
|
||||||
|
for model in data['model']:
|
||||||
|
self.model[model['key']] = model
|
||||||
|
self.model_ori = data['model']
|
||||||
|
|
||||||
def test_value(self,
|
def test_value(self,
|
||||||
path: str,
|
path: str,
|
||||||
value: Any,
|
value: Any,
|
||||||
|
|
Loading…
Reference in New Issue