Centralized backends tests scenarios in one place

This change removes duplication of backends tests scenarios
configuraion.

Related to blueprint db-tests-with-scenarios

Change-Id: If13dddb6fb6e7f05c512f0de9adea9a435b8db8e
This commit is contained in:
Alexei Kornienko 2013-07-24 12:05:41 +03:00
parent b015ae9535
commit 2f69200e98
22 changed files with 121 additions and 217 deletions

View File

@ -48,6 +48,10 @@ class TestBase(db_test_base.TestBase):
enable_acl=False,
attach_storage=False,
sources_file=sources_file)
# this is needed to pass over unhandled exceptions
self.app.debug = True
self.app.register_blueprint(v1_blueprint.blueprint)
self.test_app = self.app.test_client()

View File

@ -19,11 +19,13 @@
"""Test base classes.
"""
import fixtures
import functools
import mox
from oslo.config import cfg
import os.path
import stubout
import testtools
from testtools import testcase
cfg.CONF.import_opt('pipeline_cfg_file', 'ceilometer.pipeline')
@ -67,3 +69,27 @@ class TestCase(testtools.TestCase):
self.mox.VerifyAll()
cfg.CONF.reset()
super(TestCase, self).tearDown()
def _skip_decorator(func):
@functools.wraps(func)
def skip_if_not_implemented(*args, **kwargs):
try:
return func(*args, **kwargs)
except NotImplementedError as e:
raise testcase.TestSkipped(str(e))
except Exception as e:
if 'not implemented' in str(e):
raise testcase.TestSkipped(str(e))
raise
return skip_if_not_implemented
class SkipNotImplementedMeta(type):
def __new__(cls, name, bases, local):
for attr in local:
value = local[attr]
if callable(value) and (
attr.startswith('test_') or attr == 'setUp'):
local[attr] = _skip_decorator(value)
return type.__new__(cls, name, bases, local)

View File

@ -35,3 +35,13 @@ class TestBase(test_base.TestCase):
self.conn.upgrade()
self.conn.clear()
self.conn.upgrade()
class MixinTestsWithBackendScenarios(object):
__metaclass__ = test_base.SkipNotImplementedMeta
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]

View File

