Enable hidden field attribute to be set to false
The error has occured when some field in app UI declaration had hidden parameter set to false. Change-Id: I4591f4c72354ab1e8a262573fec5f4e91003b1ff Closes-Bug: #1368120
This commit is contained in:
parent
780c60820f
commit
739b549e65
@ -105,8 +105,11 @@ def _collect_fields(field_specs, form_name, service):
|
||||
elif isinstance(spec, basestring) and helpers.is_localizable(keys):
|
||||
return key, _(spec)
|
||||
else:
|
||||
if key == 'hidden' and spec is True:
|
||||
if key == 'hidden':
|
||||
if spec:
|
||||
return 'widget', forms.HiddenInput
|
||||
else:
|
||||
return 'widget', None
|
||||
elif key == 'regexp_validator':
|
||||
return 'validators', [helpers.prepare_regexp(spec)]
|
||||
else:
|
||||
|
0
muranodashboard/tests/unit/__init__.py
Normal file
0
muranodashboard/tests/unit/__init__.py
Normal file
0
muranodashboard/tests/unit/dynamic_ui/__init__.py
Normal file
0
muranodashboard/tests/unit/dynamic_ui/__init__.py
Normal file
63
muranodashboard/tests/unit/dynamic_ui/test_services.py
Normal file
63
muranodashboard/tests/unit/dynamic_ui/test_services.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright (c) 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import testtools
|
||||
|
||||
from django import forms
|
||||
from muranodashboard.dynamic_ui import services
|
||||
|
||||
|
||||
class TestService(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestService, self).setUp()
|
||||
|
||||
self.application = {'?': {'type': 'test.App'}}
|
||||
|
||||
def test_service_field_hidden_false(self):
|
||||
"""When Service class instantiated with some field having `hidden`
|
||||
attribute set to `false` - the generated form field should have
|
||||
widget different from `HiddenInput`.
|
||||
|
||||
Bug: #1368120
|
||||
"""
|
||||
ui = [{
|
||||
'appConfiguration': {'fields': [{'hidden': False, 'type': 'string',
|
||||
'name': 'title'}]}
|
||||
}]
|
||||
|
||||
service = services.Service(cleaned_data={},
|
||||
application=self.application,
|
||||
forms=ui)
|
||||
form = next(e for e in service.forms
|
||||
if e.__name__ == 'appConfiguration')
|
||||
field = form.base_fields['title']
|
||||
|
||||
self.assertNotIsInstance(field.widget, forms.HiddenInput)
|
||||
|
||||
def test_service_field_hidden_true(self):
|
||||
"""`hidden: true` in UI definition results to HiddenInput in Django
|
||||
form.
|
||||
"""
|
||||
ui = [{
|
||||
'appConfiguration': {'fields': [{'hidden': True, 'type': 'string',
|
||||
'name': 'title'}]}
|
||||
}]
|
||||
|
||||
service = services.Service(cleaned_data={},
|
||||
application=self.application,
|
||||
forms=ui)
|
||||
form = next(e for e in service.forms
|
||||
if e.__name__ == 'appConfiguration')
|
||||
field = form.base_fields['title']
|
||||
|
||||
self.assertIsInstance(field.widget, forms.HiddenInput)
|
Loading…
Reference in New Issue
Block a user