From 67d936902d1ba3b6491ecb5e2cdadde05b362e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victoria=20Mart=C3=ADnez=20de=20la=20Cruz?= Date: Mon, 9 Jun 2014 19:27:38 -0300 Subject: [PATCH] Refactor auxiliary methods for MongoDB unit tests This patchset DRYes the implementation of auxiliary functions in MongoDB unit tests. Change-Id: Ie6a3bfc0d20d8d30bd484a9fec2063e1c191c7c4 Closes-Bug: #1257391 --- .../unit/queues/storage/test_impl_mongodb.py | 39 +++++-------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/tests/unit/queues/storage/test_impl_mongodb.py b/tests/unit/queues/storage/test_impl_mongodb.py index 1f6b342e3..72c70212e 100644 --- a/tests/unit/queues/storage/test_impl_mongodb.py +++ b/tests/unit/queues/storage/test_impl_mongodb.py @@ -35,12 +35,17 @@ from marconi import tests as testing from marconi.tests.queues.storage import base -def _cleanup_databases(controller): - databases = (controller.driver.message_databases + - [controller.driver.queues_database]) +class MongodbDBSetup(testing.TestBase): + def _purge_databases(self): + databases = (self.driver.message_databases + + [self.driver.queues_database]) - for db in databases: - controller.driver.connection.drop_database(db) + for db in databases: + self.driver.connection.drop_database(db) + + def _prepare_conf(self): + self.config(options.MONGODB_GROUP, + database=uuid.uuid4().hex) class MongodbUtilsTest(testing.TestBase): @@ -133,9 +138,6 @@ class MongodbDriverTest(testing.TestBase): config_file = 'wsgi_mongodb.conf' - def _purge_databases(self): - _cleanup_databases(self) - def test_db_instance(self): cache = oslo_cache.get_cache() driver = mongodb.DataDriver(self.conf, cache) @@ -155,13 +157,6 @@ class MongodbQueueTests(base.QueueControllerTest): config_file = 'wsgi_mongodb.conf' controller_class = controllers.QueueController - def _purge_databases(self): - _cleanup_databases(self) - - def _prepare_conf(self): - self.config(options.MONGODB_GROUP, - database=uuid.uuid4().hex) - def test_indexes(self): collection = self.controller._collection indexes = collection.index_information() @@ -198,13 +193,6 @@ class MongodbMessageTests(base.MessageControllerTest): # NOTE(kgriffs): MongoDB's TTL scavenger only runs once a minute gc_interval = 60 - def _purge_databases(self): - _cleanup_databases(self) - - def _prepare_conf(self): - self.config(options.MONGODB_GROUP, - database=uuid.uuid4().hex) - def test_indexes(self): for collection in self.controller._collections: indexes = collection.index_information() @@ -349,13 +337,6 @@ class MongodbClaimTests(base.ClaimControllerTest): config_file = 'wsgi_mongodb.conf' controller_class = controllers.ClaimController - def _purge_databases(self): - _cleanup_databases(self) - - def _prepare_conf(self): - self.config(options.MONGODB_GROUP, - database=uuid.uuid4().hex) - def test_claim_doesnt_exist(self): """Verifies that operations fail on expired/missing claims.