Replace mox with mock in tests.api.v2
Change-Id: Id928855178d5bb69d6fc4edf159c4f5cdf633c4e
This commit is contained in:
parent
fe158993bb
commit
0dc7d495ca
@ -20,11 +20,12 @@
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import mock
|
||||||
|
|
||||||
from ceilometer.api import acl
|
from ceilometer.api import acl
|
||||||
from ceilometer.api import app
|
from ceilometer.api import app
|
||||||
from ceilometer.openstack.common import fileutils
|
from ceilometer.openstack.common import fileutils
|
||||||
from ceilometer.openstack.common.fixture import config
|
from ceilometer.openstack.common.fixture import config
|
||||||
from ceilometer.openstack.common.fixture import moxstubout
|
|
||||||
from ceilometer.openstack.common import gettextutils
|
from ceilometer.openstack.common import gettextutils
|
||||||
from ceilometer import service
|
from ceilometer import service
|
||||||
from ceilometer.tests.api.v2 import FunctionalTest
|
from ceilometer.tests.api.v2 import FunctionalTest
|
||||||
@ -88,10 +89,6 @@ class TestApiMiddleware(FunctionalTest):
|
|||||||
no_lang_translated_error = 'No lang translated error'
|
no_lang_translated_error = 'No lang translated error'
|
||||||
en_US_translated_error = 'en-US 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):
|
def _fake_get_localized_message(self, message, user_locale):
|
||||||
if user_locale is None:
|
if user_locale is None:
|
||||||
return self.no_lang_translated_error
|
return self.no_lang_translated_error
|
||||||
@ -141,14 +138,14 @@ class TestApiMiddleware(FunctionalTest):
|
|||||||
|
|
||||||
def test_json_parsable_error_middleware_translation_400(self):
|
def test_json_parsable_error_middleware_translation_400(self):
|
||||||
# Ensure translated messages get placed properly into json faults
|
# Ensure translated messages get placed properly into json faults
|
||||||
self.stubs.Set(gettextutils, 'get_localized_message',
|
with mock.patch.object(gettextutils, 'get_localized_message',
|
||||||
self._fake_get_localized_message)
|
side_effect=self._fake_get_localized_message):
|
||||||
response = self.post_json('/alarms', params={'name': 'foobar',
|
response = self.post_json('/alarms', params={'name': 'foobar',
|
||||||
'type': 'threshold'},
|
'type': 'threshold'},
|
||||||
expect_errors=True,
|
expect_errors=True,
|
||||||
headers={"Accept":
|
headers={"Accept":
|
||||||
"application/json"}
|
"application/json"}
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_int, 400)
|
self.assertEqual(response.status_int, 400)
|
||||||
self.assertEqual(response.content_type, "application/json")
|
self.assertEqual(response.content_type, "application/json")
|
||||||
self.assertTrue(response.json['error_message'])
|
self.assertTrue(response.json['error_message'])
|
||||||
@ -176,15 +173,14 @@ class TestApiMiddleware(FunctionalTest):
|
|||||||
|
|
||||||
def test_xml_parsable_error_middleware_translation_400(self):
|
def test_xml_parsable_error_middleware_translation_400(self):
|
||||||
# Ensure translated messages get placed properly into xml faults
|
# Ensure translated messages get placed properly into xml faults
|
||||||
self.stubs.Set(gettextutils, 'get_localized_message',
|
with mock.patch.object(gettextutils, 'get_localized_message',
|
||||||
self._fake_get_localized_message)
|
side_effect=self._fake_get_localized_message):
|
||||||
|
response = self.post_json('/alarms', params={'name': 'foobar',
|
||||||
response = self.post_json('/alarms', params={'name': 'foobar',
|
'type': 'threshold'},
|
||||||
'type': 'threshold'},
|
expect_errors=True,
|
||||||
expect_errors=True,
|
headers={"Accept":
|
||||||
headers={"Accept":
|
"application/xml,*/*"}
|
||||||
"application/xml,*/*"}
|
)
|
||||||
)
|
|
||||||
self.assertEqual(response.status_int, 400)
|
self.assertEqual(response.status_int, 400)
|
||||||
self.assertEqual(response.content_type, "application/xml")
|
self.assertEqual(response.content_type, "application/xml")
|
||||||
self.assertEqual(response.xml.tag, 'error_message')
|
self.assertEqual(response.xml.tag, 'error_message')
|
||||||
@ -194,17 +190,17 @@ class TestApiMiddleware(FunctionalTest):
|
|||||||
|
|
||||||
def test_best_match_language(self):
|
def test_best_match_language(self):
|
||||||
# Ensure that we are actually invoking language negotiation
|
# Ensure that we are actually invoking language negotiation
|
||||||
self.stubs.Set(gettextutils, 'get_localized_message',
|
with mock.patch.object(gettextutils, 'get_localized_message',
|
||||||
self._fake_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.status_int, 400)
|
||||||
self.assertEqual(response.content_type, "application/xml")
|
self.assertEqual(response.content_type, "application/xml")
|
||||||
self.assertEqual(response.xml.tag, 'error_message')
|
self.assertEqual(response.xml.tag, 'error_message')
|
||||||
|
@ -20,11 +20,10 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
|
||||||
|
|
||||||
import testscenarios
|
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 rpc
|
||||||
from ceilometer.openstack.common import timeutils
|
from ceilometer.openstack.common import timeutils
|
||||||
from ceilometer.tests.api.v2 import FunctionalTest
|
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
|
load_tests = testscenarios.load_tests_apply_scenarios
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class TestPostSamples(FunctionalTest,
|
class TestPostSamples(FunctionalTest,
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
tests_db.MixinTestsWithBackendScenarios):
|
||||||
|
|
||||||
def faux_cast(self, context, topic, msg):
|
def fake_cast(self, context, topic, msg):
|
||||||
for s in msg['args']['data']:
|
for s in msg['args']['data']:
|
||||||
del s['message_signature']
|
del s['message_signature']
|
||||||
self.published.append((topic, msg))
|
self.published.append((topic, msg))
|
||||||
@ -47,8 +44,7 @@ class TestPostSamples(FunctionalTest,
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestPostSamples, self).setUp()
|
super(TestPostSamples, self).setUp()
|
||||||
self.published = []
|
self.published = []
|
||||||
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
|
self.useFixture(PatchObject(rpc, 'cast', side_effect=self.fake_cast))
|
||||||
self.stubs.Set(rpc, 'cast', self.faux_cast)
|
|
||||||
|
|
||||||
def test_one(self):
|
def test_one(self):
|
||||||
s1 = [{'counter_name': 'apples',
|
s1 = [{'counter_name': 'apples',
|
||||||
|
@ -21,7 +21,7 @@ import wsme
|
|||||||
|
|
||||||
from ceilometer.api.controllers import v2 as api
|
from ceilometer.api.controllers import v2 as api
|
||||||
from ceilometer.api.controllers.v2 import Query
|
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 test
|
||||||
from ceilometer.openstack.common import timeutils
|
from ceilometer.openstack.common import timeutils
|
||||||
from ceilometer import storage
|
from ceilometer import storage
|
||||||
@ -171,9 +171,10 @@ class TestValidateGroupByFields(test.BaseTestCase):
|
|||||||
class TestQueryToKwArgs(tests_base.BaseTestCase):
|
class TestQueryToKwArgs(tests_base.BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestQueryToKwArgs, self).setUp()
|
super(TestQueryToKwArgs, self).setUp()
|
||||||
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
|
self.useFixture(PatchObject(api, '_sanitize_query',
|
||||||
self.stubs.Set(api, '_sanitize_query', lambda x, y, **z: x)
|
side_effect=lambda x, y, **z: x))
|
||||||
self.stubs.Set(api, '_verify_query_segregation', lambda x, **z: x)
|
self.useFixture(PatchObject(api, '_verify_query_segregation',
|
||||||
|
side_effect=lambda x, **z: x))
|
||||||
|
|
||||||
def test_sample_filter_single(self):
|
def test_sample_filter_single(self):
|
||||||
q = [Query(field='user_id',
|
q = [Query(field='user_id',
|
||||||
|
Loading…
Reference in New Issue
Block a user