Fix Python 3 issues in dashboard image tests
* Use NamedTemporaryFile instead of TemporaryFile because we must have a name which is a text on Python 3. Otherwise, the test fails. On Python 3, TemporaryFile uses an integer for the file name, the file descriptor. * Replace filter() and map() with list comprehensions to get a list on Python 3. * On Python 3, temporary files are open in binary mode so write a byte string instead of a text string. * tox.ini: enable all image tests on Python 3. Partial-Implements: blueprint porting-python3 Change-Id: Ice7f119c040bbddeda10ed45d137bb7851764b8d
This commit is contained in:
parent
aa86eea98c
commit
80ae31f461
@ -192,7 +192,7 @@ def filter_tenants():
|
||||
|
||||
@memoized
|
||||
def filter_tenant_ids():
|
||||
return map(lambda ft: ft['tenant'], filter_tenants())
|
||||
return [ft['tenant'] for ft in filter_tenants()]
|
||||
|
||||
|
||||
class OwnerFilter(tables.FixedFilterAction):
|
||||
|
@ -212,8 +212,8 @@ class ImageViewTests(test.TestCase):
|
||||
|
||||
@test.create_stubs({api.glance: ('image_create',)})
|
||||
def test_image_create_post_upload(self):
|
||||
temp_file = tempfile.TemporaryFile()
|
||||
temp_file.write('123')
|
||||
temp_file = tempfile.NamedTemporaryFile()
|
||||
temp_file.write(b'123')
|
||||
temp_file.flush()
|
||||
temp_file.seek(0)
|
||||
|
||||
@ -225,8 +225,8 @@ class ImageViewTests(test.TestCase):
|
||||
|
||||
@test.create_stubs({api.glance: ('image_create',)})
|
||||
def test_image_create_post_with_kernel_ramdisk(self):
|
||||
temp_file = tempfile.TemporaryFile()
|
||||
temp_file.write('123')
|
||||
temp_file = tempfile.NamedTemporaryFile()
|
||||
temp_file.write(b'123')
|
||||
temp_file.flush()
|
||||
temp_file.seek(0)
|
||||
|
||||
@ -417,12 +417,12 @@ class OwnerFilterTests(test.TestCase):
|
||||
special = map(lambda t: t['tenant'], self.filter_tenants)
|
||||
|
||||
if filter_string == 'public':
|
||||
return filter(lambda im: im.is_public, images)
|
||||
return [im for im in images if im.is_public]
|
||||
if filter_string == 'shared':
|
||||
return filter(lambda im: (not im.is_public and
|
||||
im.owner != my_tenant_id and
|
||||
im.owner not in special),
|
||||
images)
|
||||
return [im for im in images
|
||||
if (not im.is_public and
|
||||
im.owner != my_tenant_id and
|
||||
im.owner not in special)]
|
||||
if filter_string == 'project':
|
||||
filter_string = my_tenant_id
|
||||
return filter(lambda im: im.owner == filter_string, images)
|
||||
return [im for im in images if im.owner == filter_string]
|
||||
|
3
tox.ini
3
tox.ini
@ -33,8 +33,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.images.images.tests.CreateImageFormTests \
|
||||
openstack_dashboard.dashboards.project.images.tests.ImagesAndSnapshotsUtilsTests \
|
||||
openstack_dashboard.dashboards.project.images \
|
||||
openstack_dashboard.dashboards.project.instances \
|
||||
openstack_dashboard.dashboards.project.network_topology \
|
||||
openstack_dashboard.dashboards.project.networks.tests \
|
||||
|
Loading…
Reference in New Issue
Block a user