list with optiondescription filter
This commit is contained in:
parent
34e7a86130
commit
64699bfba1
|
@ -0,0 +1,53 @@
|
|||
from json import loads
|
||||
from tiramisu_json_api import Config
|
||||
|
||||
|
||||
def test_list_option():
|
||||
filename = 'test/data/boolean1.json'
|
||||
with open(filename, 'r') as fh:
|
||||
json = loads(fh.read())
|
||||
#
|
||||
config = Config(json)
|
||||
opts = []
|
||||
for option in config.option.list():
|
||||
opts.append(option.option.name())
|
||||
assert opts == []
|
||||
#
|
||||
opts = []
|
||||
for option in config.option('options').list():
|
||||
opts.append(option.option.name())
|
||||
assert opts == ['boolean']
|
||||
|
||||
|
||||
def test_list_optiondescription():
|
||||
filename = 'test/data/boolean1.json'
|
||||
with open(filename, 'r') as fh:
|
||||
json = loads(fh.read())
|
||||
#
|
||||
config = Config(json)
|
||||
opts = []
|
||||
for option in config.option.list('optiondescription'):
|
||||
opts.append(option.option.name())
|
||||
assert opts == ['options']
|
||||
#
|
||||
opts = []
|
||||
for option in config.option('options').list('optiondescription'):
|
||||
opts.append(option.option.name())
|
||||
assert opts == []
|
||||
|
||||
|
||||
def test_list_all():
|
||||
filename = 'test/data/boolean1.json'
|
||||
with open(filename, 'r') as fh:
|
||||
json = loads(fh.read())
|
||||
#
|
||||
config = Config(json)
|
||||
opts = []
|
||||
for option in config.option.list('all'):
|
||||
opts.append(option.option.name())
|
||||
assert opts == ['options']
|
||||
#
|
||||
opts = []
|
||||
for option in config.option('options').list('all'):
|
||||
opts.append(option.option.name())
|
||||
assert opts == ['boolean']
|
|
@ -288,18 +288,19 @@ class TiramisuOptionValue(_Value):
|
|||
class _Option:
|
||||
def list(self,
|
||||
type='option'):
|
||||
if type not in ['all', 'option']:
|
||||
raise NotImplementedError()
|
||||
if type not in ['all', 'option', 'optiondescription']:
|
||||
raise Exception('unknown list type {}'.format(type))
|
||||
for path, schema in self.schema['properties'].items():
|
||||
if type == 'all' or schema['type'] not in ['object', 'array'] and self.config.is_hidden(path, None):
|
||||
if not self.config.is_hidden(path, None):
|
||||
if schema['type'] in ['object', 'array']:
|
||||
if type in ['all', 'optiondescription']:
|
||||
yield TiramisuOptionDescription(self.config,
|
||||
schema,
|
||||
self.model,
|
||||
self.form,
|
||||
self.temp,
|
||||
path)
|
||||
else:
|
||||
elif type in ['all', 'option']:
|
||||
yield TiramisuOption(self.config,
|
||||
schema,
|
||||
self.model,
|
||||
|
|
Loading…
Reference in New Issue