Port last unit tests to Python 3

With this change, all Horizon unit tests pass on Python 3.4.

Changes:

* vpn/tests.py, firewalls/tests.py: Replace reverse_lazy() with
  reverse() to get a regular Python string. The lazy object caused
  failures on Python 3.
* routers/tests.py: Decode HTTP body to get Unicode on Python 3. It
  works also on Python 2.
* neutron.py: replace a/b with a//b to get an integer on Python 3.
* network_tests.py: remove useless copy.deepcopy() which caused a
  recursion error on Python 3.
* metadata_defs/tests.py: expect a different JSON error message on
  Python 3.
* tox.ini: remove openstack_dashboard whitelist, all unit tests now
  pass on Python 3 ;-)

Partial-Implements: blueprint porting-python3
Change-Id: I7b4f036fc86b66c92cccafe6938a906045f03186
This commit is contained in:
Victor Stinner 2015-11-12 18:14:42 +01:00
parent 80bbc35944
commit 7b55a2f71b
7 changed files with 19 additions and 61 deletions

View File

@ -585,7 +585,7 @@ def list_resources_with_long_filters(list_method,
val_maxlen = max(len(val) for val in filter_values)
filter_maxlen = len(filter_attr) + val_maxlen + 2
chunk_size = allowed_filter_len / filter_maxlen
chunk_size = allowed_filter_len // filter_maxlen
resources = []
for i in range(0, len(filter_values), chunk_size):

View File

@ -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.admin.metadata_defs \
@ -271,9 +272,13 @@ class MetadataDefinitionsCreateViewTest(test.BaseAdminViewTests):
res = self.client.post(reverse(constants.METADATA_CREATE_URL),
form_data)
self.assertFormError(res, "form", None, ['There was a problem loading '
'the namespace: No JSON '
'object could be decoded.'])
if six.PY3:
err_msg = ('There was a problem loading the namespace: '
'Expecting value: line 1 column 1 (char 0).')
else:
err_msg = ('There was a problem loading the namespace: '
'No JSON object could be decoded.')
self.assertFormError(res, "form", None, [err_msg])
def test_admin_metadata_defs_create_namespace_empty_json_post_raw(self):
form_data = {

View File

@ -15,7 +15,6 @@
from mox3.mox import IsA # noqa
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse_lazy
from django import http
from openstack_dashboard import api
@ -32,7 +31,7 @@ class FirewallTests(test.TestCase):
self[attr] = value
DASHBOARD = 'project'
INDEX_URL = reverse_lazy('horizon:%s:firewalls:index' % DASHBOARD)
INDEX_URL = reverse('horizon:%s:firewalls:index' % DASHBOARD)
ADDRULE_PATH = 'horizon:%s:firewalls:addrule' % DASHBOARD
ADDPOLICY_PATH = 'horizon:%s:firewalls:addpolicy' % DASHBOARD

View File

@ -199,7 +199,8 @@ class RouterTests(RouterMixin, test.TestCase):
res = self.client.post(self.INDEX_URL, formData, follow=True)
self.assertNoFormErrors(res)
self.assertMessageCount(response=res, success=1)
self.assertIn('Deleted Router: ' + router.name, res.content)
self.assertIn('Deleted Router: ' + router.name,
res.content.decode('utf-8'))
@test.create_stubs({api.neutron: ('router_list', 'network_list',
'port_list', 'router_remove_interface',
@ -242,7 +243,8 @@ class RouterTests(RouterMixin, test.TestCase):
res = self.client.post(self.INDEX_URL, formData, follow=True)
self.assertNoFormErrors(res)
self.assertMessageCount(response=res, success=1)
self.assertIn('Deleted Router: ' + router.name, res.content)
self.assertIn('Deleted Router: ' + router.name,
res.content.decode('utf-8'))
class RouterActionTests(RouterMixin, test.TestCase):

View File

@ -15,7 +15,6 @@
from mox3.mox import IsA # noqa
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse_lazy
from django import http
from horizon.workflows import views
@ -35,7 +34,7 @@ class VPNTests(test.TestCase):
self[attr] = value
DASHBOARD = 'project'
INDEX_URL = reverse_lazy('horizon:%s:vpn:index' % DASHBOARD)
INDEX_URL = reverse('horizon:%s:vpn:index' % DASHBOARD)
ADDIKEPOLICY_PATH = 'horizon:%s:vpn:addikepolicy' % DASHBOARD
ADDIPSECPOLICY_PATH = 'horizon:%s:vpn:addipsecpolicy' % DASHBOARD

View File

@ -266,7 +266,7 @@ class NetworkApiNeutronTests(NetworkApiNeutronTestBase):
def _test_servers_update_addresses(self, router_enabled=True):
tenant_id = self.request.user.tenant_id
servers = copy.deepcopy(self.servers.list())
servers = self.servers.list()
server_ids = [server.id for server in servers]
server_ports = [p for p in self.api_ports.list()
if p['device_id'] in server_ids]

53
tox.ini
View File

@ -22,57 +22,10 @@ commands = /bin/bash run_tests.sh -N --no-pep8 {posargs}
[testenv:py34]
commands =
python manage.py test --settings=horizon.test.settings horizon.test.tests
python manage.py test --settings=openstack_dashboard.test.settings \
python -u manage.py test --settings=horizon.test.settings horizon.test.tests
python -u manage.py test --settings=openstack_dashboard.test.settings \
--exclude-dir=openstack_dashboard/test/integration_tests \
openstack_dashboard.dashboards.admin.aggregates \
openstack_dashboard.dashboards.admin.metering \
openstack_dashboard.dashboards.admin.routers \
openstack_dashboard.dashboards.admin.volumes.volumes.tests \
openstack_dashboard.dashboards.identity.identity_providers \
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 \
openstack_dashboard.dashboards.project.network_topology \
openstack_dashboard.dashboards.project.networks.tests \
openstack_dashboard.dashboards.project.overview.tests \
openstack_dashboard.dashboards.project.stacks \
openstack_dashboard.dashboards.project.volumes \
openstack_dashboard.dashboards.settings.password \
openstack_dashboard.test.api_tests.base_tests.APIDictWrapperTests \
openstack_dashboard.test.api_tests.base_tests.APIResourceWrapperTests \
openstack_dashboard.test.api_tests.base_tests.ApiHelperTests \
openstack_dashboard.test.api_tests.base_tests.ApiVersionTests \
openstack_dashboard.test.api_tests.base_tests.QuotaSetTests \
openstack_dashboard.test.api_tests.ceilometer_tests \
openstack_dashboard.test.api_tests.cinder_rest_tests \
openstack_dashboard.test.api_tests.cinder_tests \
openstack_dashboard.test.api_tests.config_rest_tests \
openstack_dashboard.test.api_tests.fwaas_tests \
openstack_dashboard.test.api_tests.glance_rest_tests \
openstack_dashboard.test.api_tests.glance_tests \
openstack_dashboard.test.api_tests.heat_rest_tests \
openstack_dashboard.test.api_tests.heat_tests \
openstack_dashboard.test.api_tests.keystone_rest_tests \
openstack_dashboard.test.api_tests.keystone_tests \
openstack_dashboard.test.api_tests.lbaas_tests \
openstack_dashboard.test.api_tests.network_rest_tests \
openstack_dashboard.test.api_tests.neutron_rest_tests \
openstack_dashboard.test.api_tests.neutron_rest_tests.NeutronPortsTestCase \
openstack_dashboard.test.api_tests.nova_rest_tests \
openstack_dashboard.test.api_tests.nova_tests \
openstack_dashboard.test.api_tests.policy_rest_tests \
openstack_dashboard.test.api_tests.rest_util_tests \
openstack_dashboard.test.test_plugins.panel_group_tests.PanelGroupPluginTests \
openstack_dashboard.test.test_plugins.panel_tests.PanelPluginTests \
openstack_dashboard.test.tests.error_pages \
openstack_dashboard.test.tests.policy \
openstack_dashboard.test.tests.policy_backend \
openstack_dashboard.test.tests.quotas \
openstack_dashboard.test.tests.utils
openstack_dashboard
[testenv:pep8]
commands =