diff --git a/ceilometer/tests/api/v2/test_app.py b/ceilometer/tests/api/v2/test_app.py index a68f7284e..d2867957e 100644 --- a/ceilometer/tests/api/v2/test_app.py +++ b/ceilometer/tests/api/v2/test_app.py @@ -20,11 +20,12 @@ """ import os +import mock + from ceilometer.api import acl from ceilometer.api import app from ceilometer.openstack.common import fileutils from ceilometer.openstack.common.fixture import config -from ceilometer.openstack.common.fixture import moxstubout from ceilometer.openstack.common import gettextutils from ceilometer import service from ceilometer.tests.api.v2 import FunctionalTest @@ -88,10 +89,6 @@ class TestApiMiddleware(FunctionalTest): no_lang_translated_error = 'No lang translated error' en_US_translated_error = 'en-US translated error' - def setUp(self): - super(TestApiMiddleware, self).setUp() - self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs - def _fake_get_localized_message(self, message, user_locale): if user_locale is None: return self.no_lang_translated_error @@ -141,14 +138,14 @@ class TestApiMiddleware(FunctionalTest): def test_json_parsable_error_middleware_translation_400(self): # Ensure translated messages get placed properly into json faults - self.stubs.Set(gettextutils, 'get_localized_message', - self._fake_get_localized_message) - response = self.post_json('/alarms', params={'name': 'foobar', - 'type': 'threshold'}, - expect_errors=True, - headers={"Accept": - "application/json"} - ) + with mock.patch.object(gettextutils, 'get_localized_message', + side_effect=self._fake_get_localized_message): + response = self.post_json('/alarms', params={'name': 'foobar', + 'type': 'threshold'}, + expect_errors=True, + headers={"Accept": + "application/json"} + ) self.assertEqual(response.status_int, 400) self.assertEqual(response.content_type, "application/json") self.assertTrue(response.json['error_message']) @@ -176,15 +173,14 @@ class TestApiMiddleware(FunctionalTest): def test_xml_parsable_error_middleware_translation_400(self): # Ensure translated messages get placed properly into xml faults - self.stubs.Set(gettextutils, 'get_localized_message', - self._fake_get_localized_message) - - response = self.post_json('/alarms', params={'name': 'foobar', - 'type': 'threshold'}, - expect_errors=True, - headers={"Accept": - "application/xml,*/*"} - ) + with mock.patch.object(gettextutils, 'get_localized_message', + side_effect=self._fake_get_localized_message): + response = self.post_json('/alarms', params={'name': 'foobar', + 'type': 'threshold'}, + expect_errors=True, + headers={"Accept": + "application/xml,*/*"} + ) self.assertEqual(response.status_int, 400) self.assertEqual(response.content_type, "application/xml") self.assertEqual(response.xml.tag, 'error_message') @@ -194,17 +190,17 @@ class TestApiMiddleware(FunctionalTest): def test_best_match_language(self): # Ensure that we are actually invoking language negotiation - self.stubs.Set(gettextutils, 'get_localized_message', - self._fake_get_localized_message) + with mock.patch.object(gettextutils, 'get_localized_message', + side_effect=self._fake_get_localized_message): + response = self.post_json('/alarms', params={'name': 'foobar', + 'type': 'threshold'}, + expect_errors=True, + headers={"Accept": + "application/xml,*/*", + "Accept-Language": + "en-US"} + ) - response = self.post_json('/alarms', params={'name': 'foobar', - 'type': 'threshold'}, - expect_errors=True, - headers={"Accept": - "application/xml,*/*", - "Accept-Language": - "en-US"} - ) self.assertEqual(response.status_int, 400) self.assertEqual(response.content_type, "application/xml") self.assertEqual(response.xml.tag, 'error_message') diff --git a/ceilometer/tests/api/v2/test_post_samples_scenarios.py b/ceilometer/tests/api/v2/test_post_samples_scenarios.py index 64bc246b0..efee539f9 100644 --- a/ceilometer/tests/api/v2/test_post_samples_scenarios.py +++ b/ceilometer/tests/api/v2/test_post_samples_scenarios.py @@ -20,11 +20,10 @@ import copy import datetime -import logging import testscenarios -from ceilometer.openstack.common.fixture import moxstubout +from ceilometer.openstack.common.fixture.mockpatch import PatchObject from ceilometer.openstack.common import rpc from ceilometer.openstack.common import timeutils from ceilometer.tests.api.v2 import FunctionalTest @@ -33,13 +32,11 @@ from ceilometer.tests import db as tests_db load_tests = testscenarios.load_tests_apply_scenarios -LOG = logging.getLogger(__name__) - class TestPostSamples(FunctionalTest, tests_db.MixinTestsWithBackendScenarios): - def faux_cast(self, context, topic, msg): + def fake_cast(self, context, topic, msg): for s in msg['args']['data']: del s['message_signature'] self.published.append((topic, msg)) @@ -47,8 +44,7 @@ class TestPostSamples(FunctionalTest, def setUp(self): super(TestPostSamples, self).setUp() self.published = [] - self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs - self.stubs.Set(rpc, 'cast', self.faux_cast) + self.useFixture(PatchObject(rpc, 'cast', side_effect=self.fake_cast)) def test_one(self): s1 = [{'counter_name': 'apples', diff --git a/ceilometer/tests/api/v2/test_query.py b/ceilometer/tests/api/v2/test_query.py index 1d5cff532..f2c2650e5 100644 --- a/ceilometer/tests/api/v2/test_query.py +++ b/ceilometer/tests/api/v2/test_query.py @@ -21,7 +21,7 @@ import wsme from ceilometer.api.controllers import v2 as api from ceilometer.api.controllers.v2 import Query -from ceilometer.openstack.common.fixture import moxstubout +from ceilometer.openstack.common.fixture.mockpatch import PatchObject from ceilometer.openstack.common import test from ceilometer.openstack.common import timeutils from ceilometer import storage @@ -171,9 +171,10 @@ class TestValidateGroupByFields(test.BaseTestCase): class TestQueryToKwArgs(tests_base.BaseTestCase): def setUp(self): super(TestQueryToKwArgs, self).setUp() - self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs - self.stubs.Set(api, '_sanitize_query', lambda x, y, **z: x) - self.stubs.Set(api, '_verify_query_segregation', lambda x, **z: x) + self.useFixture(PatchObject(api, '_sanitize_query', + side_effect=lambda x, y, **z: x)) + self.useFixture(PatchObject(api, '_verify_query_segregation', + side_effect=lambda x, **z: x)) def test_sample_filter_single(self): q = [Query(field='user_id',