Merge "Fix str and dict usages in unittests for Python3"

This commit is contained in:
Zuul 2018-03-19 06:43:14 +00:00 committed by Gerrit Code Review
commit b0479c0278
10 changed files with 48 additions and 29 deletions

View File

@ -20,6 +20,8 @@ from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.decorators.debug import sensitive_variables # noqa from django.views.decorators.debug import sensitive_variables # noqa
import six
from horizon import exceptions from horizon import exceptions
from horizon import forms from horizon import forms
from horizon import messages from horizon import messages
@ -299,10 +301,10 @@ class LaunchForm(forms.SelfHandlingForm):
else: else:
fields_to_restore_at_the_end[k] = v fields_to_restore_at_the_end[k] = v
for k, v in datastore_flavor_fields.iteritems(): for k, v in datastore_flavor_fields.items():
self.fields[k] = v self.fields[k] = v
for k in reversed(fields_to_restore_at_the_end.keys()): for k in reversed(list(fields_to_restore_at_the_end.keys())):
self.fields[k] = fields_to_restore_at_the_end[k] self.fields[k] = fields_to_restore_at_the_end[k]
def _add_attr_to_optional_fields(self, datastore, selection_text): def _add_attr_to_optional_fields(self, datastore, selection_text):
@ -363,7 +365,8 @@ class LaunchForm(forms.SelfHandlingForm):
except Exception as e: except Exception as e:
redirect = reverse("horizon:project:database_clusters:index") redirect = reverse("horizon:project:database_clusters:index")
exceptions.handle(request, exceptions.handle(request,
_('Unable to launch cluster. %s') % e.message, _('Unable to launch cluster. %s') %
six.text_type(e),
redirect=redirect) redirect=redirect)
@ -465,7 +468,8 @@ class ClusterAddInstanceForm(forms.SelfHandlingForm):
except Exception as e: except Exception as e:
redirect = reverse("horizon:project:database_clusters:index") redirect = reverse("horizon:project:database_clusters:index")
exceptions.handle(request, exceptions.handle(request,
_('Unable to grow cluster. %s') % e.message, _('Unable to grow cluster. %s') %
six.text_type(e),
redirect=redirect) redirect=redirect)
return True return True
@ -489,5 +493,5 @@ class ResetPasswordForm(forms.SelfHandlingForm):
except Exception as e: except Exception as e:
redirect = reverse("horizon:project:database_clusters:index") redirect = reverse("horizon:project:database_clusters:index")
exceptions.handle(request, _('Unable to reset password. %s') % exceptions.handle(request, _('Unable to reset password. %s') %
e.message, redirect=redirect) six.text_type(e), redirect=redirect)
return True return True

View File

@ -20,6 +20,8 @@ from django.template.defaultfilters import title # noqa
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy from django.utils.translation import ungettext_lazy
import six
from horizon import messages from horizon import messages
from horizon import tables from horizon import tables
from horizon.templatetags import sizeformat from horizon.templatetags import sizeformat
@ -269,10 +271,10 @@ class ClusterShrinkAction(tables.BatchAction):
except Exception as ex: except Exception as ex:
LOG.error('Action %(action)s failed with %(ex)s for %(data)s' % LOG.error('Action %(action)s failed with %(ex)s for %(data)s' %
{'action': self._get_action_name(past=True).lower(), {'action': self._get_action_name(past=True).lower(),
'ex': ex.message, 'ex': six.text_type(ex),
'data': display_str}) 'data': display_str})
msg = _('Unable to remove instances from cluster: %s') msg = _('Unable to remove instances from cluster: %s')
messages.error(request, msg % ex.message) messages.error(request, msg % six.text_type(ex))
return shortcuts.redirect(self.get_success_url(request)) return shortcuts.redirect(self.get_success_url(request))
@ -404,10 +406,10 @@ class ClusterGrowAction(tables.Action):
messages.success(request, msg) messages.success(request, msg)
except Exception as ex: except Exception as ex:
LOG.error('Action grow cluster failed with %(ex)s for %(data)s' % LOG.error('Action grow cluster failed with %(ex)s for %(data)s' %
{'ex': ex.message, {'ex': six.text_type(ex),
'data': display_str}) 'data': display_str})
msg = _('Unable to grow cluster: %s') msg = _('Unable to grow cluster: %s')
messages.error(request, msg % ex.message) messages.error(request, msg % six.text_type(ex))
finally: finally:
cluster_manager.delete(cluster_id) cluster_manager.delete(cluster_id)

View File

@ -653,7 +653,7 @@ class ClustersTests(test.TestCase):
return filtered_datastore_versions return filtered_datastore_versions
def _contains_datastore_in_attribute(self, field, datastore): def _contains_datastore_in_attribute(self, field, datastore):
for key, value in field.widget.attrs.iteritems(): for key, value in field.widget.attrs.items():
if datastore in key: if datastore in key:
return True return True
return False return False

