2
2
from django.conf import settings
3
from django.core.cache import get_cache
4
from django.core.cache.backends.db import BaseDatabaseCache
3
5
from django.core.exceptions import ImproperlyConfigured
4
6
from django.core.management import call_command
5
7
from django.db.backends.sqlite3.creation import DatabaseCreation
22
24
self.connection.close()
24
26
self.connection.settings_dict["NAME"] = test_database_name
25
can_rollback = self._rollback_works()
26
self.connection.settings_dict["SUPPORTS_TRANSACTIONS"] = can_rollback
27
# Confirm the feature set of the test database
28
self.connection.features.confirm()
27
29
# Need to load the SpatiaLite initialization SQL before running `syncdb`.
28
30
self.load_spatialite_sql()
29
31
call_command('syncdb', verbosity=verbosity, interactive=False, database=self.connection.alias)
31
if settings.CACHE_BACKEND.startswith('db://'):
32
from django.core.cache import parse_backend_uri
33
_, cache_name, _ = parse_backend_uri(settings.CACHE_BACKEND)
34
call_command('createcachetable', cache_name)
33
for cache_alias in settings.CACHES:
34
cache = get_cache(cache_alias)
35
if isinstance(cache, BaseDatabaseCache):
36
from django.db import router
37
if router.allow_syncdb(self.connection.alias, cache.cache_model_class):
38
call_command('createcachetable', cache._table, database=self.connection.alias)
36
39
# Get a cursor (even though we don't need one yet). This has
37
40
# the side effect of initializing the test database.
38
41
cursor = self.connection.cursor()