Add support of unicode characters for node labels
Need to work with normalized string to support correct comparison. Decode bytes from terminal as unicode string. Change-Id: Ic217abb7a1c3a39fcb6c741bec14242a2117d2ae Closes-Bug: #1477598
This commit is contained in:
@@ -48,6 +48,7 @@ class NodeList(NodeMixIn, base.BaseListCommand):
|
||||
parser.add_argument(
|
||||
'-l',
|
||||
'--labels',
|
||||
type=utils.str_to_unicode,
|
||||
nargs='+',
|
||||
help='Show only nodes that have specific labels')
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
import json
|
||||
import os
|
||||
import six
|
||||
import subprocess
|
||||
|
||||
import mock
|
||||
@@ -220,3 +221,19 @@ class TestUtils(base.UnitTestCase):
|
||||
|
||||
result = data_utils.get_display_data_multi(fields, test_data)
|
||||
self.assertEqual([[2, 3], [8, 9]], result)
|
||||
|
||||
@mock.patch('sys.getfilesystemencoding', return_value='utf-8')
|
||||
def test_str_to_unicode(self, _):
|
||||
test_data = 'тест'
|
||||
expected_data = test_data if six.PY3 else u'тест'
|
||||
result = utils.str_to_unicode(test_data)
|
||||
self.assertIsInstance(result, six.text_type)
|
||||
self.assertEqual(result, expected_data)
|
||||
|
||||
@mock.patch('sys.getfilesystemencoding', return_value='iso-8859-16')
|
||||
def test_latin_str_to_unicode(self, _):
|
||||
test_data = 'czegoś' if six.PY3 else u'czegoś'.encode('iso-8859-16')
|
||||
expected_data = test_data if six.PY3 else u'czegoś'
|
||||
result = utils.str_to_unicode(test_data)
|
||||
self.assertIsInstance(result, six.text_type)
|
||||
self.assertEqual(result, expected_data)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
from fuelclient.tests.utils import fake_node
|
||||
from fuelclient.tests.v2.unit.cli import test_engine
|
||||
@@ -71,6 +72,8 @@ class TestNodeCommand(test_engine.BaseCLITest):
|
||||
self.m_get_client.assert_called_once_with('node', mock.ANY)
|
||||
self.m_client.get_all.assert_called_once_with(
|
||||
environment_id=env_id, labels=labels)
|
||||
self.assertIsInstance(
|
||||
self.m_client.get_all.call_args[1].get('labels')[0], six.text_type)
|
||||
|
||||
def test_node_show(self):
|
||||
node_id = 42
|
||||
|
||||
@@ -18,7 +18,9 @@ import glob
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import six
|
||||
import subprocess
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
from distutils.version import StrictVersion
|
||||
@@ -149,3 +151,13 @@ def parse_to_list_of_dicts(str_list):
|
||||
'Not valid JSON data: {0}'.format(json_str))
|
||||
dict_list.append(json_str)
|
||||
return dict_list
|
||||
|
||||
|
||||
def str_to_unicode(string):
|
||||
"""Normalize input string from command line to unicode standard.
|
||||
|
||||
:param str string: string to normalize
|
||||
:returns: normalized string
|
||||
|
||||
"""
|
||||
return string if six.PY3 else string.decode(sys.getfilesystemencoding())
|
||||
|
||||
Reference in New Issue
Block a user