Merge "Replace mox with mock in tests.storage"

This commit is contained in:
Jenkins 2013-11-18 15:46:05 +00:00 committed by Gerrit Code Review
commit 9a8a93a019
5 changed files with 37 additions and 45 deletions

View File

@ -18,7 +18,7 @@
"""Tests for ceilometer/storage/ """Tests for ceilometer/storage/
""" """
import mox import mock
from ceilometer.openstack.common import test from ceilometer.openstack.common import test
from ceilometer import storage from ceilometer import storage
@ -28,15 +28,13 @@ from ceilometer.storage import impl_log
class EngineTest(test.BaseTestCase): class EngineTest(test.BaseTestCase):
def test_get_engine(self): def test_get_engine(self):
conf = mox.Mox().CreateMockAnything() conf = mock.Mock()
conf.database = mox.Mox().CreateMockAnything()
conf.database.connection = 'log://localhost' conf.database.connection = 'log://localhost'
engine = storage.get_engine(conf) engine = storage.get_engine(conf)
self.assertIsInstance(engine, impl_log.LogStorage) self.assertIsInstance(engine, impl_log.LogStorage)
def test_get_engine_no_such_engine(self): def test_get_engine_no_such_engine(self):
conf = mox.Mox().CreateMockAnything() conf = mock.Mock()
conf.database = mox.Mox().CreateMockAnything()
conf.database.connection = 'no-such-engine://localhost' conf.database.connection = 'no-such-engine://localhost'
try: try:
storage.get_engine(conf) storage.get_engine(conf)

View File

@ -24,7 +24,8 @@
running the tests. Make sure the Thrift server is running on that server. running the tests. Make sure the Thrift server is running on that server.
""" """
from ceilometer.openstack.common.fixture import moxstubout from mock import patch
from ceilometer.storage.impl_hbase import Connection from ceilometer.storage.impl_hbase import Connection
from ceilometer.storage.impl_hbase import MConnection from ceilometer.storage.impl_hbase import MConnection
from ceilometer.tests import db as tests_db from ceilometer.tests import db as tests_db
@ -36,10 +37,6 @@ class HBaseEngineTestBase(tests_db.TestBase):
class ConnectionTest(HBaseEngineTestBase): class ConnectionTest(HBaseEngineTestBase):
def setUp(self):
super(ConnectionTest, self).setUp()
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
def test_hbase_connection(self): def test_hbase_connection(self):
self.CONF.database.connection = self.database_connection self.CONF.database.connection = self.database_connection
conn = Connection(self.CONF) conn = Connection(self.CONF)
@ -52,8 +49,11 @@ class ConnectionTest(HBaseEngineTestBase):
def open(self): def open(self):
pass pass
def get_connection(conf):
return TestConn(conf['host'], conf['port'])
self.CONF.database.connection = 'hbase://test_hbase:9090' self.CONF.database.connection = 'hbase://test_hbase:9090'
self.stubs.Set(Connection, '_get_connection', with patch.object(Connection, '_get_connection',
lambda self, x: TestConn(x['host'], x['port'])) side_effect=get_connection):
conn = Connection(self.CONF) conn = Connection(self.CONF)
self.assertIsInstance(conn.conn, TestConn) self.assertIsInstance(conn.conn, TestConn)

View File

@ -18,18 +18,15 @@
"""Tests for ceilometer/storage/impl_log.py """Tests for ceilometer/storage/impl_log.py
""" """
from ceilometer.openstack.common.fixture import moxstubout import mock
from ceilometer.openstack.common import test from ceilometer.openstack.common import test
from ceilometer.storage import impl_log from ceilometer.storage import impl_log
class ConnectionTest(test.BaseTestCase): class ConnectionTest(test.BaseTestCase):
def setUp(self):
super(ConnectionTest, self).setUp()
self.mox = self.useFixture(moxstubout.MoxStubout()).mox
def test_get_connection(self): def test_get_connection(self):
conf = self.mox.CreateMockAnything() conf = mock.Mock()
log_stg = impl_log.LogStorage() log_stg = impl_log.LogStorage()
conn = log_stg.get_connection(conf) conn = log_stg.get_connection(conf)
conn.record_metering_data({'counter_name': 'test', conn.record_metering_data({'counter_name': 'test',

View File

@ -26,6 +26,7 @@
import copy import copy
import datetime import datetime
from mock import patch
from ceilometer.publisher import rpc from ceilometer.publisher import rpc
from ceilometer import sample from ceilometer import sample
@ -160,32 +161,30 @@ class CompatibilityTest(test_storage_scenarios.DBTestBase,
record = copy.copy(data) record = copy.copy(data)
self.db.meter.insert(record) self.db.meter.insert(record)
return
# Stubout with the old version DB schema, the one w/o 'counter_unit' # Stubout with the old version DB schema, the one w/o 'counter_unit'
self.stubs.Set(self.conn, with patch.object(self.conn, 'record_metering_data',
'record_metering_data', side_effect=old_record_metering_data):
old_record_metering_data) self.counters = []
self.counters = [] c = sample.Sample(
c = sample.Sample( 'volume.size',
'volume.size', 'gauge',
'gauge', 'GiB',
'GiB', 5,
5, 'user-id',
'user-id', 'project1',
'project1', 'resource-id',
'resource-id', timestamp=datetime.datetime(2012, 9, 25, 10, 30),
timestamp=datetime.datetime(2012, 9, 25, 10, 30), resource_metadata={'display_name': 'test-volume',
resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter',
'tag': 'self.counter', },
}, source='test',
source='test', )
) self.counters.append(c)
self.counters.append(c) msg = rpc.meter_message_from_counter(
msg = rpc.meter_message_from_counter( c,
c, secret='not-so-secret')
secret='not-so-secret') self.conn.record_metering_data(self.conn, msg)
self.conn.record_metering_data(self.conn, msg)
# Create the old format alarm with a dict instead of a # Create the old format alarm with a dict instead of a
# array for matching_metadata # array for matching_metadata

View File

@ -23,7 +23,6 @@ import datetime
import testscenarios import testscenarios
from ceilometer.openstack.common.fixture import moxstubout
from ceilometer.openstack.common import timeutils from ceilometer.openstack.common import timeutils
from ceilometer.publisher import rpc from ceilometer.publisher import rpc
from ceilometer import sample from ceilometer import sample
@ -60,7 +59,6 @@ class DBTestBase(tests_db.TestBase):
def setUp(self): def setUp(self):
super(DBTestBase, self).setUp() super(DBTestBase, self).setUp()
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
self.prepare_data() self.prepare_data()
def tearDown(self): def tearDown(self):