Add DB unit test framework and db_api.ticket_create() unit test
Change-Id: I78139951733ef5c95d8d67399b597ecd2279edab
This commit is contained in:
parent
7137e71b3e
commit
9c87af0bfc
|
@ -1,20 +0,0 @@
|
|||
# Copyright 2015 99Cloud
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslotest import base
|
||||
|
||||
|
||||
class BaseTestCase(base.BaseTestCase):
|
||||
def test_one(self):
|
||||
pass
|
|
@ -0,0 +1,90 @@
|
|||
# Copyright 2010-2011 OpenStack Foundation
|
||||
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslotest import base
|
||||
import pecan
|
||||
import testscenarios
|
||||
|
||||
from evoque.common import context as evoque_context
|
||||
from evoque.tests.unit import fixture
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
log.register_options(CONF)
|
||||
CONF.set_override('use_stderr', False)
|
||||
|
||||
|
||||
class BaseTestCase(testscenarios.WithScenarios, base.BaseTestCase):
|
||||
"""Test base class."""
|
||||
|
||||
def setUp(self):
|
||||
super(BaseTestCase, self).setUp()
|
||||
self.addCleanup(cfg.CONF.reset)
|
||||
|
||||
|
||||
class TestCase(base.BaseTestCase):
|
||||
"""Test case base class for all unit tests."""
|
||||
|
||||
def setUp(self):
|
||||
super(TestCase, self).setUp()
|
||||
token_info = {
|
||||
'token': {
|
||||
'project': {
|
||||
'id': 'fake_project'
|
||||
},
|
||||
'user': {
|
||||
'id': 'fake_user'
|
||||
}
|
||||
}
|
||||
}
|
||||
self.context = evoque_context.RequestContext(
|
||||
auth_token_info=token_info,
|
||||
project_id='fake_project',
|
||||
user_id='fake_user')
|
||||
|
||||
def make_context(*args, **kwargs):
|
||||
# If context hasn't been constructed with token_info
|
||||
if not kwargs.get('auth_token_info'):
|
||||
kwargs['auth_token_info'] = copy.deepcopy(token_info)
|
||||
if not kwargs.get('project_id'):
|
||||
kwargs['project_id'] = 'fake_project'
|
||||
if not kwargs.get('user_id'):
|
||||
kwargs['user_id'] = 'fake_user'
|
||||
|
||||
context = evoque_context.RequestContext(*args, **kwargs)
|
||||
return evoque_context.RequestContext.from_dict(context.to_dict())
|
||||
|
||||
p = mock.patch.object(evoque_context, 'make_context',
|
||||
side_effect=make_context)
|
||||
self.mock_make_context = p.start()
|
||||
self.addCleanup(p.stop)
|
||||
|
||||
self.useFixture(fixture.ConfigFixture())
|
||||
|
||||
def reset_pecan():
|
||||
pecan.set_config({}, overwrite=True)
|
||||
|
||||
self.addCleanup(reset_pecan)
|
||||
|
||||
def config(self, **kw):
|
||||
"""Override config options for a test."""
|
||||
group = kw.pop('group', None)
|
||||
for k, v in kw.items():
|
||||
CONF.set_override(k, v, group)
|
|
@ -0,0 +1,49 @@
|
|||
# Copyright (c) 2012 NTT DOCOMO, INC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Evoque DB test base class."""
|
||||
|
||||
import fixtures
|
||||
from oslo_config import cfg
|
||||
|
||||
from evoque.db import api as db_api
|
||||
from evoque.tests.unit import base
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
_DB_CACHE = None
|
||||
|
||||
|
||||
class Database(fixtures.Fixture):
|
||||
|
||||
def __init__(self, db_api):
|
||||
self.engine = db_api.get_engine()
|
||||
|
||||
def _setUp(self):
|
||||
db_api.db_sync(self.engine)
|
||||
self.engine.connect()
|
||||
|
||||
|
||||
class DBTestCase(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(DBTestCase, self).setUp()
|
||||
|
||||
self.db_api = db_api
|
||||
|
||||
global _DB_CACHE
|
||||
if not _DB_CACHE:
|
||||
_DB_CACHE = Database(db_api)
|
||||
self.useFixture(_DB_CACHE)
|
|
@ -0,0 +1,25 @@
|
|||
# Copyright 2015 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Tests for manipulating Bays via the DB API"""
|
||||
|
||||
from evoque.tests.unit.db import base
|
||||
from evoque.tests.unit.db import utils
|
||||
|
||||
|
||||
class DBTicketTestCase(base.DBTestCase):
|
||||
|
||||
def test_ticket_create(self):
|
||||
utils.ticket_create(self.context)
|
|
@ -0,0 +1,23 @@
|
|||
# Copyright 2015 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Evoque test utilities."""
|
||||
|
||||
from evoque.db import api as db_api
|
||||
|
||||
|
||||
def ticket_create(context):
|
||||
values = {"name": "test-ticket"}
|
||||
db_api.ticket_create(context, values)
|
|
@ -0,0 +1,33 @@
|
|||
# Copyright 2010 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import fixtures
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.import_opt('connection', 'oslo_db.options', group='database')
|
||||
CONF.import_opt('sqlite_synchronous', 'oslo_db.options', group='database')
|
||||
|
||||
|
||||
class ConfigFixture(fixtures.Fixture):
|
||||
"""Fixture to manage global conf settings."""
|
||||
|
||||
def _setUp(self):
|
||||
log.register_options(cfg.CONF)
|
||||
CONF.set_default('connection', "sqlite://", group='database')
|
||||
CONF.set_default('sqlite_synchronous', False, group='database')
|
||||
self.addCleanup(CONF.reset)
|
Loading…
Reference in New Issue