2009-12-13 17:08:36 +00:00
|
|
|
"""
|
|
|
|
Tests for django test runner
|
|
|
|
"""
|
2013-07-29 17:19:04 +00:00
|
|
|
from __future__ import unicode_literals
|
2011-10-13 21:34:56 +00:00
|
|
|
|
2013-07-01 12:22:27 +00:00
|
|
|
import unittest
|
2010-10-11 12:55:17 +00:00
|
|
|
|
2015-01-28 12:35:27 +00:00
|
|
|
from admin_scripts.tests import AdminScriptTestCase
|
|
|
|
|
2014-09-15 15:17:12 +00:00
|
|
|
from django import db
|
2014-10-24 12:53:58 +00:00
|
|
|
from django.conf import settings
|
2010-12-05 00:44:34 +00:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
2011-06-10 08:26:05 +00:00
|
|
|
from django.core.management import call_command
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.test import (
|
2015-03-12 16:17:15 +00:00
|
|
|
TestCase, TransactionTestCase, mock, skipUnlessDBFeature, testcases,
|
2015-01-28 12:35:27 +00:00
|
|
|
)
|
2014-11-15 19:03:31 +00:00
|
|
|
from django.test.runner import DiscoverRunner, dependency_ordered
|
2012-03-13 17:52:48 +00:00
|
|
|
from django.test.testcases import connections_support_transactions
|
2014-03-08 10:13:45 +00:00
|
|
|
from django.utils import six
|
2015-02-15 00:47:07 +00:00
|
|
|
from django.utils.encoding import force_text
|
2011-06-12 12:34:10 +00:00
|
|
|
|
2012-04-24 16:47:31 +00:00
|
|
|
from .models import Person
|
2009-12-22 06:00:57 +00:00
|
|
|
|
2011-04-02 13:26:39 +00:00
|
|
|
|
2010-12-05 00:44:34 +00:00
|
|
|
class DependencyOrderingTests(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_simple_dependencies(self):
|
|
|
|
raw = [
|
2011-02-02 14:02:14 +00:00
|
|
|
('s1', ('s1_db', ['alpha'])),
|
|
|
|
('s2', ('s2_db', ['bravo'])),
|
|
|
|
('s3', ('s3_db', ['charlie'])),
|
2010-12-05 00:44:34 +00:00
|
|
|
]
|
|
|
|
dependencies = {
|
|
|
|
'alpha': ['charlie'],
|
|
|
|
'bravo': ['charlie'],
|
|
|
|
}
|
|
|
|
|
2014-11-15 19:03:31 +00:00
|
|
|
ordered = dependency_ordered(raw, dependencies=dependencies)
|
2013-10-26 19:15:03 +00:00
|
|
|
ordered_sigs = [sig for sig, value in ordered]
|
2010-12-05 00:44:34 +00:00
|
|
|
|
|
|
|
self.assertIn('s1', ordered_sigs)
|
|
|
|
self.assertIn('s2', ordered_sigs)
|
|
|
|
self.assertIn('s3', ordered_sigs)
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s1'))
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s2'))
|
|
|
|
|
|
|
|
def test_chained_dependencies(self):
|
|
|
|
raw = [
|
2011-02-02 14:02:14 +00:00
|
|
|
('s1', ('s1_db', ['alpha'])),
|
|
|
|
('s2', ('s2_db', ['bravo'])),
|
|
|
|
('s3', ('s3_db', ['charlie'])),
|
2010-12-05 00:44:34 +00:00
|
|
|
]
|
|
|
|
dependencies = {
|
|
|
|
'alpha': ['bravo'],
|
|
|
|
'bravo': ['charlie'],
|
|
|
|
}
|
|
|
|
|
2014-11-15 19:03:31 +00:00
|
|
|
ordered = dependency_ordered(raw, dependencies=dependencies)
|
2013-10-26 19:15:03 +00:00
|
|
|
ordered_sigs = [sig for sig, value in ordered]
|
2010-12-05 00:44:34 +00:00
|
|
|
|
|
|
|
self.assertIn('s1', ordered_sigs)
|
|
|
|
self.assertIn('s2', ordered_sigs)
|
|
|
|
self.assertIn('s3', ordered_sigs)
|
|
|
|
|
|
|
|
# Explicit dependencies
|
|
|
|
self.assertLess(ordered_sigs.index('s2'), ordered_sigs.index('s1'))
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s2'))
|
|
|
|
|
|
|
|
# Implied dependencies
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s1'))
|
|
|
|
|
|
|
|
def test_multiple_dependencies(self):
|
|
|
|
raw = [
|
2011-02-02 14:02:14 +00:00
|
|
|
('s1', ('s1_db', ['alpha'])),
|
|
|
|
('s2', ('s2_db', ['bravo'])),
|
|
|
|
('s3', ('s3_db', ['charlie'])),
|
|
|
|
('s4', ('s4_db', ['delta'])),
|
2010-12-05 00:44:34 +00:00
|
|
|
]
|
|
|
|
dependencies = {
|
2013-10-26 19:15:03 +00:00
|
|
|
'alpha': ['bravo', 'delta'],
|
2010-12-05 00:44:34 +00:00
|
|
|
'bravo': ['charlie'],
|
|
|
|
'delta': ['charlie'],
|
|
|
|
}
|
|
|
|
|
2014-11-15 19:03:31 +00:00
|
|
|
ordered = dependency_ordered(raw, dependencies=dependencies)
|
2013-10-26 19:15:03 +00:00
|
|
|
ordered_sigs = [sig for sig, aliases in ordered]
|
2010-12-05 00:44:34 +00:00
|
|
|
|
|
|
|
self.assertIn('s1', ordered_sigs)
|
|
|
|
self.assertIn('s2', ordered_sigs)
|
|
|
|
self.assertIn('s3', ordered_sigs)
|
|
|
|
self.assertIn('s4', ordered_sigs)
|
|
|
|
|
|
|
|
# Explicit dependencies
|
|
|
|
self.assertLess(ordered_sigs.index('s2'), ordered_sigs.index('s1'))
|
|
|
|
self.assertLess(ordered_sigs.index('s4'), ordered_sigs.index('s1'))
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s2'))
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s4'))
|
|
|
|
|
|
|
|
# Implicit dependencies
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s1'))
|
|
|
|
|
|
|
|
def test_circular_dependencies(self):
|
|
|
|
raw = [
|
2011-02-02 14:02:14 +00:00
|
|
|
('s1', ('s1_db', ['alpha'])),
|
|
|
|
('s2', ('s2_db', ['bravo'])),
|
2010-12-05 00:44:34 +00:00
|
|
|
]
|
|
|
|
dependencies = {
|
|
|
|
'bravo': ['alpha'],
|
|
|
|
'alpha': ['bravo'],
|
|
|
|
}
|
|
|
|
|
2014-11-15 19:03:31 +00:00
|
|
|
self.assertRaises(ImproperlyConfigured, dependency_ordered, raw, dependencies=dependencies)
|
2010-12-05 00:44:34 +00:00
|
|
|
|
2012-04-24 16:05:47 +00:00
|
|
|
def test_own_alias_dependency(self):
|
|
|
|
raw = [
|
|
|
|
('s1', ('s1_db', ['alpha', 'bravo']))
|
|
|
|
]
|
|
|
|
dependencies = {
|
|
|
|
'alpha': ['bravo']
|
|
|
|
}
|
|
|
|
|
|
|
|
with self.assertRaises(ImproperlyConfigured):
|
2014-11-15 19:03:31 +00:00
|
|
|
dependency_ordered(raw, dependencies=dependencies)
|
2012-04-24 16:05:47 +00:00
|
|
|
|
|
|
|
# reordering aliases shouldn't matter
|
|
|
|
raw = [
|
|
|
|
('s1', ('s1_db', ['bravo', 'alpha']))
|
|
|
|
]
|
|
|
|
|
|
|
|
with self.assertRaises(ImproperlyConfigured):
|
2014-11-15 19:03:31 +00:00
|
|
|
dependency_ordered(raw, dependencies=dependencies)
|
2012-04-24 16:05:47 +00:00
|
|
|
|
2011-06-10 08:26:05 +00:00
|
|
|
|
|
|
|
class MockTestRunner(object):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
2014-11-29 16:45:06 +00:00
|
|
|
MockTestRunner.run_tests = mock.Mock(return_value=[])
|
2011-06-10 08:26:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ManageCommandTests(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_custom_test_runner(self):
|
|
|
|
call_command('test', 'sites',
|
2013-02-26 12:19:18 +00:00
|
|
|
testrunner='test_runner.tests.MockTestRunner')
|
2014-11-29 16:45:06 +00:00
|
|
|
MockTestRunner.run_tests.assert_called_with(('sites',))
|
2011-06-10 08:26:05 +00:00
|
|
|
|
2013-02-16 12:26:36 +00:00
|
|
|
def test_bad_test_runner(self):
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
call_command('test', 'sites',
|
2013-02-26 12:19:18 +00:00
|
|
|
testrunner='test_runner.NonExistentRunner')
|
2013-02-16 12:26:36 +00:00
|
|
|
|
2011-06-10 08:26:05 +00:00
|
|
|
|
|
|
|
class CustomTestRunnerOptionsTests(AdminScriptTestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
settings = {
|
2015-02-09 21:41:57 +00:00
|
|
|
'TEST_RUNNER': '\'test_runner.runner.CustomOptionsTestRunner\'',
|
2011-06-10 08:26:05 +00:00
|
|
|
}
|
|
|
|
self.write_settings('settings.py', sdict=settings)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.remove_settings('settings.py')
|
|
|
|
|
|
|
|
def test_default_options(self):
|
2013-02-26 15:02:24 +00:00
|
|
|
args = ['test', '--settings=test_project.settings']
|
2011-06-10 08:26:05 +00:00
|
|
|
out, err = self.run_django_admin(args)
|
|
|
|
self.assertNoOutput(err)
|
|
|
|
self.assertOutput(out, '1:2:3')
|
|
|
|
|
|
|
|
def test_default_and_given_options(self):
|
2013-02-26 15:02:24 +00:00
|
|
|
args = ['test', '--settings=test_project.settings', '--option_b=foo']
|
2011-06-10 08:26:05 +00:00
|
|
|
out, err = self.run_django_admin(args)
|
|
|
|
self.assertNoOutput(err)
|
|
|
|
self.assertOutput(out, '1:foo:3')
|
|
|
|
|
|
|
|
def test_option_name_and_value_separated(self):
|
2013-02-26 15:02:24 +00:00
|
|
|
args = ['test', '--settings=test_project.settings', '--option_b', 'foo']
|
2011-06-10 08:26:05 +00:00
|
|
|
out, err = self.run_django_admin(args)
|
|
|
|
self.assertNoOutput(err)
|
|
|
|
self.assertOutput(out, '1:foo:3')
|
|
|
|
|
|
|
|
def test_all_options_given(self):
|
2013-02-26 15:02:24 +00:00
|
|
|
args = ['test', '--settings=test_project.settings', '--option_a=bar',
|
|
|
|
'--option_b=foo', '--option_c=31337']
|
2011-06-10 08:26:05 +00:00
|
|
|
out, err = self.run_django_admin(args)
|
|
|
|
self.assertNoOutput(err)
|
|
|
|
self.assertOutput(out, 'bar:foo:31337')
|
2011-06-12 12:34:10 +00:00
|
|
|
|
|
|
|
|
2011-12-29 01:18:30 +00:00
|
|
|
class Ticket17477RegressionTests(AdminScriptTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.write_settings('settings.py')
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.remove_settings('settings.py')
|
|
|
|
|
|
|
|
def test_ticket_17477(self):
|
|
|
|
"""'manage.py help test' works after r16352."""
|
|
|
|
args = ['help', 'test']
|
|
|
|
out, err = self.run_manage(args)
|
|
|
|
self.assertNoOutput(err)
|
|
|
|
|
|
|
|
|
2013-06-14 21:11:51 +00:00
|
|
|
class Sqlite3InMemoryTestDbs(TestCase):
|
|
|
|
|
|
|
|
available_apps = []
|
2012-03-14 10:58:23 +00:00
|
|
|
|
|
|
|
@unittest.skipUnless(all(db.connections[conn].vendor == 'sqlite' for conn in db.connections),
|
2013-09-05 22:23:48 +00:00
|
|
|
"This is an sqlite-specific issue")
|
2012-03-13 17:52:48 +00:00
|
|
|
def test_transaction_support(self):
|
|
|
|
"""Ticket #16329: sqlite3 in-memory test databases"""
|
2014-03-09 20:37:05 +00:00
|
|
|
for option_key, option_value in (
|
|
|
|
('NAME', ':memory:'), ('TEST', {'NAME': ':memory:'})):
|
2015-05-09 14:33:58 +00:00
|
|
|
tested_connections = db.ConnectionHandler({
|
|
|
|
'default': {
|
|
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
|
|
option_key: option_value,
|
|
|
|
},
|
|
|
|
'other': {
|
|
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
|
|
option_key: option_value,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
with mock.patch('django.db.connections', new=tested_connections):
|
|
|
|
with mock.patch('django.test.testcases.connections', new=tested_connections):
|
|
|
|
other = tested_connections['other']
|
|
|
|
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)
|
2012-04-24 16:47:31 +00:00
|
|
|
|
|
|
|
|
2013-01-04 12:55:20 +00:00
|
|
|
class DummyBackendTest(unittest.TestCase):
|
|
|
|
def test_setup_databases(self):
|
|
|
|
"""
|
|
|
|
Test that setup_databases() doesn't fail with dummy database backend.
|
|
|
|
"""
|
2015-05-09 14:33:58 +00:00
|
|
|
tested_connections = db.ConnectionHandler({})
|
|
|
|
with mock.patch('django.db.connections', new=tested_connections):
|
|
|
|
runner_instance = DiscoverRunner(verbosity=0)
|
|
|
|
try:
|
|
|
|
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)
|
2013-07-04 23:58:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AliasedDefaultTestSetupTest(unittest.TestCase):
|
|
|
|
def test_setup_aliased_default_database(self):
|
|
|
|
"""
|
|
|
|
Test that setup_datebases() doesn't fail when 'default' is aliased
|
|
|
|
"""
|
2015-05-09 14:33:58 +00:00
|
|
|
tested_connections = db.ConnectionHandler({
|
|
|
|
'default': {
|
|
|
|
'NAME': 'dummy'
|
|
|
|
},
|
|
|
|
'aliased': {
|
|
|
|
'NAME': 'dummy'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
with mock.patch('django.db.connections', new=tested_connections):
|
|
|
|
runner_instance = DiscoverRunner(verbosity=0)
|
|
|
|
try:
|
|
|
|
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)
|
2013-01-04 12:55:20 +00:00
|
|
|
|
|
|
|
|
2014-09-15 15:17:12 +00:00
|
|
|
class SetupDatabasesTests(unittest.TestCase):
|
2013-07-13 21:46:05 +00:00
|
|
|
|
2014-09-15 15:17:12 +00:00
|
|
|
def setUp(self):
|
2014-11-15 19:03:31 +00:00
|
|
|
self.runner_instance = DiscoverRunner(verbosity=0)
|
2013-07-13 21:46:05 +00:00
|
|
|
|
2014-09-15 15:17:12 +00:00
|
|
|
def test_setup_aliased_databases(self):
|
2015-05-09 14:33:58 +00:00
|
|
|
tested_connections = db.ConnectionHandler({
|
2014-09-15 15:17:12 +00:00
|
|
|
'default': {
|
|
|
|
'ENGINE': 'django.db.backends.dummy',
|
|
|
|
'NAME': 'dbname',
|
|
|
|
},
|
|
|
|
'other': {
|
|
|
|
'ENGINE': 'django.db.backends.dummy',
|
|
|
|
'NAME': 'dbname',
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-05-09 14:33:58 +00:00
|
|
|
with mock.patch('django.db.backends.dummy.base.DatabaseCreation') as mocked_db_creation:
|
|
|
|
with mock.patch('django.db.connections', new=tested_connections):
|
|
|
|
old_config = self.runner_instance.setup_databases()
|
|
|
|
self.runner_instance.teardown_databases(old_config)
|
|
|
|
mocked_db_creation.return_value.destroy_test_db.assert_called_once_with('dbname', 0, False)
|
2014-09-15 15:17:12 +00:00
|
|
|
|
2014-10-24 12:53:58 +00:00
|
|
|
def test_destroy_test_db_restores_db_name(self):
|
2015-05-09 14:33:58 +00:00
|
|
|
tested_connections = db.ConnectionHandler({
|
2014-10-24 12:53:58 +00:00
|
|
|
'default': {
|
|
|
|
'ENGINE': settings.DATABASES[db.DEFAULT_DB_ALIAS]["ENGINE"],
|
|
|
|
'NAME': 'xxx_test_database',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
# Using the real current name as old_name to not mess with the test suite.
|
|
|
|
old_name = settings.DATABASES[db.DEFAULT_DB_ALIAS]["NAME"]
|
2015-05-09 14:33:58 +00:00
|
|
|
with mock.patch('django.db.connections', new=tested_connections):
|
|
|
|
tested_connections['default'].creation.destroy_test_db(old_name, verbosity=0, keepdb=True)
|
|
|
|
self.assertEqual(tested_connections['default'].settings_dict["NAME"], old_name)
|
2014-10-24 12:53:58 +00:00
|
|
|
|
2014-09-15 15:17:12 +00:00
|
|
|
def test_serialization(self):
|
2015-05-09 14:33:58 +00:00
|
|
|
tested_connections = db.ConnectionHandler({
|
2014-09-15 15:17:12 +00:00
|
|
|
'default': {
|
|
|
|
'ENGINE': 'django.db.backends.dummy',
|
|
|
|
},
|
|
|
|
})
|
2015-05-09 14:33:58 +00:00
|
|
|
with mock.patch('django.db.backends.dummy.base.DatabaseCreation') as mocked_db_creation:
|
|
|
|
with mock.patch('django.db.connections', new=tested_connections):
|
|
|
|
self.runner_instance.setup_databases()
|
|
|
|
mocked_db_creation.return_value.create_test_db.assert_called_once_with(
|
|
|
|
0, autoclobber=False, serialize=True, keepdb=False
|
|
|
|
)
|
2014-09-15 15:17:12 +00:00
|
|
|
|
|
|
|
def test_serialized_off(self):
|
2015-05-09 14:33:58 +00:00
|
|
|
tested_connections = db.ConnectionHandler({
|
2014-09-15 15:17:12 +00:00
|
|
|
'default': {
|
|
|
|
'ENGINE': 'django.db.backends.dummy',
|
|
|
|
'TEST': {'SERIALIZE': False},
|
|
|
|
},
|
|
|
|
})
|
2015-05-09 14:33:58 +00:00
|
|
|
with mock.patch('django.db.backends.dummy.base.DatabaseCreation') as mocked_db_creation:
|
|
|
|
with mock.patch('django.db.connections', new=tested_connections):
|
|
|
|
self.runner_instance.setup_databases()
|
|
|
|
mocked_db_creation.return_value.create_test_db.assert_called_once_with(
|
|
|
|
0, autoclobber=False, serialize=False, keepdb=False
|
|
|
|
)
|
2013-07-13 21:46:05 +00:00
|
|
|
|
|
|
|
|
2013-01-03 00:00:39 +00:00
|
|
|
class DeprecationDisplayTest(AdminScriptTestCase):
|
|
|
|
# tests for 19546
|
|
|
|
def setUp(self):
|
2013-05-11 03:08:45 +00:00
|
|
|
settings = {
|
|
|
|
'DATABASES': '{"default": {"ENGINE":"django.db.backends.sqlite3", "NAME":":memory:"}}'
|
2013-10-18 09:02:43 +00:00
|
|
|
}
|
2013-01-03 00:00:39 +00:00
|
|
|
self.write_settings('settings.py', sdict=settings)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.remove_settings('settings.py')
|
|
|
|
|
|
|
|
def test_runner_deprecation_verbosity_default(self):
|
2013-05-11 03:08:45 +00:00
|
|
|
args = ['test', '--settings=test_project.settings', 'test_runner_deprecation_app']
|
2013-01-03 00:00:39 +00:00
|
|
|
out, err = self.run_django_admin(args)
|
2015-02-15 00:47:07 +00:00
|
|
|
self.assertIn("Ran 1 test", force_text(err))
|
2015-06-22 17:54:35 +00:00
|
|
|
six.assertRegex(self, err, r"RemovedInDjango\d+Warning: warning from test")
|
|
|
|
six.assertRegex(self, err, r"RemovedInDjango\d+Warning: module-level warning from deprecation_app")
|
2013-01-03 00:00:39 +00:00
|
|
|
|
|
|
|
def test_runner_deprecation_verbosity_zero(self):
|
2013-12-31 12:12:30 +00:00
|
|
|
args = ['test', '--settings=test_project.settings', '--verbosity=0', 'test_runner_deprecation_app']
|
2013-01-03 00:00:39 +00:00
|
|
|
out, err = self.run_django_admin(args)
|
2013-12-31 12:12:30 +00:00
|
|
|
self.assertIn("Ran 1 test", err)
|
2014-10-28 10:02:56 +00:00
|
|
|
self.assertNotIn("warning from test", err)
|
2013-01-03 00:00:39 +00:00
|
|
|
|
2013-01-09 18:59:24 +00:00
|
|
|
|
2012-04-24 16:47:31 +00:00
|
|
|
class AutoIncrementResetTest(TransactionTestCase):
|
|
|
|
"""
|
|
|
|
Here we test creating the same model two times in different test methods,
|
|
|
|
and check that both times they get "1" as their PK value. That is, we test
|
|
|
|
that AutoField values start from 1 for each transactional test case.
|
|
|
|
"""
|
2012-07-24 20:24:16 +00:00
|
|
|
|
2013-06-04 06:09:29 +00:00
|
|
|
available_apps = ['test_runner']
|
|
|
|
|
2012-07-24 20:24:16 +00:00
|
|
|
reset_sequences = True
|
|
|
|
|
2012-05-22 20:46:27 +00:00
|
|
|
@skipUnlessDBFeature('supports_sequence_reset')
|
2012-04-24 16:47:31 +00:00
|
|
|
def test_autoincrement_reset1(self):
|
|
|
|
p = Person.objects.create(first_name='Jack', last_name='Smith')
|
2012-05-03 14:39:16 +00:00
|
|
|
self.assertEqual(p.pk, 1)
|
2012-04-24 16:47:31 +00:00
|
|
|
|
2012-05-22 20:46:27 +00:00
|
|
|
@skipUnlessDBFeature('supports_sequence_reset')
|
2012-04-24 16:47:31 +00:00
|
|
|
def test_autoincrement_reset2(self):
|
|
|
|
p = Person.objects.create(first_name='Jack', last_name='Smith')
|
2012-05-03 14:39:16 +00:00
|
|
|
self.assertEqual(p.pk, 1)
|
2015-03-12 16:17:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EmptyDefaultDatabaseTest(unittest.TestCase):
|
|
|
|
def test_empty_default_database(self):
|
|
|
|
"""
|
|
|
|
Test that an empty default database in settings does not raise an ImproperlyConfigured
|
|
|
|
error when running a unit test that does not use a database.
|
|
|
|
"""
|
|
|
|
testcases.connections = db.ConnectionHandler({'default': {}})
|
|
|
|
connection = testcases.connections[db.utils.DEFAULT_DB_ALIAS]
|
|
|
|
self.assertEqual(connection.settings_dict['ENGINE'], 'django.db.backends.dummy')
|
|
|
|
try:
|
|
|
|
connections_support_transactions()
|
|
|
|
except Exception as e:
|
|
|
|
self.fail("connections_support_transactions() unexpectedly raised an error: %s" % e)
|