From 09e89e0517ac101d547e7bc3cf48be2615c6418d Mon Sep 17 00:00:00 2001 From: Zhijiang Hu Date: Thu, 9 Feb 2017 04:06:53 -0500 Subject: [PATCH] Add db unit test framework Change-Id: I5c14a4d49af4708b68ffceb08dac479481846f62 Signed-off-by: Zhijiang Hu --- code/daisy/daisy/tests/test_migrations.py | 62 +++++++++++++++++++++++ code/daisy/test-requirements.txt | 1 + 2 files changed, 63 insertions(+) create mode 100644 code/daisy/daisy/tests/test_migrations.py diff --git a/code/daisy/daisy/tests/test_migrations.py b/code/daisy/daisy/tests/test_migrations.py new file mode 100644 index 00000000..b6df997e --- /dev/null +++ b/code/daisy/daisy/tests/test_migrations.py @@ -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) diff --git a/code/daisy/test-requirements.txt b/code/daisy/test-requirements.txt index 9fa6b294..cf4051cd 100755 --- a/code/daisy/test-requirements.txt +++ b/code/daisy/test-requirements.txt @@ -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