View File

@ -15,6 +15,8 @@
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import six
from horizon import exceptions from horizon import exceptions
from horizon import forms from horizon import forms
from horizon import messages from horizon import messages
@ -107,7 +109,7 @@ class CreateConfigurationForm(forms.SelfHandlingForm):
redirect = reverse("horizon:project:database_configurations:index") redirect = reverse("horizon:project:database_configurations:index")
exceptions.handle(request, _('Unable to create configuration ' exceptions.handle(request, _('Unable to create configuration '
'group. %s') 'group. %s')
% e.message, redirect=redirect) % six.text_type(e), redirect=redirect)
return True return True
@ -185,5 +187,5 @@ class AddParameterForm(forms.SelfHandlingForm):
except Exception as e: except Exception as e:
redirect = reverse("horizon:project:database_configurations:index") redirect = reverse("horizon:project:database_configurations:index")
exceptions.handle(request, _('Unable to add new parameter: %s') exceptions.handle(request, _('Unable to add new parameter: %s')
% e.message, redirect=redirect) % six.text_type(e), redirect=redirect)
return True return True

View File

@ -20,6 +20,8 @@ from django import shortcuts
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy from django.utils.translation import ungettext_lazy
import six
from horizon import forms from horizon import forms
from horizon import messages from horizon import messages
from horizon import tables from horizon import tables
@ -141,7 +143,7 @@ class DiscardChanges(tables.Action):
except Exception as ex: except Exception as ex:
messages.error( messages.error(
request, request,
_('Error resetting parameters: %s') % ex.message) _('Error resetting parameters: %s') % six.text_type(ex))
return shortcuts.redirect(request.build_absolute_uri()) return shortcuts.redirect(request.build_absolute_uri())

View File

@ -16,6 +16,8 @@ from django.core.urlresolvers import reverse
from django.forms import ValidationError # noqa from django.forms import ValidationError # noqa
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import six
from horizon import exceptions from horizon import exceptions
from horizon import forms from horizon import forms
from horizon import messages from horizon import messages
@ -47,7 +49,7 @@ class CreateDatabaseForm(forms.SelfHandlingForm):
redirect = reverse("horizon:project:databases:detail", redirect = reverse("horizon:project:databases:detail",
args=(instance,)) args=(instance,))
exceptions.handle(request, _('Unable to create database. %s') % exceptions.handle(request, _('Unable to create database. %s') %
e.message, redirect=redirect) six.text_type(e), redirect=redirect)
return True return True
@ -88,7 +90,7 @@ class ResizeVolumeForm(forms.SelfHandlingForm):
except Exception as e: except Exception as e:
redirect = reverse("horizon:project:databases:index") redirect = reverse("horizon:project:databases:index")
exceptions.handle(request, _('Unable to resize volume. %s') % exceptions.handle(request, _('Unable to resize volume. %s') %
e.message, redirect=redirect) six.text_type(e), redirect=redirect)
return True return True
@ -126,7 +128,7 @@ class ResizeInstanceForm(forms.SelfHandlingForm):
except Exception as e: except Exception as e:
redirect = reverse("horizon:project:databases:index") redirect = reverse("horizon:project:databases:index")
exceptions.handle(request, _('Unable to resize instance. %s') % exceptions.handle(request, _('Unable to resize instance. %s') %
e.message, redirect=redirect) six.text_type(e), redirect=redirect)
return True return True
@ -146,7 +148,7 @@ class PromoteToReplicaSourceForm(forms.SelfHandlingForm):
exceptions.handle( exceptions.handle(
request, request,
_('Unable to promote replica as the new replica source. "%s"') _('Unable to promote replica as the new replica source. "%s"')
% e.message, redirect=redirect) % six.text_type(e), redirect=redirect)
return True return True
@ -182,7 +184,7 @@ class CreateUserForm(forms.SelfHandlingForm):
redirect = reverse("horizon:project:databases:detail", redirect = reverse("horizon:project:databases:detail",
args=(instance,)) args=(instance,))
exceptions.handle(request, _('Unable to create user. %s') % exceptions.handle(request, _('Unable to create user. %s') %
e.message, redirect=redirect) six.text_type(e), redirect=redirect)
return True return True
def _get_databases(self, data): def _get_databases(self, data):
@ -231,7 +233,7 @@ class EditUserForm(forms.SelfHandlingForm):
redirect = reverse("horizon:project:databases:detail", redirect = reverse("horizon:project:databases:detail",
args=(instance,)) args=(instance,))
exceptions.handle(request, _('Unable to update user. %s') % exceptions.handle(request, _('Unable to update user. %s') %
e.message, redirect=redirect) six.text_type(e), redirect=redirect)
return True return True
def clean(self): def clean(self):
@ -279,5 +281,5 @@ class AttachConfigurationForm(forms.SelfHandlingForm):
redirect = reverse("horizon:project:databases:index") redirect = reverse("horizon:project:databases:index")
exceptions.handle(request, _('Unable to attach configuration ' exceptions.handle(request, _('Unable to attach configuration '
'group. %s') 'group. %s')
% e.message, redirect=redirect) % six.text_type(e), redirect=redirect)
return True return True

