From 19e28307bf5b565476396b1f97685b6cc483b52b Mon Sep 17 00:00:00 2001 From: Kamil Sambor Date: Tue, 13 May 2014 11:24:34 +0200 Subject: [PATCH] Added support for unicode in client in fuelclient Added support for unicode in env names, Added test for unicode in creating env and getting env info Change-Id: I46ae80695bfdeffc68e10afde27cbb667ad7c318 Closes-Bug: #1318509 --- fuelclient/cli/actions/environment.py | 5 +++-- fuelclient/cli/formatting.py | 20 +++++++++++--------- fuelclient/cli/serializers.py | 2 +- fuelclient/objects/environment.py | 2 +- tests/test_client.py | 13 +++++++++++++ 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/fuelclient/cli/actions/environment.py b/fuelclient/cli/actions/environment.py index f509964..6bc1c7c 100644 --- a/fuelclient/cli/actions/environment.py +++ b/fuelclient/cli/actions/environment.py @@ -88,10 +88,11 @@ class EnvironmentAction(Action): data = env.set(mode=params.mode) else: data = env.get_fresh_data() + self.serializer.print_to_output( data, - "Environment '{name}' with id={id}, mode={mode}" - " and network-mode={net_provider} was created!" + u"Environment '{name}' with id={id}, mode={mode}" + u" and network-mode={net_provider} was created!" .format(**data) ) diff --git a/fuelclient/cli/formatting.py b/fuelclient/cli/formatting.py index 1312a0c..5eaafb5 100644 --- a/fuelclient/cli/formatting.py +++ b/fuelclient/cli/formatting.py @@ -54,18 +54,20 @@ def format_table(data, acceptable_keys=None, column_to_join=None): ) for row in rows: column_widths.update( - (index, max(column_widths[index], len(str(element)))) + (index, max(column_widths[index], len(unicode(element)))) for index, element in enumerate(row) ) - row_template = ' | '.join( - "{{{0}:{1}}}".format(idx, width) + row_template = u' | '.join( + u"{{{0}:{1}}}".format(idx, width) for idx, width in column_widths.iteritems() ) - return '\n'.join( + + return u'\n'.join( (row_template.format(*header), - '-|-'.join(column_widths[column_index] * '-' - for column_index in range(number_of_columns)), - '\n'.join(row_template.format(*map(str, x)) for x in rows)) + u'-|-'.join(column_widths[column_index] * u'-' + for column_index in range(number_of_columns)), + u'\n'.join(row_template.format(*map(unicode, x)) + for x in rows)) ) @@ -232,8 +234,8 @@ def print_health_check(env): ) for test in new_finished_tests: print( - "[{0:2} of {1}] [{status}] '{name}' " - "({taken:.4} s) {message}".format( + u"[{0:2} of {1}] [{status}] '{name}' " + u"({taken:.4} s) {message}".format( test_counter, total_tests_count, **test diff --git a/fuelclient/cli/serializers.py b/fuelclient/cli/serializers.py index e83b8f9..12d772a 100644 --- a/fuelclient/cli/serializers.py +++ b/fuelclient/cli/serializers.py @@ -61,7 +61,7 @@ class Serializer(object): if self.format_flags: self.print_formatted(formatted_data) else: - print_method(arg) + print_method(arg.encode('utf-8')) def prepare_path(self, path): return "{0}.{1}".format( diff --git a/fuelclient/objects/environment.py b/fuelclient/objects/environment.py index f500fc9..13f59b8 100644 --- a/fuelclient/objects/environment.py +++ b/fuelclient/objects/environment.py @@ -247,7 +247,7 @@ class Environment(BaseObject): (serializer or self.serializer).write_to_file( engine_file_path, facts["engine"]) facts = facts["nodes"] - name_template = "{name}" + name_template = u"{name}" else: name_template = "{role}_{uid}" for _fact in facts: diff --git a/tests/test_client.py b/tests/test_client.py index 89ca51b..ca3d6ad 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2013-2014 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -127,6 +129,17 @@ class TestHandlers(BaseTestCase): ) +class TestCharset(BaseTestCase): + + def test_charset_problem(self): + self.load_data_to_nailgun_server() + self.run_cli_commands(( + "env create --name=привет --release=1", + "--env-id=1 node set --node 1 --role=controller", + "env" + )) + + class TestFiles(BaseTestCase): def setUp(self):