From 96301d21bb2ec7c5e06e3cea54fa2cdcd25a464d Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 4 Jan 2013 13:55:20 +0100 Subject: [PATCH] [1.5.x] Fixed #19192 -- Allowed running tests with dummy db backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks Simon Charette for the initial patch, and Jan Bednařík for his work on the ticket. Backport of b740da3504 from master. --- AUTHORS | 1 + django/db/backends/dummy/base.py | 6 +++++- tests/regressiontests/test_runner/tests.py | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index a4bd387bd25..070ec7003a7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -125,6 +125,7 @@ answer newbie questions, and generally made Django that much better: Chris Chamberlin Amit Chakradeo ChaosKCW + Simon Charette Kowito Charoenratchatabhan Sengtha Chay ivan.chelubeev@gmail.com diff --git a/django/db/backends/dummy/base.py b/django/db/backends/dummy/base.py index 12a940d3a22..b648aae9c9c 100644 --- a/django/db/backends/dummy/base.py +++ b/django/db/backends/dummy/base.py @@ -31,6 +31,10 @@ class DatabaseOperations(BaseDatabaseOperations): class DatabaseClient(BaseDatabaseClient): runshell = complain +class DatabaseCreation(BaseDatabaseCreation): + create_test_db = ignore + destroy_test_db = ignore + class DatabaseIntrospection(BaseDatabaseIntrospection): get_table_list = complain get_table_description = complain @@ -64,6 +68,6 @@ class DatabaseWrapper(BaseDatabaseWrapper): self.features = BaseDatabaseFeatures(self) self.ops = DatabaseOperations(self) self.client = DatabaseClient(self) - self.creation = BaseDatabaseCreation(self) + self.creation = DatabaseCreation(self) self.introspection = DatabaseIntrospection(self) self.validation = BaseDatabaseValidation(self) diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py index c723f162a42..5ef4d5537de 100644 --- a/tests/regressiontests/test_runner/tests.py +++ b/tests/regressiontests/test_runner/tests.py @@ -261,6 +261,24 @@ class Sqlite3InMemoryTestDbs(unittest.TestCase): db.connections = old_db_connections +class DummyBackendTest(unittest.TestCase): + def test_setup_databases(self): + """ + Test that setup_databases() doesn't fail with dummy database backend. + """ + runner = DjangoTestSuiteRunner(verbosity=0) + old_db_connections = db.connections + try: + db.connections = db.ConnectionHandler({}) + old_config = runner.setup_databases() + runner.teardown_databases(old_config) + except Exception as e: + self.fail("setup_databases/teardown_databases unexpectedly raised " + "an error: %s" % e) + finally: + db.connections = old_db_connections + + class AutoIncrementResetTest(TransactionTestCase): """ Here we test creating the same model two times in different test methods,