Browse Source

Merge "test: use safer way to override settings"

tags/18.6.0
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
930c5a6138
2 changed files with 20 additions and 18 deletions
  1. +6
    -3
      openstack_dashboard/dashboards/settings/user/tests.py
  2. +14
    -15
      openstack_dashboard/test/unit/api/test_base.py

+ 6
- 3
openstack_dashboard/dashboards/settings/user/tests.py View File

@@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.

from django.conf import settings
from django.urls import reverse

from openstack_dashboard.test import helpers as test
@@ -32,9 +31,13 @@ class UserSettingsTest(test.TestCase):

def test_display_language(self):
# Add an unknown language to LANGUAGES list
settings.LANGUAGES += (('unknown', 'Unknown Language'),)
with self.modify_settings(
# NOTE: modify_settings take a list of values to append.
# We add a single entry but it is a tuple,
# so we need to wrap it as a list.
LANGUAGES={'append': [('unknown', 'Unknown Language')]}):
res = self.client.get(INDEX_URL)

res = self.client.get(INDEX_URL)
# Known language
self.assertContains(res, 'English')
# Unknown language


+ 14
- 15
openstack_dashboard/test/unit/api/test_base.py View File

@@ -16,8 +16,6 @@
# License for the specific language governing permissions and limitations
# under the License.

from django.conf import settings

from horizon import exceptions

from openstack_dashboard.api import base as api_base
@@ -232,21 +230,22 @@ class ApiVersionTests(test.TestCase):

def setUp(self):
super(ApiVersionTests, self).setUp()
self.previous_settings = settings.OPENSTACK_API_VERSIONS
settings.OPENSTACK_API_VERSIONS = {
"data-processing": 1.1,
"identity": "3",
"volume": 1
}
# Make sure cached data from other tests doesn't interfere
cinder.VERSIONS.clear_active_cache()
keystone.VERSIONS.clear_active_cache()
glance.VERSIONS.clear_active_cache()
override = self.settings(
OPENSTACK_API_VERSIONS={
"data-processing": 1.1,
"identity": "3",
"volume": 1
}
)
override.enable()
self.addCleanup(override.disable)

def tearDown(self):
super(ApiVersionTests, self).tearDown()
settings.OPENSTACK_API_VERSIONS = self.previous_settings
# Make sure cached data from other tests doesn't interfere
self._clear_version_cache()
# Clear out our bogus data so it doesn't interfere
self.addCleanup(self._clear_version_cache)

def _clear_version_cache(self):
cinder.VERSIONS.clear_active_cache()
keystone.VERSIONS.clear_active_cache()
glance.VERSIONS.clear_active_cache()


Loading…
Cancel
Save