Port horizon base tests to Python 3

* Replace registry.keys() with list(registry). On Python 3,
  dict.keys() now returns a dictionary view, whereas we need a copy
  of keys here.
* CustomPanelTests: load horizon.test.customization.cust_test1
  configuration after calling setUp() and force a reload of URLs.
  BaseHorizonTests.setUp() keeps original panels for each dashboard
  to be able to restore them in tearDown().
* tox.ini: run all horizon.test.tests.base tests on Python 3.4, not
  only horizon.test.tests.base.GetUserHomeTests.

Without the CustomPanelTests change, 3 tests fail with NoReverseMatch
when running the base test on Python 2 with the following command (in
the .tox/py27/ virtual environment):

    python manage.py test --settings=horizon.test.settings \
        horizon.test.tests.base

Partial-Implements: blueprint porting-python3
Change-Id: Ibdd5fcaa863c6eaae4a519f3d1b56034f0ef9708
This commit is contained in:
Victor Stinner 2015-09-07 12:03:57 +02:00 committed by Timur Sufiev
parent 749e436c63
commit 46628f0cb1
2 changed files with 7 additions and 6 deletions

View File

@ -87,11 +87,11 @@ class BaseHorizonTests(test.TestCase):
# hasn't happened yet.
base.Horizon._urls()
# Store our original dashboards
self._discovered_dashboards = base.Horizon._registry.keys()
self._discovered_dashboards = list(base.Horizon._registry)
# Gather up and store our original panels for each dashboard
self._discovered_panels = {}
for dash in self._discovered_dashboards:
panels = base.Horizon._registry[dash]._registry.keys()
panels = list(base.Horizon._registry[dash]._registry)
self._discovered_panels[dash] = panels
def tearDown(self):
@ -372,11 +372,12 @@ class CustomPanelTests(BaseHorizonTests):
"""
def setUp(self):
super(CustomPanelTests, self).setUp()
settings.HORIZON_CONFIG['customization_module'] = \
'horizon.test.customization.cust_test1'
# refresh config
conf.HORIZON_CONFIG._setup()
super(CustomPanelTests, self).setUp()
self._reload_urls()
def tearDown(self):
# Restore dash
@ -476,11 +477,11 @@ class RbacHorizonTests(test.TestCase):
# hasn't happened yet.
base.Horizon._urls()
# Store our original dashboards
self._discovered_dashboards = base.Horizon._registry.keys()
self._discovered_dashboards = list(base.Horizon._registry)
# Gather up and store our original panels for each dashboard
self._discovered_panels = {}
for dash in self._discovered_dashboards:
panels = base.Horizon._registry[dash]._registry.keys()
panels = list(base.Horizon._registry[dash]._registry)
self._discovered_panels[dash] = panels
def tearDown(self):

View File

@ -22,7 +22,7 @@ commands = /bin/bash run_tests.sh -N --no-pep8 {posargs}
[testenv:py34]
commands =
python manage.py test --settings=horizon.test.settings \
horizon.test.tests.base.GetUserHomeTests \
horizon.test.tests.base \
horizon.test.tests.forms \
horizon.test.tests.middleware \
horizon.test.tests.tables.DataTableViewTests \