def test_setup_aliased_databases(self): from django.db.backends.dummy.base import DatabaseCreation runner_instance = runner.DiscoverRunner(verbosity=0) old_db_connections = db.connections old_destroy_test_db = DatabaseCreation.destroy_test_db old_create_test_db = DatabaseCreation.create_test_db try: destroyed_names = [] DatabaseCreation.destroy_test_db = lambda self, old_database_name, verbosity=1: destroyed_names.append( old_database_name) DatabaseCreation.create_test_db = lambda self, verbosity=1, autoclobber=False: self._get_test_db_name( ) db.connections = db.ConnectionHandler({ 'default': { 'ENGINE': 'django.db.backends.dummy', 'NAME': 'dbname', }, 'other': { 'ENGINE': 'django.db.backends.dummy', 'NAME': 'dbname', } }) old_config = runner_instance.setup_databases() runner_instance.teardown_databases(old_config) self.assertEqual(destroyed_names.count('dbname'), 1) finally: DatabaseCreation.create_test_db = old_create_test_db DatabaseCreation.destroy_test_db = old_destroy_test_db db.connections = old_db_connections
def test_transaction_support(self): """Ticket #16329: sqlite3 in-memory test databases""" old_db_connections = db.connections for option_key, option_value in ( ('NAME', ':memory:'), ('TEST', {'NAME': ':memory:'})): try: db.connections = db.ConnectionHandler({ 'default': { 'ENGINE': 'django.db.backends.sqlite3', option_key: option_value, }, 'other': { 'ENGINE': 'django.db.backends.sqlite3', option_key: option_value, }, }) other = db.connections['other'] runner.DiscoverRunner(verbosity=0).setup_databases() msg = "DATABASES setting '%s' option set to sqlite3's ':memory:' value shouldn't interfere with transaction support detection." % option_key # Transaction support should be properly initialized for the 'other' DB self.assertTrue(other.features.supports_transactions, msg) # And all the DBs should report that they support transactions self.assertTrue(connections_support_transactions(), msg) finally: db.connections = old_db_connections
def setUpModule(): if not django_loaded: # pragma: no cover raise unittest.SkipTest("Django not installed") django_test_utils.setup_test_environment() runner = django_test_runner.DiscoverRunner() runner_state = runner.setup_databases() test_state.update({ 'runner': runner, 'runner_state': runner_state, })
def setup_django(): """Provide a test database and django configuration""" from yawn.worker.models import Queue manager = runner.DiscoverRunner(verbosity=1, interactive=False) old_config = manager.setup_databases() # create the default queue outside the transaction Queue.get_default_queue() yield manager.teardown_databases(old_config)
def test_setup_databases(self): """ Test that setup_databases() doesn't fail with dummy database backend. """ runner_instance = runner.DiscoverRunner(verbosity=0) old_db_connections = db.connections try: db.connections = db.ConnectionHandler({}) old_config = runner_instance.setup_databases() runner_instance.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
def test_setup_aliased_default_database(self): """ Test that setup_datebases() doesn't fail when 'default' is aliased """ runner_instance = runner.DiscoverRunner(verbosity=0) old_db_connections = db.connections try: db.connections = db.ConnectionHandler({ 'default': { 'NAME': 'dummy' }, 'aliased': { 'NAME': 'dummy' } }) old_config = runner_instance.setup_databases() runner_instance.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
def setUp(self): self._old_db_connections = db.connections self._old_destroy_test_db = DatabaseCreation.destroy_test_db self._old_create_test_db = DatabaseCreation.create_test_db self.runner_instance = runner.DiscoverRunner(verbosity=0)