| 1 |
import os |
| 2 |
|
| 3 |
from django import VERSION as __DJ_V |
| 4 |
|
| 5 |
|
| 6 |
DATABASES = { |
| 7 |
'sqlite3': { |
| 8 |
'ENGINE': 'django.db.backends.sqlite3', |
| 9 |
'NAME': 'cachalot.sqlite3', |
| 10 |
}, |
| 11 |
'postgresql': { |
| 12 |
'ENGINE': 'django.db.backends.postgresql', |
| 13 |
'NAME': 'cachalot', |
| 14 |
'USER': 'cachalot', |
| 15 |
'PASSWORD': 'password', |
| 16 |
'HOST': '127.0.0.1', |
| 17 |
}, |
| 18 |
'mysql': { |
| 19 |
'ENGINE': 'django.db.backends.mysql', |
| 20 |
'NAME': 'cachalot', |
| 21 |
'USER': 'root', |
| 22 |
'HOST': '127.0.0.1', |
| 23 |
}, |
| 24 |
} |
| 25 |
if 'MYSQL_PASSWORD' in os.environ: |
| 26 |
DATABASES['mysql']['PASSWORD'] = os.environ['MYSQL_PASSWORD'] |
| 27 |
if 'POSTGRES_PASSWORD' in os.environ: |
| 28 |
DATABASES['postgresql']['PASSWORD'] = os.environ['POSTGRES_PASSWORD'] |
| 29 |
for alias in DATABASES: |
| 30 |
if 'TEST' not in DATABASES[alias]: |
| 31 |
test_db_name = 'test_' + DATABASES[alias]['NAME'] |
| 32 |
DATABASES[alias]['TEST'] = {'NAME': test_db_name} |
| 33 |
|
| 34 |
DATABASES['default'] = DATABASES.pop(os.environ.get('DB_ENGINE', 'sqlite3')) |
| 35 |
DEFAULT_AUTO_FIELD = "django.db.models.AutoField" |
| 36 |
DATABASE_ROUTERS = ['cachalot.tests.db_router.PostgresRouter'] |
| 37 |
|
| 38 |
CACHES = { |
| 39 |
'redis': { |
| 40 |
'BACKEND': 'django_redis.cache.RedisCache', |
| 41 |
'LOCATION': 'redis://127.0.0.1:6379/0', |
| 42 |
'OPTIONS': { |
| 43 |
# Since we are using both Python 2 & 3 in tests, we need to use |
| 44 |
# a compatible pickle version to avoid unpickling errors when |
| 45 |
# running a Python 2 test after a Python 3 test. |
| 46 |
'PICKLE_VERSION': 2, |
| 47 |
}, |
| 48 |
}, |
| 49 |
'memcached': { |
| 50 |
'BACKEND': 'django.core.cache.backends.memcached.' |
| 51 |
+ ('PyMemcacheCache' if __DJ_V[0] > 2 |
| 52 |
and (__DJ_V[1] > 1 or __DJ_V[0] > 3) else 'MemcachedCache'), |
| 53 |
'LOCATION': '127.0.0.1:11211', |
| 54 |
}, |
| 55 |
'locmem': { |
| 56 |
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', |
| 57 |
'OPTIONS': { |
| 58 |
# We want that limit to be infinite, otherwise we can’t |
| 59 |
# reliably count the number of SQL queries executed in tests. |
| 60 |
|
| 61 |
# In this context, 10e9 is enough to be considered |
| 62 |
# infinite. |
| 63 |
'MAX_ENTRIES': 10e9, |
| 64 |
} |
| 65 |
}, |
| 66 |
'filebased': { |
| 67 |
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', |
| 68 |
'LOCATION': '/tmp/django_cache', |
| 69 |
'OPTIONS': { |
| 70 |
'MAX_ENTRIES': 10e9, # (See locmem) |
| 71 |
}, |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
try: |
| 76 |
from django.core.cache.backends.redis import RedisCache |
| 77 |
except ImportError: |
| 78 |
pass |
| 79 |
else: |
| 80 |
CACHES['builtin_redis']= { |
| 81 |
'BACKEND': 'django.core.cache.backends.redis.RedisCache', |
| 82 |
# Make sure to use a different redis database to avoid conflicts with the other |
| 83 |
# redis cache backend. |
| 84 |
'LOCATION': 'redis://127.0.0.1:6379/1', |
| 85 |
} |
| 86 |
|
| 87 |
try: |
| 88 |
import pylibmc |
| 89 |
except ImportError: |
| 90 |
pass |
| 91 |
else: |
| 92 |
CACHES['pylibmc'] = { |
| 93 |
'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', |
| 94 |
'LOCATION': '127.0.0.1:11211', |
| 95 |
} |
| 96 |
|
| 97 |
DEFAULT_CACHE_ALIAS = os.environ.get('CACHE_BACKEND', 'locmem') |
| 98 |
CACHES['default'] = CACHES.pop(DEFAULT_CACHE_ALIAS) |
| 99 |
if DEFAULT_CACHE_ALIAS == 'memcached' and 'pylibmc' in CACHES: |
| 100 |
del CACHES['pylibmc'] |
| 101 |
elif DEFAULT_CACHE_ALIAS == 'pylibmc': |
| 102 |
del CACHES['memcached'] |
| 103 |
|
| 104 |
INSTALLED_APPS = [ |
| 105 |
'cachalot', |
| 106 |
'cachalot.admin_tests', |
| 107 |
'django.contrib.auth', |
| 108 |
'django.contrib.contenttypes', |
| 109 |
'django.contrib.postgres', # Enables the unaccent lookup. |
| 110 |
'django.contrib.sessions', |
| 111 |
'django.contrib.admin', |
| 112 |
'django.contrib.messages', |
| 113 |
] |
| 114 |
|
| 115 |
MIGRATION_MODULES = { |
| 116 |
'cachalot': 'cachalot.tests.migrations', |
| 117 |
} |
| 118 |
|
| 119 |
TEMPLATES = [ |
| 120 |
{ |
| 121 |
'BACKEND': 'django.template.backends.django.DjangoTemplates', |
| 122 |
'DIRS': [], |
| 123 |
'APP_DIRS': True, |
| 124 |
'OPTIONS': { |
| 125 |
'context_processors': [ |
| 126 |
'django.contrib.auth.context_processors.auth', |
| 127 |
'django.contrib.messages.context_processors.messages', |
| 128 |
], |
| 129 |
} |
| 130 |
}, |
| 131 |
{ |
| 132 |
'BACKEND': 'django.template.backends.jinja2.Jinja2', |
| 133 |
'APP_DIRS': True, |
| 134 |
'OPTIONS': { |
| 135 |
'extensions': [ |
| 136 |
'cachalot.jinja2ext.cachalot', |
| 137 |
], |
| 138 |
}, |
| 139 |
} |
| 140 |
] |
| 141 |
|
| 142 |
MIDDLEWARE = [ |
| 143 |
'django.contrib.sessions.middleware.SessionMiddleware', |
| 144 |
'django.contrib.auth.middleware.AuthenticationMiddleware', |
| 145 |
'django.contrib.messages.middleware.MessageMiddleware', |
| 146 |
] |
| 147 |
PASSWORD_HASHERS = ['django.contrib.auth.hashers.MD5PasswordHasher'] |
| 148 |
SECRET_KEY = 'it’s not important in tests but we have to set it' |
| 149 |
|
| 150 |
USE_TZ = False # Time zones are not supported by MySQL, we only enable it in tests when needed. |
| 151 |
TIME_ZONE = 'UTC' |
| 152 |
|
| 153 |
CACHALOT_ENABLED = True |
| 154 |
|
| 155 |
# |
| 156 |
# Settings for django-debug-toolbar |
| 157 |
# |
| 158 |
|
| 159 |
# We put django-debug-toolbar before to reproduce the conditions of this issue: |
| 160 |
# https://github.com/noripyt/django-cachalot/issues/62 |
| 161 |
INSTALLED_APPS = [ |
| 162 |
'debug_toolbar', |
| 163 |
] + INSTALLED_APPS + ['django.contrib.staticfiles'] |
| 164 |
|
| 165 |
DEBUG_TOOLBAR_PANELS = [ |
| 166 |
'debug_toolbar.panels.versions.VersionsPanel', |
| 167 |
'debug_toolbar.panels.timer.TimerPanel', |
| 168 |
'debug_toolbar.panels.settings.SettingsPanel', |
| 169 |
'debug_toolbar.panels.headers.HeadersPanel', |
| 170 |
'debug_toolbar.panels.request.RequestPanel', |
| 171 |
'debug_toolbar.panels.sql.SQLPanel', |
| 172 |
'debug_toolbar.panels.staticfiles.StaticFilesPanel', |
| 173 |
'debug_toolbar.panels.templates.TemplatesPanel', |
| 174 |
'debug_toolbar.panels.cache.CachePanel', |
| 175 |
'debug_toolbar.panels.signals.SignalsPanel', |
| 176 |
'debug_toolbar.panels.logging.LoggingPanel', |
| 177 |
'debug_toolbar.panels.redirects.RedirectsPanel', |
| 178 |
'cachalot.panels.CachalotPanel', |
| 179 |
] |
| 180 |
|
| 181 |
DEBUG_TOOLBAR_CONFIG = { |
| 182 |
# Django’s test client sets wsgi.multiprocess to True inappropriately. |
| 183 |
'RENDER_PANELS': False, |
| 184 |
} |
| 185 |
|
| 186 |
MIDDLEWARE += [ |
| 187 |
'debug_toolbar.middleware.DebugToolbarMiddleware', |
| 188 |
] |
| 189 |
|
| 190 |
INTERNAL_IPS = ['127.0.0.1'] |
| 191 |
ROOT_URLCONF = 'runtests_urls' |
| 192 |
STATIC_URL = '/static/' |