Merge "tests: Use WarningsFixture in all tests"

This commit is contained in:
Zuul 2023-08-09 07:55:57 +00:00 committed by Gerrit Code Review
commit d4dffa1714
3 changed files with 52 additions and 3 deletions

View File

@ -13,12 +13,15 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import testtools
from unittest import mock from unittest import mock
from oslo_log.fixture import logging_error as log_fixture
import testtools
import webob import webob
import glance.api.common import glance.api.common
from glance.common import exception from glance.common import exception
from glance.tests.unit import fixtures as glance_fixtures
class SimpleIterator(object): class SimpleIterator(object):
@ -39,6 +42,17 @@ class SimpleIterator(object):
class TestSizeCheckedIter(testtools.TestCase): class TestSizeCheckedIter(testtools.TestCase):
def setUp(self):
super().setUp()
# Limit the amount of DeprecationWarning messages in the unit test logs
self.useFixture(glance_fixtures.WarningsFixture())
# Make sure logging output is limited but still test debug formatting
self.useFixture(log_fixture.get_logging_handle_error_fixture())
self.useFixture(glance_fixtures.StandardLogging())
def _get_image_metadata(self): def _get_image_metadata(self):
return {'id': 'e31cb99c-fe89-49fb-9cc5-f5104fffa636'} return {'id': 'e31cb99c-fe89-49fb-9cc5-f5104fffa636'}
@ -128,6 +142,16 @@ class TestSizeCheckedIter(testtools.TestCase):
class TestThreadPool(testtools.TestCase): class TestThreadPool(testtools.TestCase):
def setUp(self):
super().setUp()
# Limit the amount of DeprecationWarning messages in the unit test logs
self.useFixture(glance_fixtures.WarningsFixture())
# Make sure logging output is limited but still test debug formatting
self.useFixture(log_fixture.get_logging_handle_error_fixture())
self.useFixture(glance_fixtures.StandardLogging())
@mock.patch('glance.async_.get_threadpool_model') @mock.patch('glance.async_.get_threadpool_model')
def test_get_thread_pool(self, mock_gtm): def test_get_thread_pool(self, mock_gtm):
get_thread_pool = glance.api.common.get_thread_pool get_thread_pool = glance.api.common.get_thread_pool

View File

@ -16,10 +16,12 @@
import http.client import http.client
from unittest import mock from unittest import mock
from oslo_log.fixture import logging_error as log_fixture
import testtools import testtools
from glance.common import auth from glance.common import auth
from glance.common import client from glance.common import client
from glance.tests.unit import fixtures as glance_fixtures
from glance.tests import utils from glance.tests import utils
@ -31,8 +33,12 @@ class TestClient(testtools.TestCase):
self.client = client.BaseClient(self.endpoint, port=9191, self.client = client.BaseClient(self.endpoint, port=9191,
auth_token='abc123') auth_token='abc123')
def tearDown(self): # Limit the amount of DeprecationWarning messages in the unit test logs
super(TestClient, self).tearDown() self.useFixture(glance_fixtures.WarningsFixture())
# Make sure logging output is limited but still test debug formatting
self.useFixture(log_fixture.get_logging_handle_error_fixture())
self.useFixture(glance_fixtures.StandardLogging())
def test_make_auth_plugin(self): def test_make_auth_plugin(self):
creds = {'strategy': 'keystone'} creds = {'strategy': 'keystone'}

View File

@ -16,6 +16,7 @@
import http.client as http import http.client as http
from unittest.mock import patch from unittest.mock import patch
from oslo_log.fixture import logging_error as log_fixture
from oslo_policy import policy from oslo_policy import policy
from oslo_utils.fixture import uuidsentinel as uuids from oslo_utils.fixture import uuidsentinel as uuids
import testtools import testtools
@ -26,6 +27,7 @@ import glance.api.policy
from glance.common import exception from glance.common import exception
from glance import context from glance import context
from glance.tests.unit import base from glance.tests.unit import base
from glance.tests.unit import fixtures as glance_fixtures
from glance.tests.unit import test_policy from glance.tests.unit import test_policy
from glance.tests.unit import utils as unit_test_utils from glance.tests.unit import utils as unit_test_utils
@ -59,6 +61,16 @@ class ImageStub(object):
class TestCacheMiddlewareURLMatching(testtools.TestCase): class TestCacheMiddlewareURLMatching(testtools.TestCase):
def setUp(self):
super().setUp()
# Limit the amount of DeprecationWarning messages in the unit test logs
self.useFixture(glance_fixtures.WarningsFixture())
# Make sure logging output is limited but still test debug formatting
self.useFixture(log_fixture.get_logging_handle_error_fixture())
self.useFixture(glance_fixtures.StandardLogging())
def test_v2_match_id(self): def test_v2_match_id(self):
req = webob.Request.blank('/v2/images/asdf/file') req = webob.Request.blank('/v2/images/asdf/file')
out = glance.api.middleware.cache.CacheFilter._match_request(req) out = glance.api.middleware.cache.CacheFilter._match_request(req)
@ -81,6 +93,13 @@ class TestCacheMiddlewareRequestStashCacheInfo(testtools.TestCase):
self.request = webob.Request.blank('') self.request = webob.Request.blank('')
self.middleware = glance.api.middleware.cache.CacheFilter self.middleware = glance.api.middleware.cache.CacheFilter
# Limit the amount of DeprecationWarning messages in the unit test logs
self.useFixture(glance_fixtures.WarningsFixture())
# Make sure logging output is limited but still test debug formatting
self.useFixture(log_fixture.get_logging_handle_error_fixture())
self.useFixture(glance_fixtures.StandardLogging())
def test_stash_cache_request_info(self): def test_stash_cache_request_info(self):
self.middleware._stash_request_info(self.request, 'asdf', 'GET', 'v2') self.middleware._stash_request_info(self.request, 'asdf', 'GET', 'v2')
self.assertEqual('asdf', self.request.environ['api.cache.image_id']) self.assertEqual('asdf', self.request.environ['api.cache.image_id'])