Add db unit test framework

Change-Id: I5c14a4d49af4708b68ffceb08dac479481846f62
Signed-off-by: Zhijiang Hu <hu.zhijiang@zte.com.cn>
This commit is contained in:
Zhijiang Hu
2017-02-09 04:06:53 -05:00
parent f6494f45ad
commit 09e89e0517
2 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
# Copyright 2010-2011 OpenStack Foundation
# All Rights Reserved.
# Copyright 2013 IBM Corp.
#
# 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 database migrations. This test case reads the configuration
file /tests/test_migrations.conf for database connection settings
to use in the tests. For each connection found in the config file,
the test case runs a series of test cases to ensure that migrations work
properly both upgrading and downgrading, and that no data loss occurs
if possible.
"""
from __future__ import print_function
import os
from migrate.versioning import api as migration_api
from migrate.versioning.repository import Repository
from oslo_db.sqlalchemy import test_migrations
from daisy.db import migration
from daisy.db.sqlalchemy import migrate_repo
from daisy import i18n
_ = i18n._
class MigrationsMixin(test_migrations.WalkVersionsMixin):
@property
def INIT_VERSION(self):
return migration.INIT_VERSION
@property
def REPOSITORY(self):
migrate_file = migrate_repo.__file__
return Repository(os.path.abspath(os.path.dirname(migrate_file)))
@property
def migration_api(self):
return migration_api
@property
def migrate_engine(self):
return self.engine
def test_walk_versions(self):
# No more downgrades
self._walk_versions(False, False)

View File

@@ -15,6 +15,7 @@ mock>=1.0
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
requests>=2.2.0,!=2.4.0
testrepository>=0.0.18
testresources>=0.2.4 # Apache-2.0/BSD
testscenarios>=0.4 # Apache-2.0/BSD
testtools>=0.9.36,!=1.2.0
psutil>=1.1.1,<2.0.0