Merge "Port openstack dashboard overview tests to Python 3"
This commit is contained in:
commit
2c3f81e00e
@ -37,7 +37,8 @@ class CsvDataMixin(object):
|
||||
self.out = StringIO()
|
||||
super(CsvDataMixin, self).__init__()
|
||||
if hasattr(self, "columns"):
|
||||
self.writer = DictWriter(self.out, map(self.encode, self.columns))
|
||||
columns = [self.encode(col) for col in self.columns]
|
||||
self.writer = DictWriter(self.out, columns)
|
||||
self.is_dict = True
|
||||
else:
|
||||
self.writer = writer(self.out)
|
||||
@ -56,14 +57,17 @@ class CsvDataMixin(object):
|
||||
def write_csv_row(self, args):
|
||||
if self.is_dict:
|
||||
self.writer.writerow(dict(zip(
|
||||
self.writer.fieldnames, map(self.encode, args))))
|
||||
self.writer.fieldnames, [self.encode(col) for col in args])))
|
||||
else:
|
||||
self.writer.writerow(map(self.encode, args))
|
||||
self.writer.writerow([self.encode(col) for col in args])
|
||||
|
||||
def encode(self, value):
|
||||
value = six.text_type(value)
|
||||
if six.PY2:
|
||||
# csv and StringIO cannot work with mixed encodings,
|
||||
# so encode all with utf-8
|
||||
return six.text_type(value).encode('utf-8')
|
||||
value = value.encode('utf-8')
|
||||
return value
|
||||
|
||||
|
||||
class BaseCsvResponse(CsvDataMixin, HttpResponse):
|
||||
|
1
tox.ini
1
tox.ini
@ -42,6 +42,7 @@ commands =
|
||||
openstack_dashboard.dashboards.project.access_and_security.api_access.tests \
|
||||
openstack_dashboard.dashboards.project.images.images.tests.CreateImageFormTests \
|
||||
openstack_dashboard.dashboards.project.images.tests.ImagesAndSnapshotsUtilsTests \
|
||||
openstack_dashboard.dashboards.project.overview.tests \
|
||||
openstack_dashboard.dashboards.project.stacks.tests.TemplateFormTests \
|
||||
openstack_dashboard.dashboards.settings.password \
|
||||
openstack_dashboard.test.api_tests.base_tests.APIDictWrapperTests \
|
||||
|
Loading…
Reference in New Issue
Block a user