From 4057ff25694161bcff5032768e0872dc827fe851 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 19 Aug 2015 16:28:50 -0700 Subject: [PATCH] py3: Replace unicode with six.text_type Initial patch generated by: sixer.py unicode horizon openstack_dashboard/ tools/ Partial-Implements: blueprint porting-python3 Change-Id: I8bdec74fbe32a6ff0e65f2f0810a0c698a3b9637 --- horizon/tables/formset.py | 2 +- horizon/tabs/base.py | 2 +- horizon/test/tests/base.py | 4 ++- horizon/test/tests/tables.py | 34 +++++++++++------- horizon/test/tests/workflows.py | 10 +++--- horizon/workflows/views.py | 2 +- openstack_dashboard/api/keystone.py | 2 +- .../cluster_templates/tests.py | 3 +- .../data_processing/data_plugins/tests.py | 3 +- .../data_processing/data_sources/tests.py | 3 +- .../data_processing/job_binaries/tests.py | 9 ++--- .../data_processing/job_executions/tests.py | 3 +- .../content/data_processing/jobs/tests.py | 3 +- .../nodegroup_templates/tests.py | 3 +- .../data_processing/utils/workflow_helpers.py | 7 ++-- .../trove/content/database_backups/tests.py | 7 ++-- .../contrib/trove/content/databases/tests.py | 35 ++++++++++--------- .../contrib/trove/content/databases/views.py | 5 ++- .../dashboards/admin/metering/tables.py | 2 +- .../dashboards/admin/metering/tests.py | 7 ++-- .../access_and_security/floating_ips/tests.py | 3 +- .../access_and_security/keypairs/tests.py | 3 +- .../security_groups/forms.py | 5 ++- .../security_groups/tables.py | 5 +-- .../project/access_and_security/tests.py | 3 +- .../dashboards/project/containers/tests.py | 3 +- .../dashboards/project/images/tests.py | 3 +- .../dashboards/project/instances/tests.py | 12 ++++--- .../dashboards/project/networks/tests.py | 8 +++-- .../dashboards/project/routers/tests.py | 3 +- .../dashboards/project/stacks/forms.py | 2 +- .../dashboards/project/stacks/tests.py | 3 +- .../project/volumes/volumes/tests.py | 5 +-- .../test/api_tests/keystone_tests.py | 5 +-- openstack_dashboard/test/helpers.py | 3 +- .../test/test_data/exceptions.py | 3 +- 36 files changed, 131 insertions(+), 84 deletions(-) diff --git a/horizon/tables/formset.py b/horizon/tables/formset.py index e35d88e75..3377f4268 100644 --- a/horizon/tables/formset.py +++ b/horizon/tables/formset.py @@ -40,7 +40,7 @@ class FormsetCell(horizon_tables.Cell): self.attrs['class'] = (self.attrs.get('class', '') + ' error form-group') self.attrs['title'] = ' '.join( - unicode(error) for error in self.field.errors) + six.text_type(error) for error in self.field.errors) class FormsetRow(horizon_tables.Row): diff --git a/horizon/tabs/base.py b/horizon/tabs/base.py index 2dcde25b6..1ed9dfa36 100644 --- a/horizon/tabs/base.py +++ b/horizon/tabs/base.py @@ -263,7 +263,7 @@ class Tab(html.HTMLElement): # Priority: constructor, class-defined, fallback if not self.name: raise ValueError("%s must have a name." % self.__class__.__name__) - self.name = unicode(self.name) # Force unicode. + self.name = six.text_type(self.name) # Force unicode. if not self.slug: raise ValueError("%s must have a slug." % self.__class__.__name__) self.tab_group = tab_group diff --git a/horizon/test/tests/base.py b/horizon/test/tests/base.py index 4d3abf52f..478b1f84d 100644 --- a/horizon/test/tests/base.py +++ b/horizon/test/tests/base.py @@ -24,6 +24,8 @@ from django.core import urlresolvers from django.utils.importlib import import_module # noqa from six import moves +import six + import horizon from horizon import base from horizon import conf @@ -163,7 +165,7 @@ class HorizonTests(BaseHorizonTests): horizon.get_dashboard(MyDash) def test_site(self): - self.assertEqual("Horizon", unicode(base.Horizon)) + self.assertEqual("Horizon", six.text_type(base.Horizon)) self.assertEqual("", repr(base.Horizon)) dash = base.Horizon.get_dashboard('cats') self.assertEqual(dash, base.Horizon.get_default_dashboard()) diff --git a/horizon/test/tests/tables.py b/horizon/test/tests/tables.py index 8275478a9..0953f568f 100644 --- a/horizon/test/tests/tables.py +++ b/horizon/test/tests/tables.py @@ -20,6 +20,7 @@ from django import shortcuts from django.template import defaultfilters from mox3.mox import IsA # noqa +import six from horizon import tables from horizon.tables import formset as table_formset @@ -331,7 +332,7 @@ class DataTableTests(test.TestCase): self.assertTrue(self.table._meta.actions_column) self.assertTrue(self.table._meta.multi_select) # Test for verbose_name - self.assertEqual(u"My Table", unicode(self.table)) + self.assertEqual(u"My Table", six.text_type(self.table)) # Column ordering and exclusion. # This should include auto-columns for multi_select and actions, # but should not contain the excluded column. @@ -497,8 +498,8 @@ class DataTableTests(test.TestCase): self.assertEqual('1', row.cells['id'].data) # Standard attr access self.assertEqual('custom object_1', row.cells['name'].data) # Callable # name and verbose_name - self.assertEqual("Id", unicode(id_col)) - self.assertEqual("Verbose Name", unicode(name_col)) + self.assertEqual("Id", six.text_type(id_col)) + self.assertEqual("Verbose Name", six.text_type(name_col)) # sortable self.assertEqual(False, id_col.sortable) self.assertNotIn("sortable", id_col.get_final_attrs().get('class', "")) @@ -862,13 +863,15 @@ class DataTableTests(test.TestCase): req = self.factory.get('/my_url/') self.table = MyTable(req, TEST_DATA_3) toggle_action = self.table.get_row_actions(TEST_DATA_3[0])[2] - self.assertEqual("Batch Item", unicode(toggle_action.verbose_name)) + self.assertEqual("Batch Item", + six.text_type(toggle_action.verbose_name)) # Batch action with custom help text req = self.factory.get('/my_url/') self.table = MyTable(req, TEST_DATA_3) toggle_action = self.table.get_row_actions(TEST_DATA_3[0])[4] - self.assertEqual("BatchHelp Item", unicode(toggle_action.verbose_name)) + self.assertEqual("BatchHelp Item", + six.text_type(toggle_action.verbose_name)) # Single object toggle action # GET page - 'up' to 'down' @@ -876,7 +879,8 @@ class DataTableTests(test.TestCase): self.table = MyTable(req, TEST_DATA_3) self.assertEqual(5, len(self.table.get_row_actions(TEST_DATA_3[0]))) toggle_action = self.table.get_row_actions(TEST_DATA_3[0])[3] - self.assertEqual("Down Item", unicode(toggle_action.verbose_name)) + self.assertEqual("Down Item", + six.text_type(toggle_action.verbose_name)) # Toggle from status 'up' to 'down' # POST page @@ -897,7 +901,7 @@ class DataTableTests(test.TestCase): self.table = MyTable(req, TEST_DATA_2) self.assertEqual(4, len(self.table.get_row_actions(TEST_DATA_2[0]))) toggle_action = self.table.get_row_actions(TEST_DATA_2[0])[2] - self.assertEqual("Up Item", unicode(toggle_action.verbose_name)) + self.assertEqual("Up Item", six.text_type(toggle_action.verbose_name)) # POST page action_string = "my_table__toggle__2" @@ -1013,12 +1017,16 @@ class DataTableTests(test.TestCase): # Verbose names table_actions = self.table.get_table_actions() - self.assertEqual("Filter", unicode(table_actions[0].verbose_name)) - self.assertEqual("Delete Me", unicode(table_actions[1].verbose_name)) + self.assertEqual("Filter", + six.text_type(table_actions[0].verbose_name)) + self.assertEqual("Delete Me", + six.text_type(table_actions[1].verbose_name)) row_actions = self.table.get_row_actions(TEST_DATA[0]) - self.assertEqual("Delete Me", unicode(row_actions[0].verbose_name)) - self.assertEqual("Log In", unicode(row_actions[1].verbose_name)) + self.assertEqual("Delete Me", + six.text_type(row_actions[0].verbose_name)) + self.assertEqual("Log In", + six.text_type(row_actions[1].verbose_name)) def test_server_filtering(self): filter_value_param = "my_table__filter__q" @@ -1266,8 +1274,8 @@ class DataTableTests(test.TestCase): self.assertEqual('1', row.cells['id'].data) # Standard attr access self.assertEqual('custom object_1', row.cells['name'].data) # Callable # name and verbose_name - self.assertEqual("Id", unicode(id_col)) - self.assertEqual("Verbose Name", unicode(name_col)) + self.assertEqual("Id", six.text_type(id_col)) + self.assertEqual("Verbose Name", six.text_type(name_col)) self.assertIn("sortable", name_col.get_final_attrs().get('class', "")) # hidden self.assertEqual(True, id_col.hidden) diff --git a/horizon/test/tests/workflows.py b/horizon/test/tests/workflows.py index a89d872d8..fec7785e5 100644 --- a/horizon/test/tests/workflows.py +++ b/horizon/test/tests/workflows.py @@ -15,6 +15,8 @@ from django import forms from django import http +import six + from horizon import exceptions from horizon.test import helpers as test from horizon import workflows @@ -267,10 +269,10 @@ class WorkflowsTests(test.TestCase): req = self.factory.get("/foo") flow = TestWorkflow(req) output = http.HttpResponse(flow.render()) - self.assertContains(output, unicode(flow.name)) - self.assertContains(output, unicode(TestActionOne.name)) - self.assertContains(output, unicode(TestActionTwo.name)) - self.assertContains(output, unicode(TestActionThree.name)) + self.assertContains(output, six.text_type(flow.name)) + self.assertContains(output, six.text_type(TestActionOne.name)) + self.assertContains(output, six.text_type(TestActionTwo.name)) + self.assertContains(output, six.text_type(TestActionThree.name)) def test_has_permissions(self): self.assertQuerysetEqual(TestWorkflow._cls_registry, []) diff --git a/horizon/workflows/views.py b/horizon/workflows/views.py index f708f5aac..dbcc7c6a6 100644 --- a/horizon/workflows/views.py +++ b/horizon/workflows/views.py @@ -154,7 +154,7 @@ class WorkflowView(hz_views.ModalBackdropMixin, generic.TemplateView): for step in workflow.steps[start:end + 1]: if not step.action.is_valid(): errors[step.slug] = dict( - (field, [unicode(error) for error in errors]) + (field, [six.text_type(error) for error in errors]) for (field, errors) in six.iteritems(step.action.errors)) return { 'has_errors': bool(errors), diff --git a/openstack_dashboard/api/keystone.py b/openstack_dashboard/api/keystone.py index d4c75db54..f1acc285f 100644 --- a/openstack_dashboard/api/keystone.py +++ b/openstack_dashboard/api/keystone.py @@ -102,7 +102,7 @@ class Service(base.APIDictWrapper): return self.type def __repr__(self): - return "" % unicode(self) + return "" % six.text_type(self) def _get_endpoint_url(request, endpoint_type, catalog=None): diff --git a/openstack_dashboard/contrib/sahara/content/data_processing/cluster_templates/tests.py b/openstack_dashboard/contrib/sahara/content/data_processing/cluster_templates/tests.py index b24fb9369..1fcc18c11 100644 --- a/openstack_dashboard/contrib/sahara/content/data_processing/cluster_templates/tests.py +++ b/openstack_dashboard/contrib/sahara/content/data_processing/cluster_templates/tests.py @@ -18,6 +18,7 @@ from django.core.urlresolvers import reverse from django import http from mox3.mox import IsA # noqa +import six from openstack_dashboard import api as dash_api from openstack_dashboard.contrib.sahara import api @@ -50,7 +51,7 @@ class DataProcessingClusterTemplateTests(test.TestCase): dash_api.nova.flavor_get(IsA(http.HttpRequest), flavor.id) \ .MultipleTimes().AndReturn(flavor) api.sahara.cluster_template_get(IsA(http.HttpRequest), - IsA(unicode)) \ + IsA(six.text_type)) \ .MultipleTimes().AndReturn(ct) self.mox.ReplayAll() res = self.client.get(DETAILS_URL) diff --git a/openstack_dashboard/contrib/sahara/content/data_processing/data_plugins/tests.py b/openstack_dashboard/contrib/sahara/content/data_processing/data_plugins/tests.py index fca836abb..4b10f8430 100644 --- a/openstack_dashboard/contrib/sahara/content/data_processing/data_plugins/tests.py +++ b/openstack_dashboard/contrib/sahara/content/data_processing/data_plugins/tests.py @@ -14,6 +14,7 @@ from django.core.urlresolvers import reverse from django import http from mox3.mox import IsA # noqa +import six from openstack_dashboard.contrib.sahara import api from openstack_dashboard.test import helpers as test @@ -39,7 +40,7 @@ class DataProcessingPluginsTests(test.TestCase): @test.create_stubs({api.sahara: ('plugin_get',)}) def test_details(self): - api.sahara.plugin_get(IsA(http.HttpRequest), IsA(unicode)) \ + api.sahara.plugin_get(IsA(http.HttpRequest), IsA(six.text_type)) \ .AndReturn(self.plugins.list()[0]) self.mox.ReplayAll() res = self.client.get(DETAILS_URL) diff --git a/openstack_dashboard/contrib/sahara/content/data_processing/data_sources/tests.py b/openstack_dashboard/contrib/sahara/content/data_processing/data_sources/tests.py index 023e18fbe..ec1419fe8 100644 --- a/openstack_dashboard/contrib/sahara/content/data_processing/data_sources/tests.py +++ b/openstack_dashboard/contrib/sahara/content/data_processing/data_sources/tests.py @@ -14,6 +14,7 @@ from django.core.urlresolvers import reverse from django import http from mox3.mox import IsA # noqa +import six from openstack_dashboard.contrib.sahara import api from openstack_dashboard.test import helpers as test @@ -40,7 +41,7 @@ class DataProcessingDataSourceTests(test.TestCase): @test.create_stubs({api.sahara: ('data_source_get',)}) def test_details(self): - api.sahara.data_source_get(IsA(http.HttpRequest), IsA(unicode)) \ + api.sahara.data_source_get(IsA(http.HttpRequest), IsA(six.text_type)) \ .MultipleTimes().AndReturn(self.data_sources.first()) self.mox.ReplayAll() res = self.client.get(DETAILS_URL) diff --git a/openstack_dashboard/contrib/sahara/content/data_processing/job_binaries/tests.py b/openstack_dashboard/contrib/sahara/content/data_processing/job_binaries/tests.py index e559472fe..886db95ae 100644 --- a/openstack_dashboard/contrib/sahara/content/data_processing/job_binaries/tests.py +++ b/openstack_dashboard/contrib/sahara/content/data_processing/job_binaries/tests.py @@ -14,6 +14,7 @@ from django.core.urlresolvers import reverse from django import http from mox3.mox import IsA # noqa +import six from openstack_dashboard.contrib.sahara import api from openstack_dashboard.test import helpers as test @@ -39,7 +40,7 @@ class DataProcessingJobBinaryTests(test.TestCase): @test.create_stubs({api.sahara: ('job_binary_get',)}) def test_details(self): - api.sahara.job_binary_get(IsA(http.HttpRequest), IsA(unicode)) \ + api.sahara.job_binary_get(IsA(http.HttpRequest), IsA(six.text_type)) \ .MultipleTimes().AndReturn(self.job_binaries.first()) self.mox.ReplayAll() res = self.client.get(DETAILS_URL) @@ -54,7 +55,7 @@ class DataProcessingJobBinaryTests(test.TestCase): def test_delete(self): jb_list = (api.sahara.job_binary_list(IsA(http.HttpRequest)) .AndReturn(self.job_binaries.list())) - api.sahara.job_binary_get(IsA(http.HttpRequest), IsA(unicode)) \ + api.sahara.job_binary_get(IsA(http.HttpRequest), IsA(six.text_type)) \ .AndReturn(self.job_binaries.list()[0]) api.sahara.job_binary_delete(IsA(http.HttpRequest), jb_list[0].id) int_id = jb_list[0].url.split("//")[1] @@ -67,7 +68,7 @@ class DataProcessingJobBinaryTests(test.TestCase): @test.create_stubs({api.sahara: ('job_binary_get', 'job_binary_get_file')}) def test_download(self): - jb = api.sahara.job_binary_get(IsA(http.HttpRequest), IsA(unicode)) \ + jb = api.sahara.job_binary_get(IsA(http.HttpRequest), IsA(six.text_type)) \ .AndReturn(self.job_binaries.list()[0]) api.sahara.job_binary_get_file(IsA(http.HttpRequest), jb.id) \ .AndReturn("TEST FILE CONTENT") @@ -82,7 +83,7 @@ class DataProcessingJobBinaryTests(test.TestCase): @test.create_stubs({api.sahara: ('job_binary_get', 'job_binary_get_file')}) def test_download_with_spaces(self): - jb = api.sahara.job_binary_get(IsA(http.HttpRequest), IsA(unicode)) \ + jb = api.sahara.job_binary_get(IsA(http.HttpRequest), IsA(six.text_type)) \ .AndReturn(self.job_binaries.list()[1]) api.sahara.job_binary_get_file(IsA(http.HttpRequest), jb.id) \ .AndReturn("MORE TEST FILE CONTENT") diff --git a/openstack_dashboard/contrib/sahara/content/data_processing/job_executions/tests.py b/openstack_dashboard/contrib/sahara/content/data_processing/job_executions/tests.py index 37bce578b..af4f9c8e5 100644 --- a/openstack_dashboard/contrib/sahara/content/data_processing/job_executions/tests.py +++ b/openstack_dashboard/contrib/sahara/content/data_processing/job_executions/tests.py @@ -14,6 +14,7 @@ from django.core.urlresolvers import reverse from django import http from mox3.mox import IsA # noqa +import six from openstack_dashboard.contrib.sahara import api from openstack_dashboard.test import helpers as test @@ -43,7 +44,7 @@ class DataProcessingJobExecutionTests(test.TestCase): @test.create_stubs({api.sahara: ('job_execution_get',)}) def test_details(self): - api.sahara.job_execution_get(IsA(http.HttpRequest), IsA(unicode)) \ + api.sahara.job_execution_get(IsA(http.HttpRequest), IsA(six.text_type)) \ .MultipleTimes().AndReturn(self.job_executions.first()) self.mox.ReplayAll() res = self.client.get(DETAILS_URL) diff --git a/openstack_dashboard/contrib/sahara/content/data_processing/jobs/tests.py b/openstack_dashboard/contrib/sahara/content/data_processing/jobs/tests.py index c08e16b77..0873640ef 100644 --- a/openstack_dashboard/contrib/sahara/content/data_processing/jobs/tests.py +++ b/openstack_dashboard/contrib/sahara/content/data_processing/jobs/tests.py @@ -14,6 +14,7 @@ from django.core.urlresolvers import reverse from django import http from mox3.mox import IsA # noqa +import six from openstack_dashboard.contrib.sahara import api from openstack_dashboard.test import helpers as test @@ -38,7 +39,7 @@ class DataProcessingJobTests(test.TestCase): @test.create_stubs({api.sahara: ('job_get',)}) def test_details(self): - api.sahara.job_get(IsA(http.HttpRequest), IsA(unicode)) \ + api.sahara.job_get(IsA(http.HttpRequest), IsA(six.text_type)) \ .MultipleTimes().AndReturn(self.jobs.first()) self.mox.ReplayAll() res = self.client.get(DETAILS_URL) diff --git a/openstack_dashboard/contrib/sahara/content/data_processing/nodegroup_templates/tests.py b/openstack_dashboard/contrib/sahara/content/data_processing/nodegroup_templates/tests.py index 56477d327..92bf7fdef 100644 --- a/openstack_dashboard/contrib/sahara/content/data_processing/nodegroup_templates/tests.py +++ b/openstack_dashboard/contrib/sahara/content/data_processing/nodegroup_templates/tests.py @@ -15,6 +15,7 @@ from django import http from mox3.mox import IgnoreArg # noqa from mox3.mox import IsA # noqa +import six from openstack_dashboard import api as dash_api from openstack_dashboard.contrib.sahara import api @@ -55,7 +56,7 @@ class DataProcessingNodeGroupTests(test.TestCase): dash_api.nova.flavor_get(IsA(http.HttpRequest), flavor.id) \ .AndReturn(flavor) api.sahara.nodegroup_template_get(IsA(http.HttpRequest), - IsA(unicode)) \ + IsA(six.text_type)) \ .MultipleTimes().AndReturn(ngt) self.mox.ReplayAll() res = self.client.get(DETAILS_URL) diff --git a/openstack_dashboard/contrib/sahara/content/data_processing/utils/workflow_helpers.py b/openstack_dashboard/contrib/sahara/content/data_processing/utils/workflow_helpers.py index fc47be277..d1d8698f0 100644 --- a/openstack_dashboard/contrib/sahara/content/data_processing/utils/workflow_helpers.py +++ b/openstack_dashboard/contrib/sahara/content/data_processing/utils/workflow_helpers.py @@ -14,6 +14,8 @@ import logging from django.utils.translation import ugettext_lazy as _ +import six + from horizon import forms from horizon import workflows @@ -133,8 +135,9 @@ def parse_configs_from_context(context, defaults): config = key_split[2] if service not in configs_dict: configs_dict[service] = dict() - if (val is None or - unicode(defaults[service][config]) == unicode(val)): + if val is None: + continue + if six.text_type(defaults[service][config]) == six.text_type(val): continue configs_dict[service][config] = val return configs_dict diff --git a/openstack_dashboard/contrib/trove/content/database_backups/tests.py b/openstack_dashboard/contrib/trove/content/database_backups/tests.py index 6b72e0ac9..c1aac5ac8 100644 --- a/openstack_dashboard/contrib/trove/content/database_backups/tests.py +++ b/openstack_dashboard/contrib/trove/content/database_backups/tests.py @@ -15,6 +15,7 @@ from django.core.urlresolvers import reverse from django import http from mox3.mox import IsA # noqa +import six from openstack_dashboard.contrib.trove import api from openstack_dashboard.test import helpers as test @@ -139,7 +140,7 @@ class DatabasesBackupsTests(test.TestCase): @test.create_stubs({api.trove: ('backup_get', 'instance_get')}) def test_detail_backup(self): api.trove.backup_get(IsA(http.HttpRequest), - IsA(unicode))\ + IsA(six.text_type))\ .AndReturn(self.database_backups.first()) api.trove.instance_get(IsA(http.HttpRequest), @@ -155,7 +156,7 @@ class DatabasesBackupsTests(test.TestCase): @test.create_stubs({api.trove: ('backup_get',)}) def test_detail_backup_notfound(self): api.trove.backup_get(IsA(http.HttpRequest), - IsA(unicode))\ + IsA(six.text_type))\ .AndRaise(self.exceptions.trove) self.mox.ReplayAll() @@ -168,7 +169,7 @@ class DatabasesBackupsTests(test.TestCase): incr_backup = self.database_backups.list()[2] parent_backup = self.database_backups.list()[1] - api.trove.backup_get(IsA(http.HttpRequest), IsA(unicode))\ + api.trove.backup_get(IsA(http.HttpRequest), IsA(six.text_type))\ .AndReturn(incr_backup) api.trove.backup_get(IsA(http.HttpRequest), incr_backup.parent_id) \ .AndReturn(parent_backup) diff --git a/openstack_dashboard/contrib/trove/content/databases/tests.py b/openstack_dashboard/contrib/trove/content/databases/tests.py index 0816d13ab..e242fea79 100644 --- a/openstack_dashboard/contrib/trove/content/databases/tests.py +++ b/openstack_dashboard/contrib/trove/content/databases/tests.py @@ -21,6 +21,7 @@ from django import http from django.utils import unittest from mox3.mox import IsA # noqa +import six from horizon import exceptions from openstack_dashboard import api as dash_api @@ -222,12 +223,12 @@ class DatabaseTests(test.TestCase): # Actual create database call api.trove.instance_create( IsA(http.HttpRequest), - IsA(unicode), + IsA(six.text_type), IsA(int), - IsA(unicode), + IsA(six.text_type), databases=None, - datastore=IsA(unicode), - datastore_version=IsA(unicode), + datastore=IsA(six.text_type), + datastore_version=IsA(six.text_type), restore_point=None, replica_of=None, users=None, @@ -283,12 +284,12 @@ class DatabaseTests(test.TestCase): # Actual create database call api.trove.instance_create( IsA(http.HttpRequest), - IsA(unicode), + IsA(six.text_type), IsA(int), - IsA(unicode), + IsA(six.text_type), databases=None, - datastore=IsA(unicode), - datastore_version=IsA(unicode), + datastore=IsA(six.text_type), + datastore_version=IsA(six.text_type), restore_point=None, replica_of=None, users=None, @@ -309,7 +310,7 @@ class DatabaseTests(test.TestCase): @test.create_stubs( {api.trove: ('instance_get', 'flavor_get',)}) def _test_details(self, database, with_designate=False): - api.trove.instance_get(IsA(http.HttpRequest), IsA(unicode))\ + api.trove.instance_get(IsA(http.HttpRequest), IsA(six.text_type))\ .AndReturn(database) api.trove.flavor_get(IsA(http.HttpRequest), IsA(str))\ .AndReturn(self.flavors.first()) @@ -343,7 +344,7 @@ class DatabaseTests(test.TestCase): user_id = user.name # views.py: DetailView.get_data - api.trove.instance_get(IsA(http.HttpRequest), IsA(unicode))\ + api.trove.instance_get(IsA(http.HttpRequest), IsA(six.text_type))\ .AndReturn(database) api.trove.flavor_get(IsA(http.HttpRequest), IsA(str))\ .AndReturn(self.flavors.first()) @@ -378,7 +379,7 @@ class DatabaseTests(test.TestCase): database_size = database.volume.get('size') # views.py: DetailView.get_data - api.trove.instance_get(IsA(http.HttpRequest), IsA(unicode))\ + api.trove.instance_get(IsA(http.HttpRequest), IsA(six.text_type))\ .AndReturn(database) # forms.py: ResizeVolumeForm.handle @@ -405,7 +406,7 @@ class DatabaseTests(test.TestCase): database_size = database.volume.get('size') # views.py: DetailView.get_data - api.trove.instance_get(IsA(http.HttpRequest), IsA(unicode))\ + api.trove.instance_get(IsA(http.HttpRequest), IsA(six.text_type))\ .AndReturn(database) self.mox.ReplayAll() @@ -511,18 +512,18 @@ class DatabaseTests(test.TestCase): nics = [{"net-id": self.networks.first().id, "v4-fixed-ip": ''}] - api.trove.instance_get(IsA(http.HttpRequest), IsA(unicode))\ + api.trove.instance_get(IsA(http.HttpRequest), IsA(six.text_type))\ .AndReturn(self.databases.first()) # Actual create database call api.trove.instance_create( IsA(http.HttpRequest), - IsA(unicode), + IsA(six.text_type), IsA(int), - IsA(unicode), + IsA(six.text_type), databases=None, - datastore=IsA(unicode), - datastore_version=IsA(unicode), + datastore=IsA(six.text_type), + datastore_version=IsA(six.text_type), restore_point=None, replica_of=self.databases.first().id, users=None, diff --git a/openstack_dashboard/contrib/trove/content/databases/views.py b/openstack_dashboard/contrib/trove/content/databases/views.py index 1b9e4bdf3..69dabe80f 100644 --- a/openstack_dashboard/contrib/trove/content/databases/views.py +++ b/openstack_dashboard/contrib/trove/content/databases/views.py @@ -22,6 +22,8 @@ from django.core.urlresolvers import reverse_lazy from django.utils.datastructures import SortedDict from django.utils.translation import ugettext_lazy as _ +import six + from horizon import exceptions from horizon import forms as horizon_forms from horizon import tables as horizon_tables @@ -58,7 +60,8 @@ class IndexView(horizon_tables.DataTableView): flavors = [] msg = _('Unable to retrieve database size information.') exceptions.handle(self.request, msg) - return SortedDict((unicode(flavor.id), flavor) for flavor in flavors) + return SortedDict((six.text_type(flavor.id), flavor) + for flavor in flavors) def _extra_data(self, instance): flavor = self.get_flavors().get(instance.flavor["id"]) diff --git a/openstack_dashboard/dashboards/admin/metering/tables.py b/openstack_dashboard/dashboards/admin/metering/tables.py index 86cf58157..7217bdfb3 100644 --- a/openstack_dashboard/dashboards/admin/metering/tables.py +++ b/openstack_dashboard/dashboards/admin/metering/tables.py @@ -81,7 +81,7 @@ class UsageTable(tables.DataTable): def name(self): # slugify was introduced in Django 1.5 if hasattr(text, 'slugify'): - return text.slugify(unicode(self.title)) + return text.slugify(six.text_type(self.title)) else: return self.title diff --git a/openstack_dashboard/dashboards/admin/metering/tests.py b/openstack_dashboard/dashboards/admin/metering/tests.py index 22197effc..23a64f54a 100644 --- a/openstack_dashboard/dashboards/admin/metering/tests.py +++ b/openstack_dashboard/dashboards/admin/metering/tests.py @@ -15,6 +15,7 @@ from django.core.urlresolvers import reverse from django import http from mox3.mox import IsA # noqa +import six from openstack_dashboard import api from openstack_dashboard.test import helpers as test @@ -82,7 +83,7 @@ class MeteringLineChartTabTests(test.BaseAdminViewTests): ), }) def test_stats_for_line_chart(self): api.ceilometer.sample_list(IsA(http.HttpRequest), - IsA(unicode), + IsA(six.text_type), limit=IsA(int)).AndReturn([]) api.ceilometer.statistic_list(IsA(http.HttpRequest), 'memory', @@ -115,7 +116,7 @@ class MeteringLineChartTabTests(test.BaseAdminViewTests): ), }) def test_stats_for_line_chart_attr_max(self): api.ceilometer.sample_list(IsA(http.HttpRequest), - IsA(unicode), + IsA(six.text_type), limit=IsA(int)).AndReturn([]) api.ceilometer.statistic_list(IsA(http.HttpRequest), 'memory', period=IsA(int), @@ -149,7 +150,7 @@ class MeteringLineChartTabTests(test.BaseAdminViewTests): ), }) def test_stats_for_line_chart_no_group(self): api.ceilometer.sample_list(IsA(http.HttpRequest), - IsA(unicode), + IsA(six.text_type), limit=IsA(int)).AndReturn([]) api.ceilometer.resource_list(IsA(http.HttpRequest), query=None, ceilometer_usage_object=None)\ diff --git a/openstack_dashboard/dashboards/project/access_and_security/floating_ips/tests.py b/openstack_dashboard/dashboards/project/access_and_security/floating_ips/tests.py index 8bec2bd5c..35d5f1130 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/floating_ips/tests.py +++ b/openstack_dashboard/dashboards/project/access_and_security/floating_ips/tests.py @@ -22,6 +22,7 @@ from django import http from django.utils.http import urlencode from mox3.mox import IsA # noqa +import six from openstack_dashboard import api from openstack_dashboard.dashboards.project.access_and_security \ @@ -269,7 +270,7 @@ class FloatingIpViewTests(test.TestCase): url = allocate_link.get_link_url() classes = (list(allocate_link.get_default_classes()) + list(allocate_link.classes)) - link_name = "%s (%s)" % (unicode(allocate_link.verbose_name), + link_name = "%s (%s)" % (six.text_type(allocate_link.verbose_name), "Quota exceeded") expected_string = ("" diff --git a/openstack_dashboard/dashboards/project/access_and_security/keypairs/tests.py b/openstack_dashboard/dashboards/project/access_and_security/keypairs/tests.py index fa9bd7481..a15a33f85 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/keypairs/tests.py +++ b/openstack_dashboard/dashboards/project/access_and_security/keypairs/tests.py @@ -20,6 +20,7 @@ from django.core.urlresolvers import reverse from django import http from mox3.mox import IsA # noqa +import six from openstack_dashboard import api from openstack_dashboard.dashboards.project.access_and_security.\ @@ -180,7 +181,7 @@ class KeyPairViewTests(test.TestCase): url = reverse('horizon:project:access_and_security:keypairs:import') res = self.client.post(url, formData, follow=True) self.assertEqual(res.redirect_chain, []) - msg = unicode(KEYPAIR_ERROR_MESSAGES['invalid']) + msg = six.text_type(KEYPAIR_ERROR_MESSAGES['invalid']) self.assertFormErrors(res, count=1, message=msg) @test.create_stubs({api.nova: ("keypair_create",)}) diff --git a/openstack_dashboard/dashboards/project/access_and_security/security_groups/forms.py b/openstack_dashboard/dashboards/project/access_and_security/security_groups/forms.py index 0e39e33d9..722493680 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/security_groups/forms.py +++ b/openstack_dashboard/dashboards/project/access_and_security/security_groups/forms.py @@ -23,6 +23,8 @@ from django.core.urlresolvers import reverse from django.forms import ValidationError # noqa from django.utils.translation import ugettext_lazy as _ +import six + from horizon import exceptions from horizon import forms from horizon import messages @@ -399,7 +401,8 @@ class AddRule(forms.SelfHandlingForm): data['cidr'], data['security_group']) messages.success(request, - _('Successfully added rule: %s') % unicode(rule)) + _('Successfully added rule: %s') + % six.text_type(rule)) return rule except Exception: redirect = reverse("horizon:project:access_and_security:" diff --git a/openstack_dashboard/dashboards/project/access_and_security/security_groups/tables.py b/openstack_dashboard/dashboards/project/access_and_security/security_groups/tables.py index d7146a8b4..14136eac9 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/security_groups/tables.py +++ b/openstack_dashboard/dashboards/project/access_and_security/security_groups/tables.py @@ -18,6 +18,7 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import tables +import six from openstack_dashboard import api from openstack_dashboard import policy @@ -243,7 +244,7 @@ def filter_direction(direction): def filter_protocol(protocol): if protocol is None: return _('Any') - return unicode.upper(protocol) + return six.text_type.upper(protocol) def check_rule_template(port, ip_proto): @@ -280,7 +281,7 @@ class RulesTable(tables.DataTable): return filters.get_int_or_uuid(obj_id) def get_object_display(self, rule): - return unicode(rule) + return six.text_type(rule) class Meta(object): name = "rules" diff --git a/openstack_dashboard/dashboards/project/access_and_security/tests.py b/openstack_dashboard/dashboards/project/access_and_security/tests.py index 6d4d3455c..f6f374a76 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/tests.py +++ b/openstack_dashboard/dashboards/project/access_and_security/tests.py @@ -21,6 +21,7 @@ from copy import deepcopy # noqa from django.core.urlresolvers import reverse from django import http from mox3.mox import IsA # noqa +import six from horizon.workflows import views from openstack_dashboard import api @@ -220,7 +221,7 @@ class SecurityGroupTabTests(test.TestCase): url = create_link.get_link_url() classes = (list(create_link.get_default_classes()) + list(create_link.classes)) - link_name = "%s (%s)" % (unicode(create_link.verbose_name), + link_name = "%s (%s)" % (six.text_type(create_link.verbose_name), "Quota exceeded") expected_string = "" \ diff --git a/openstack_dashboard/dashboards/project/containers/tests.py b/openstack_dashboard/dashboards/project/containers/tests.py index 2621d6328..44cd999b8 100644 --- a/openstack_dashboard/dashboards/project/containers/tests.py +++ b/openstack_dashboard/dashboards/project/containers/tests.py @@ -25,6 +25,7 @@ from django import http from django.utils import http as utils_http from mox3.mox import IsA # noqa +import six from openstack_dashboard import api from openstack_dashboard.dashboards.project.containers import forms @@ -110,7 +111,7 @@ class SwiftTests(test.TestCase): handled = table.maybe_handle() self.assertEqual(handled.status_code, 302) - self.assertEqual(unicode(list(req._messages)[0].message), + self.assertEqual(six.text_type(list(req._messages)[0].message), u"The container cannot be deleted " u"since it is not empty.") diff --git a/openstack_dashboard/dashboards/project/images/tests.py b/openstack_dashboard/dashboards/project/images/tests.py index 118a342d1..2a5824e60 100644 --- a/openstack_dashboard/dashboards/project/images/tests.py +++ b/openstack_dashboard/dashboards/project/images/tests.py @@ -23,6 +23,7 @@ from django.core.urlresolvers import reverse from django import http from mox3.mox import IsA # noqa +import six from horizon import exceptions @@ -114,7 +115,7 @@ class ImagesAndSnapshotsTests(test.TestCase): row_actions = snaps.get_row_actions(snaps.data[2]) # third instance - status queued, only delete is available self.assertEqual(len(row_actions), 1) - self.assertEqual(unicode(row_actions[0].verbose_name), + self.assertEqual(six.text_type(row_actions[0].verbose_name), u"Delete Image") self.assertEqual(str(row_actions[0]), "") diff --git a/openstack_dashboard/dashboards/project/instances/tests.py b/openstack_dashboard/dashboards/project/instances/tests.py index fd89ac1ab..10c43fde7 100644 --- a/openstack_dashboard/dashboards/project/instances/tests.py +++ b/openstack_dashboard/dashboards/project/instances/tests.py @@ -30,6 +30,7 @@ from django.utils import encoding from django.utils.http import urlencode from mox3.mox import IgnoreArg # noqa from mox3.mox import IsA # noqa +import six from horizon import exceptions from horizon import forms @@ -503,7 +504,8 @@ class InstanceTests(helpers.TestCase): api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \ .AndReturn([servers, False]) api.network.servers_update_addresses(IsA(http.HttpRequest), servers) - api.nova.server_suspend(IsA(http.HttpRequest), unicode(server.id)) + api.nova.server_suspend(IsA(http.HttpRequest), + six.text_type(server.id)) self.mox.ReplayAll() @@ -533,7 +535,7 @@ class InstanceTests(helpers.TestCase): api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \ .AndReturn([servers, False]) api.network.servers_update_addresses(IsA(http.HttpRequest), servers) - api.nova.server_suspend(IsA(http.HttpRequest), unicode(server.id)) \ + api.nova.server_suspend(IsA(http.HttpRequest), six.text_type(server.id)) \ .AndRaise(self.exceptions.nova) self.mox.ReplayAll() @@ -565,7 +567,7 @@ class InstanceTests(helpers.TestCase): api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \ .AndReturn([servers, False]) api.network.servers_update_addresses(IsA(http.HttpRequest), servers) - api.nova.server_resume(IsA(http.HttpRequest), unicode(server.id)) + api.nova.server_resume(IsA(http.HttpRequest), six.text_type(server.id)) self.mox.ReplayAll() @@ -597,7 +599,7 @@ class InstanceTests(helpers.TestCase): .AndReturn([servers, False]) api.network.servers_update_addresses(IsA(http.HttpRequest), servers) api.nova.server_resume(IsA(http.HttpRequest), - unicode(server.id)) \ + six.text_type(server.id)) \ .AndRaise(self.exceptions.nova) self.mox.ReplayAll() @@ -3286,7 +3288,7 @@ class InstanceTests(helpers.TestCase): launch = tables.LaunchLink() url = launch.get_link_url() classes = list(launch.get_default_classes()) + list(launch.classes) - link_name = "%s (%s)" % (unicode(launch.verbose_name), + link_name = "%s (%s)" % (six.text_type(launch.verbose_name), "Quota exceeded") res = self.client.get(INDEX_URL) diff --git a/openstack_dashboard/dashboards/project/networks/tests.py b/openstack_dashboard/dashboards/project/networks/tests.py index 81c517242..0213edfc3 100644 --- a/openstack_dashboard/dashboards/project/networks/tests.py +++ b/openstack_dashboard/dashboards/project/networks/tests.py @@ -16,6 +16,8 @@ from django.core.urlresolvers import reverse from django import http from django.utils.html import escape +import six + from horizon.workflows import views from mox3.mox import IsA # noqa @@ -1854,7 +1856,7 @@ class NetworkViewTests(test.TestCase): url = create_link.get_link_url() classes = (list(create_link.get_default_classes()) + list(create_link.classes)) - link_name = "%s (%s)" % (unicode(create_link.verbose_name), + link_name = "%s (%s)" % (six.text_type(create_link.verbose_name), "Quota exceeded") expected_string = "" \ @@ -1873,7 +1875,7 @@ class NetworkViewTests(test.TestCase): url = reverse(create_link.get_link_url(), args=[network_id]) classes = (list(create_link.get_default_classes()) + list(create_link.classes)) - link_name = "%s (%s)" % (unicode(create_link.verbose_name), + link_name = "%s (%s)" % (six.text_type(create_link.verbose_name), "Quota exceeded") expected_string = "%s" \ @@ -1924,7 +1926,7 @@ class NetworkViewTests(test.TestCase): url = create_link.get_link_url() classes = (list(create_link.get_default_classes()) + list(create_link.classes)) - link_name = "%s (%s)" % (unicode(create_link.verbose_name), + link_name = "%s (%s)" % (six.text_type(create_link.verbose_name), "Quota exceeded") expected_string = "" \ diff --git a/openstack_dashboard/dashboards/project/routers/tests.py b/openstack_dashboard/dashboards/project/routers/tests.py index 56f1736e3..8eb9e4d5d 100644 --- a/openstack_dashboard/dashboards/project/routers/tests.py +++ b/openstack_dashboard/dashboards/project/routers/tests.py @@ -18,6 +18,7 @@ from django import http from mox3.mox import IgnoreArg # noqa from mox3.mox import IsA # noqa +import six from openstack_dashboard import api from openstack_dashboard.dashboards.project.routers.extensions.routerrules\ @@ -946,7 +947,7 @@ class RouterViewTests(RouterMixin, test.TestCase): url = create_link.get_link_url() classes = (list(create_link.get_default_classes()) + list(create_link.classes)) - link_name = "%s (%s)" % (unicode(create_link.verbose_name), + link_name = "%s (%s)" % (six.text_type(create_link.verbose_name), "Quota exceeded") expected_string = "" \ diff --git a/openstack_dashboard/dashboards/project/stacks/forms.py b/openstack_dashboard/dashboards/project/stacks/forms.py index ba9e14181..431b6c259 100644 --- a/openstack_dashboard/dashboards/project/stacks/forms.py +++ b/openstack_dashboard/dashboards/project/stacks/forms.py @@ -150,7 +150,7 @@ class TemplateForm(forms.SelfHandlingForm): validated = api.heat.template_validate(self.request, **kwargs) cleaned['template_validate'] = validated except Exception as e: - raise forms.ValidationError(unicode(e)) + raise forms.ValidationError(six.text_type(e)) return cleaned diff --git a/openstack_dashboard/dashboards/project/stacks/tests.py b/openstack_dashboard/dashboards/project/stacks/tests.py index 5b3c52cc0..d2155747c 100644 --- a/openstack_dashboard/dashboards/project/stacks/tests.py +++ b/openstack_dashboard/dashboards/project/stacks/tests.py @@ -22,6 +22,7 @@ from django.test.utils import override_settings # noqa from django.utils import html from mox3.mox import IsA # noqa +import six from openstack_dashboard import api from openstack_dashboard.test import helpers as test @@ -626,7 +627,7 @@ class StackTests(test.TestCase): 'disable_rollback': True, 'timeout_mins': 61, 'password': 'password', - 'template': IsA(unicode), + 'template': IsA(six.text_type), 'parameters': IsA(dict) } api.heat.stack_update(IsA(http.HttpRequest), diff --git a/openstack_dashboard/dashboards/project/volumes/volumes/tests.py b/openstack_dashboard/dashboards/project/volumes/volumes/tests.py index 7b63ebaf4..6972ed4f4 100644 --- a/openstack_dashboard/dashboards/project/volumes/volumes/tests.py +++ b/openstack_dashboard/dashboards/project/volumes/volumes/tests.py @@ -23,6 +23,7 @@ from django import http from django.test.utils import override_settings from mox3.mox import IsA # noqa +import six from openstack_dashboard import api from openstack_dashboard.api import cinder @@ -1011,7 +1012,7 @@ class VolumeViewTests(test.TestCase): classes = (list(create_link.get_default_classes()) + list(create_link.classes)) - link_name = "%s (%s)" % (unicode(create_link.verbose_name), + link_name = "%s (%s)" % (six.text_type(create_link.verbose_name), "Quota exceeded") expected_string = "%s" \ @@ -1054,7 +1055,7 @@ class VolumeViewTests(test.TestCase): url = create_link.get_link_url() classes = (list(create_link.get_default_classes()) + list(create_link.classes)) - link_name = "%s (%s)" % (unicode(create_link.verbose_name), + link_name = "%s (%s)" % (six.text_type(create_link.verbose_name), "Quota exceeded") expected_string = "