summaryrefslogtreecommitdiff
path: root/nova/tests/unit/test_fixtures.py
diff options
context:
space:
mode:
authorSean Dague <sean@dague.net>2014-12-09 11:46:28 -0500
committerSean Dague <sean@dague.net>2014-12-10 08:51:30 -0500
commitccac8cfef73b2a4f6e839d03edef2889e6a78cd5 (patch)
treecbdaa68bc5fa96c9fc26f3cfa093fd7f238150cf /nova/tests/unit/test_fixtures.py
parent666cccd3eb212ec82bb04101bfe710fb27a152c7 (diff)
downloadnova-ccac8cfef73b2a4f6e839d03edef2889e6a78cd5.tar.gz
simplify database fixture to the features we use
The Database fixture has existed for a long time, and has a large amount of vestigial code that is no longer usable as it's masked by other test setup. For instance, the conf fixture always sets the db connection string to in memory db. Simplify what the Database fixture is doing to just the inmemory schema caching and reconstruction. Also provide a test case demonstrating that this both sets up the db correctly, as well as resets it after we've made changes. Change-Id: Idc9b587c705c1c1ab4e1173ad1e8e244037284d7
Diffstat (limited to 'nova/tests/unit/test_fixtures.py')
-rw-r--r--nova/tests/unit/test_fixtures.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/nova/tests/unit/test_fixtures.py b/nova/tests/unit/test_fixtures.py
index bf1671f84e..82407ca07e 100644
--- a/nova/tests/unit/test_fixtures.py
+++ b/nova/tests/unit/test_fixtures.py
@@ -21,6 +21,7 @@ import fixtures as fx
from oslo.config import cfg
import testtools
+from nova.db.sqlalchemy import api as session
from nova.tests.unit import conf_fixture
from nova.tests import fixtures
@@ -145,3 +146,36 @@ class TestTimeout(testtools.TestCase):
self.assertEqual(timeout.test_timeout, 10)
timeout = fixtures.Timeout("10", 2)
self.assertEqual(timeout.test_timeout, 20)
+
+
+class TestDatabaseFixture(testtools.TestCase):
+ def test_fixture_reset(self):
+ # because this sets up reasonable db connection strings
+ self.useFixture(conf_fixture.ConfFixture())
+ self.useFixture(fixtures.Database())
+ engine = session.get_engine()
+ conn = engine.connect()
+ result = conn.execute("select * from instance_types")
+ rows = result.fetchall()
+ self.assertEqual(len(rows), 5, "Rows %s" % rows)
+
+ # insert a 6th instance type, column 5 below is an int id
+ # which has a constraint on it, so if new standard instance
+ # types are added you have to bump it.
+ conn.execute("insert into instance_types VALUES "
+ "(NULL, NULL, NULL, 't1.test', 6, 4096, 2, 0, NULL, '87'"
+ ", 1.0, 40, 0, 0, 1, 0)")
+ result = conn.execute("select * from instance_types")
+ rows = result.fetchall()
+ self.assertEqual(len(rows), 6, "Rows %s" % rows)
+
+ # reset by invoking the fixture again
+ #
+ # NOTE(sdague): it's important to reestablish the db
+ # connection because otherwise we have a reference to the old
+ # in mem db.
+ self.useFixture(fixtures.Database())
+ conn = engine.connect()
+ result = conn.execute("select * from instance_types")
+ rows = result.fetchall()
+ self.assertEqual(len(rows), 5, "Rows %s" % rows)