From 8e92106c259375f9751cd477c7af891296331a41 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sun, 6 Jan 2013 02:35:09 -0500 Subject: [PATCH] Rearrange db tests in prep for testr. The way discover does test discovery will find any classes that subclass the unittest base class. This means that db.base was getting picked up as a set of tests that need to be run, which is bogus, as it's intended to just be a base class. Split it up a little bit differently to make it work as intended when python test discovery is run outside of how nose things of things. Part of blueprint grizzly-testtools Change-Id: Iede92452d0c48224a1f80288c2bf2693224dc56f --- glance/tests/functional/db/base.py | 14 ++++++++----- glance/tests/functional/db/test_simple.py | 21 +++++++++++-------- glance/tests/functional/db/test_sqlalchemy.py | 21 +++++++++++-------- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/glance/tests/functional/db/base.py b/glance/tests/functional/db/base.py index 4aae4cb16e..369ce354d1 100644 --- a/glance/tests/functional/db/base.py +++ b/glance/tests/functional/db/base.py @@ -61,18 +61,16 @@ def build_image_fixture(**kwargs): class TestDriver(base.IsolatedUnitTest): + def setUp(self): + super(TestDriver, self).setUp() self.adm_context = context.RequestContext(is_admin=True) self.context = context.RequestContext(is_admin=False) self.db_api = db_tests.get_db(self.config) db_tests.reset_db(self.db_api) self.fixtures = self.build_image_fixtures() self.create_images(self.fixtures) - super(TestDriver, self).setUp() - - def tearDown(self): - timeutils.clear_time_override() - super(TestDriver, self).tearDown() + self.addCleanup(timeutils.clear_time_override) def build_image_fixtures(self): dt1 = timeutils.utcnow() @@ -103,6 +101,9 @@ class TestDriver(base.IsolatedUnitTest): for fixture in images: self.db_api.image_create(self.adm_context, fixture) + +class DriverTests(object): + def test_image_create_requires_status(self): fixture = {'name': 'mark', 'size': 12} self.assertRaises(exception.Invalid, @@ -630,6 +631,9 @@ class TestVisibility(base.IsolatedUnitTest): for fixture in images: self.db_api.image_create(self.admin_context, fixture) + +class VisibilityTests(object): + def test_unknown_admin_sees_all(self): images = self.db_api.image_get_all(self.admin_none_context) self.assertEquals(len(images), 8) diff --git a/glance/tests/functional/db/test_simple.py b/glance/tests/functional/db/test_simple.py index 0e9c86f0b0..6b6f899c55 100644 --- a/glance/tests/functional/db/test_simple.py +++ b/glance/tests/functional/db/test_simple.py @@ -16,6 +16,7 @@ import glance.db.simple.api import glance.tests.functional.db as db_tests +from glance.tests.functional.db import base def get_db(config): @@ -26,15 +27,17 @@ def reset_db(db_api): db_api.reset() -def setUpModule(): - """Stub in get_db and reset_db for testing the simple db api.""" - db_tests.load(get_db, reset_db) +class TestSimpleDriver(base.TestDriver, base.DriverTests): + + def setUp(self): + db_tests.load(get_db, reset_db) + super(TestSimpleDriver, self).setUp() + self.addCleanup(db_tests.reset) -def tearDownModule(): - """Reset get_db and reset_db for cleanliness.""" - db_tests.reset() +class TestSimpleVisibility(base.TestVisibility, base.VisibilityTests): - -#NOTE(markwash): Pull in all the base test cases -from glance.tests.functional.db.base import * + def setUp(self): + db_tests.load(get_db, reset_db) + super(TestSimpleVisibility, self).setUp() + self.addCleanup(db_tests.reset) diff --git a/glance/tests/functional/db/test_sqlalchemy.py b/glance/tests/functional/db/test_sqlalchemy.py index 51b8211081..abc689cb26 100644 --- a/glance/tests/functional/db/test_sqlalchemy.py +++ b/glance/tests/functional/db/test_sqlalchemy.py @@ -17,6 +17,7 @@ import glance.db.sqlalchemy.api from glance.db.sqlalchemy import models as db_models import glance.tests.functional.db as db_tests +from glance.tests.functional.db import base def get_db(config): @@ -31,15 +32,17 @@ def reset_db(db_api): db_models.register_models(db_api._ENGINE) -def setUpModule(): - """Stub in get_db and reset_db for testing the sqlalchemy db api.""" - db_tests.load(get_db, reset_db) +class TestSqlAlchemyDriver(base.TestDriver, base.DriverTests): + + def setUp(self): + db_tests.load(get_db, reset_db) + super(TestSqlAlchemyDriver, self).setUp() + self.addCleanup(db_tests.reset) -def tearDownModule(): - """Reset get_db and reset_db for cleanliness.""" - db_tests.reset() +class TestSqlAlchemyVisibility(base.TestVisibility, base.VisibilityTests): - -#NOTE(markwash): Pull in all the base test cases -from glance.tests.functional.db.base import * + def setUp(self): + db_tests.load(get_db, reset_db) + super(TestSqlAlchemyVisibility, self).setUp() + self.addCleanup(db_tests.reset)