@ -25,19 +25,15 @@ import testscenarios
from ceilometer.openstack.common import timeutils
from ceilometer.storage import models
from ceilometer.tests import api as tests_api
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
LOG = logging.getLogger(__name__)
class TestComputeDurationByResource(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestComputeDurationByResource(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestComputeDurationByResource, self).setUp()

View File

@ -28,17 +28,13 @@ from ceilometer.publisher import rpc
from ceilometer import counter
from ceilometer.tests import api as tests_api
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
class TestListEvents(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListEvents(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestListEvents, self).setUp()
@ -183,13 +179,8 @@ class TestListEvents(tests_api.TestBase):
self.assertTrue("text/html" in rv.content_type)
class TestListEventsMetaquery(TestListEvents):
scenarios = [
#('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListEventsMetaquery(TestListEvents,
tests_db.MixinTestsWithBackendScenarios):
def test_metaquery1(self):
q = '/sources/source1/meters/instance'

View File

@ -29,32 +29,23 @@ from ceilometer.publisher import rpc
from ceilometer import counter
from ceilometer.tests import api as tests_api
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
LOG = logging.getLogger(__name__)
class TestListEmptyMeters(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListEmptyMeters(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def test_empty(self):
data = self.get('/meters')
self.assertEquals({'meters': []}, data)
class TestListMeters(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListMeters(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestListMeters, self).setUp()
@ -223,13 +214,8 @@ class TestListMeters(tests_api.TestBase):
self.assertEquals(data['meters'], [])
class TestListMetersMetaquery(TestListMeters):
scenarios = [
#('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListMetersMetaquery(TestListMeters,
tests_db.MixinTestsWithBackendScenarios):
def test_metaquery1(self):
data = self.get('/meters?metadata.tag=self.counter')

View File

@ -29,32 +29,23 @@ from ceilometer.publisher import rpc
from ceilometer import counter
from ceilometer.tests import api as tests_api
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
LOG = logging.getLogger(__name__)
class TestListEmptyProjects(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListEmptyProjects(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def test_empty(self):
data = self.get('/projects')
self.assertEquals({'projects': []}, data)
class TestListProjects(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListProjects(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestListProjects, self).setUp()

View File

@ -29,32 +29,23 @@ from ceilometer.publisher import rpc
from ceilometer import counter
from ceilometer.tests import api as tests_api
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
LOG = logging.getLogger(__name__)
class TestListEmptyResources(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListEmptyResources(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def test_empty(self):
data = self.get('/resources')
self.assertEquals({'resources': []}, data)
class TestListResourcesBase(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListResourcesBase(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestListResourcesBase, self).setUp()
@ -275,13 +266,8 @@ class TestListResources(TestListResourcesBase):
self.assertEquals(data['resources'], [])
class TestListResourcesMetaquery(TestListResourcesBase):
scenarios = [
#('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListResourcesMetaquery(TestListResourcesBase,
tests_db.MixinTestsWithBackendScenarios):
def test_metaquery1(self):
q = '/sources/test_list_resources/resources'

View File

@ -20,17 +20,13 @@
import testscenarios
from ceilometer.tests import api as tests_api
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
class TestListSource(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListSource(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def test_source(self):
ydata = self.get('/sources/test_source')

View File

@ -29,32 +29,23 @@ from ceilometer.publisher import rpc
from ceilometer import counter
from ceilometer.tests import api as tests_api
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
LOG = logging.getLogger(__name__)
class TestListEmptyUsers(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListEmptyUsers(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def test_empty(self):
data = self.get('/users')
self.assertEquals({'users': []}, data)
class TestListUsers(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListUsers(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestListUsers, self).setUp()

View File

@ -28,17 +28,13 @@ from ceilometer.publisher import rpc
from ceilometer import counter
from ceilometer.tests import api as tests_api
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
class TestMaxProjectVolume(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestMaxProjectVolume(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestMaxProjectVolume, self).setUp()

View File

@ -27,17 +27,13 @@ from ceilometer.publisher import rpc
from ceilometer import counter
from ceilometer.tests import api as tests_api
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
class TestMaxResourceVolume(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestMaxResourceVolume(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestMaxResourceVolume, self).setUp()

View File

@ -28,17 +28,13 @@ from ceilometer.publisher import rpc
from ceilometer import counter
from ceilometer.tests import api as tests_api
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
class TestSumProjectVolume(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestSumProjectVolume(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestSumProjectVolume, self).setUp()

View File

@ -28,17 +28,13 @@ from ceilometer.publisher import rpc
from ceilometer import counter
from ceilometer.tests import api as tests_api
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
class TestSumResourceVolume(tests_api.TestBase):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestSumResourceVolume(tests_api.TestBase,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestSumResourceVolume, self).setUp()

View File

@ -25,6 +25,7 @@ from oslo.config import cfg
from ceilometer import counter
from ceilometer.api import acl
from ceilometer.publisher import rpc
from ceilometer.tests import db as tests_db
from .base import FunctionalTest
@ -73,13 +74,8 @@ class FakeMemcache(object):
self.set_key = key
class TestAPIACL(FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestAPIACL(FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestAPIACL, self).setUp()

View File

@ -26,32 +26,23 @@ import testscenarios
from .base import FunctionalTest
from ceilometer.storage.models import Alarm
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
LOG = logging.getLogger(__name__)
class TestListEmptyAlarms(FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
#('hbase', dict(database_connection='hbase://__test__')),
]
class TestListEmptyAlarms(FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
def test_empty(self):
data = self.get_json('/alarms')
self.assertEquals([], data)
class TestAlarms(FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
#('hbase', dict(database_connection='hbase://__test__')),
]
class TestAlarms(FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestAlarms, self).setUp()

View File

@ -24,6 +24,7 @@ import testscenarios
from ceilometer.openstack.common import timeutils
from ceilometer.storage import models
from ceilometer.tests import db as tests_db
from .base import FunctionalTest
load_tests = testscenarios.load_tests_apply_scenarios
@ -31,13 +32,8 @@ load_tests = testscenarios.load_tests_apply_scenarios
LOG = logging.getLogger(__name__)
class TestComputeDurationByResource(FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestComputeDurationByResource(FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestComputeDurationByResource, self).setUp()

View File

@ -27,6 +27,7 @@ from oslo.config import cfg
from ceilometer.publisher import rpc
from ceilometer import counter
from ceilometer.tests import db as tests_db
from .base import FunctionalTest
@ -35,13 +36,8 @@ load_tests = testscenarios.load_tests_apply_scenarios
LOG = logging.getLogger(__name__)
class TestListEvents(FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListEvents(FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestListEvents, self).setUp()

View File

@ -26,6 +26,7 @@ from oslo.config import cfg
from ceilometer.publisher import rpc
from ceilometer import counter
from ceilometer.tests import db as tests_db
from .base import FunctionalTest
@ -34,26 +35,16 @@ load_tests = testscenarios.load_tests_apply_scenarios
LOG = logging.getLogger(__name__)
class TestListEmptyMeters(FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListEmptyMeters(FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
def test_empty(self):
data = self.get_json('/meters')
self.assertEquals([], data)
class TestListMeters(FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListMeters(FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
def setUp(self):
super(TestListMeters, self).setUp()

View File

@ -26,6 +26,7 @@ from oslo.config import cfg
from ceilometer.publisher import rpc
from ceilometer import counter
from ceilometer.tests import db as tests_db
from .base import FunctionalTest
@ -34,13 +35,8 @@ load_tests = testscenarios.load_tests_apply_scenarios
LOG = logging.getLogger(__name__)
class TestListResources(FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestListResources(FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
SOURCE_DATA = {'test_list_resources': {}}

View File

@ -25,6 +25,7 @@ import testscenarios
from ceilometer.openstack.common import rpc
from ceilometer.openstack.common import timeutils
from ceilometer.tests import db as tests_db
from .base import FunctionalTest
@ -33,13 +34,8 @@ load_tests = testscenarios.load_tests_apply_scenarios
LOG = logging.getLogger(__name__)
class TestPostSamples(FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestPostSamples(FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
def faux_cast(self, context, topic, msg):
self.published.append((topic, msg))

View File

@ -25,17 +25,13 @@ from oslo.config import cfg
from . import base
from ceilometer import counter
from ceilometer.publisher import rpc
from ceilometer.tests import db as tests_db
load_tests = testscenarios.load_tests_apply_scenarios
class TestMaxProjectVolume(base.FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestMaxProjectVolume(base.FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
PATH = '/meters/volume.size/statistics'
@ -135,13 +131,8 @@ class TestMaxProjectVolume(base.FunctionalTest):
self.assertEqual(data[0]['count'], 1)
class TestMaxResourceVolume(base.FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestMaxResourceVolume(base.FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
PATH = '/meters/volume.size/statistics'
@ -257,13 +248,8 @@ class TestMaxResourceVolume(base.FunctionalTest):
self.assertEqual(data[0]['count'], 1)
class TestSumProjectVolume(base.FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestSumProjectVolume(base.FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
PATH = '/meters/volume.size/statistics'
@ -365,13 +351,8 @@ class TestSumProjectVolume(base.FunctionalTest):
self.assertEqual(data[0]['count'], 1)
class TestSumResourceVolume(base.FunctionalTest):
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection='mongodb://__test__')),
('hbase', dict(database_connection='hbase://__test__')),
]
class TestSumResourceVolume(base.FunctionalTest,
tests_db.MixinTestsWithBackendScenarios):
PATH = '/meters/volume.size/statistics'