From 46628f0cb1ca4c4f6a78239a3bfb0c7644c4289c Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 7 Sep 2015 12:03:57 +0200 Subject: [PATCH] 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 --- horizon/test/tests/base.py | 11 ++++++----- tox.ini | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/horizon/test/tests/base.py b/horizon/test/tests/base.py index 478b1f84de..2ce4637530 100644 --- a/horizon/test/tests/base.py +++ b/horizon/test/tests/base.py @@ -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): diff --git a/tox.ini b/tox.ini index 787a53ba0b..1161049715 100644 --- a/tox.ini +++ b/tox.ini @@ -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 \