View File

@ -17,6 +17,8 @@ from django import shortcuts
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views import generic from django.views import generic
import six
from horizon import exceptions from horizon import exceptions
from horizon import messages from horizon import messages
@ -63,7 +65,8 @@ def get_contents(request, instance_id, filename, publish, lines):
for log_part in log_generator(): for log_part in log_generator():
data += log_part data += log_part
except Exception as e: except Exception as e:
data = _('Unable to load {0} log\n{1}').format(filename, e.message) data = _('Unable to load {0} log\n{1}').format(filename,
six.text_type(e))
return data return data

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import six.moves.urllib.parse as urlparse
from django.conf import settings from django.conf import settings
from django.core import urlresolvers from django.core import urlresolvers
from django.template import defaultfilters as d_filters from django.template import defaultfilters as d_filters
@ -22,6 +20,9 @@ from django.utils.translation import pgettext_lazy
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy from django.utils.translation import ungettext_lazy
import six
import six.moves.urllib.parse as urlparse
from horizon import exceptions from horizon import exceptions
from horizon import messages from horizon import messages
from horizon import tables from horizon import tables
@ -510,7 +511,8 @@ class DisableRootAction(tables.Action):
messages.success(request, _("Successfully disabled root access.")) messages.success(request, _("Successfully disabled root access."))
except Exception as e: except Exception as e:
messages.warning(request, messages.warning(request,
_("Cannot disable root access: %s") % e.message) _("Cannot disable root access: %s") %
six.text_type(e))
class ManageRoot(tables.LinkAction): class ManageRoot(tables.LinkAction):

View File

@ -15,6 +15,8 @@
from django import template from django import template
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import six
from horizon import exceptions from horizon import exceptions
from horizon import tabs from horizon import tabs
from oslo_log import log as logging from oslo_log import log as logging
@ -178,7 +180,7 @@ class LogsTab(tabs.TableTab):
return logs return logs
except Exception as e: except Exception as e:
LOG.exception( LOG.exception(
_('Unable to retrieve list of logs.\n%s') % e.message) _('Unable to retrieve list of logs.\n%s') % six.text_type(e))
logs = [] logs = []
return logs return logs

View File

@ -496,7 +496,7 @@ class DatabaseTests(test.TestCase):
database.id = u'id' database.id = u'id'
user = self.database_user_roots.first() user = self.database_user_roots.first()
api.trove.instance_get(IsA(http.HttpRequest), IsA(unicode))\ api.trove.instance_get(IsA(http.HttpRequest), IsA(six.text_type))\
.AndReturn(database) .AndReturn(database)
api.trove.root_show(IsA(http.HttpRequest), database.id) \ api.trove.root_show(IsA(http.HttpRequest), database.id) \
@ -514,7 +514,7 @@ class DatabaseTests(test.TestCase):
def test_show_root_exception(self): def test_show_root_exception(self):
database = self.databases.first() database = self.databases.first()
api.trove.instance_get(IsA(http.HttpRequest), IsA(unicode))\ api.trove.instance_get(IsA(http.HttpRequest), IsA(six.text_type))\
.AndReturn(database) .AndReturn(database)
api.trove.root_show(IsA(http.HttpRequest), u'id') \ api.trove.root_show(IsA(http.HttpRequest), u'id') \
@ -1266,7 +1266,7 @@ class DatabaseTests(test.TestCase):
database = self.databases.first() database = self.databases.first()
configuration = self.database_configurations.first() configuration = self.database_configurations.first()
api.trove.instance_get(IsA(http.HttpRequest), IsA(unicode))\ api.trove.instance_get(IsA(http.HttpRequest), IsA(six.text_type))\
.AndReturn(database) .AndReturn(database)
api.trove.configuration_list(IsA(http.HttpRequest))\ api.trove.configuration_list(IsA(http.HttpRequest))\
@ -1296,7 +1296,7 @@ class DatabaseTests(test.TestCase):
database = self.databases.first() database = self.databases.first()
configuration = self.database_configurations.first() configuration = self.database_configurations.first()
api.trove.instance_get(IsA(http.HttpRequest), IsA(unicode))\ api.trove.instance_get(IsA(http.HttpRequest), IsA(six.text_type))\
.AndReturn(database) .AndReturn(database)
api.trove.configuration_list(IsA(http.HttpRequest))\ api.trove.configuration_list(IsA(http.HttpRequest))\