Replace mox with mock in tests.storage

Change-Id: I912c999567eba012eb1777f937d1a5785a720d54
This commit is contained in:
Victor Stinner 2013-11-15 19:26:22 +01:00
parent 4a638fab63
commit d0b710c9cc
5 changed files with 37 additions and 45 deletions

View File

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

View File

@ -24,7 +24,8 @@
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 MConnection
from ceilometer.tests import db as tests_db
@ -36,10 +37,6 @@ class HBaseEngineTestBase(tests_db.TestBase):
class ConnectionTest(HBaseEngineTestBase):
def setUp(self):
super(ConnectionTest, self).setUp()
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
def test_hbase_connection(self):
self.CONF.database.connection = self.database_connection
conn = Connection(self.CONF)
@ -52,8 +49,11 @@ class ConnectionTest(HBaseEngineTestBase):
def open(self):
pass
def get_connection(conf):
return TestConn(conf['host'], conf['port'])
self.CONF.database.connection = 'hbase://test_hbase:9090'
self.stubs.Set(Connection, '_get_connection',
lambda self, x: TestConn(x['host'], x['port']))
with patch.object(Connection, '_get_connection',
side_effect=get_connection):
conn = Connection(self.CONF)
self.assertIsInstance(conn.conn, TestConn)

View File

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

View File

@ -26,6 +26,7 @@
import copy
import datetime
from mock import patch
from ceilometer.publisher import rpc
from ceilometer import sample
@ -160,12 +161,10 @@ class CompatibilityTest(test_storage_scenarios.DBTestBase,
record = copy.copy(data)
self.db.meter.insert(record)
return
# Stubout with the old version DB schema, the one w/o 'counter_unit'
self.stubs.Set(self.conn,
'record_metering_data',
old_record_metering_data)
with patch.object(self.conn, 'record_metering_data',
side_effect=old_record_metering_data):
self.counters = []
c = sample.Sample(
'volume.size',

View File

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