From 34ef42a923fab149d192161b2ee41183704328a0 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 2 Feb 2016 15:58:37 +0100 Subject: [PATCH] Port dashboard containers to Python 3 On Python 3, Content-Disposition header is encoded using MIME format '=?utf-8?b?...?='. Use decode_header() of email.header to decode it. Handle also Unicode/bytes issues on this header. tox.ini: Add openstack_dashboard.dashboards.project.containers to Python 3.4. Partial-Implements: blueprint porting-python3 Change-Id: Id5898ee5494d019d1397ed3fa5e0a715e9a0393f --- .../dashboards/project/containers/tests.py | 18 ++++++++++++------ tox.ini | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/openstack_dashboard/dashboards/project/containers/tests.py b/openstack_dashboard/dashboards/project/containers/tests.py index 109ed79547..90509ed1e3 100644 --- a/openstack_dashboard/dashboards/project/containers/tests.py +++ b/openstack_dashboard/dashboards/project/containers/tests.py @@ -17,6 +17,7 @@ # under the License. import copy +import email.header import tempfile from django.core.files.uploadedfile import InMemoryUploadedFile # noqa @@ -359,13 +360,18 @@ class SwiftTests(test.TestCase): # Check that the returned Content-Disposition filename is well # surrounded by double quotes and with commas removed + content = res.get('Content-Disposition') expected_name = '"%s"' % obj.name.replace(',', '') - if six.PY2: - expected_name = expected_name.encode('utf-8') - self.assertEqual( - res.get('Content-Disposition'), - 'attachment; filename=%s' % expected_name - ) + expected = 'attachment; filename=%s' % expected_name + + if six.PY3: + header = email.header.decode_header(content) + content = header[0][0] + if isinstance(content, str): + content = content.encode('utf-8') + expected = expected.encode('utf-8') + + self.assertEqual(content, expected) @test.create_stubs({api.swift: ('swift_get_containers',)}) def test_copy_index(self): diff --git a/tox.ini b/tox.ini index d00a5d6746..badcc63535 100644 --- a/tox.ini +++ b/tox.ini @@ -31,6 +31,7 @@ commands = openstack_dashboard.dashboards.admin.volumes.volumes.tests \ openstack_dashboard.dashboards.identity.users \ openstack_dashboard.dashboards.project.access_and_security.api_access.tests \ + openstack_dashboard.dashboards.project.containers \ openstack_dashboard.dashboards.project.images \ openstack_dashboard.dashboards.project.instances \ openstack_dashboard.dashboards.project.loadbalancers \