Merge "Convert dynamic UI form names to string type"
This commit is contained in:
commit
57f32fa2ec
@ -141,3 +141,14 @@ def int2base(x, base):
|
||||
digits.append('-')
|
||||
digits.reverse()
|
||||
return ''.join(digits)
|
||||
|
||||
|
||||
def to_str(text):
|
||||
if not isinstance(text, str):
|
||||
# unicode in python2
|
||||
if isinstance(text, six.text_type):
|
||||
text = text.encode('utf-8')
|
||||
# bytes in python3
|
||||
elif isinstance(text, six.binary_type):
|
||||
text = text.decode('utf-8')
|
||||
return text
|
||||
|
@ -76,10 +76,12 @@ class Service(object):
|
||||
for key, value in six.iteritems(kwargs):
|
||||
setattr(self, key, value)
|
||||
|
||||
if forms:
|
||||
for counter, data in enumerate(forms):
|
||||
name, field_specs, validators = self.extract_form_data(data)
|
||||
self._add_form(name, field_specs, validators)
|
||||
for form in forms:
|
||||
name, field_specs, validators = self.extract_form_data(form)
|
||||
# NOTE(kzaitsev) should be str (not unicode) under python2
|
||||
# however it also works as str under python3
|
||||
name = helpers.to_str(name)
|
||||
self._add_form(name, field_specs, validators)
|
||||
|
||||
# Add ManageWorkflowForm
|
||||
workflow_form = catalog_forms.WorkflowManagementForm()
|
||||
|
24
muranodashboard/tests/unit/dynamic_ui/test_helpers.py
Normal file
24
muranodashboard/tests/unit/dynamic_ui/test_helpers.py
Normal file
@ -0,0 +1,24 @@
|
||||
# Copyright (c) 2016 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 muranodashboard.dynamic_ui import helpers
|
||||
|
||||
|
||||
class TestHelper(testtools.TestCase):
|
||||
def test_to_str(self):
|
||||
names = ['string', b'ascii', u'ascii',
|
||||
u'\u043d\u0435 \u0430\u0441\u043a\u0438']
|
||||
for name in names:
|
||||
self.assertIsInstance(helpers.to_str(name), str)
|
Loading…
x
Reference in New Issue
Block a user