| 1 |
import os |
| 2 |
|
| 3 |
from tests.redis_config import REDIS_CONFIG_1, REDIS_CONFIG_2 |
| 4 |
|
| 5 |
SECRET_KEY = 'a' |
| 6 |
|
| 7 |
# Detect whether either django-redis or django-redis-cache is installed. This |
| 8 |
# is only really used to conditionally configure options for the unit tests. |
| 9 |
# In actually usage, no such check is necessary. |
| 10 |
try: |
| 11 |
from django_redis import get_redis_connection |
| 12 |
|
| 13 |
REDIS_CACHE_TYPE = 'django-redis' |
| 14 |
except ImportError: |
| 15 |
try: |
| 16 |
import redis_cache |
| 17 |
|
| 18 |
REDIS_CACHE_TYPE = 'django-redis-cache' |
| 19 |
except ImportError: |
| 20 |
REDIS_CACHE_TYPE = 'none' |
| 21 |
|
| 22 |
INSTALLED_APPS = [ |
| 23 |
'django.contrib.contenttypes', |
| 24 |
'django.contrib.admin', |
| 25 |
'django.contrib.auth', |
| 26 |
'django.contrib.messages', |
| 27 |
'django.contrib.sessions', |
| 28 |
'django_rq', |
| 29 |
] |
| 30 |
|
| 31 |
|
| 32 |
DATABASES = { |
| 33 |
'default': { |
| 34 |
'ENGINE': 'django.db.backends.sqlite3', |
| 35 |
'NAME': ':memory:', |
| 36 |
}, |
| 37 |
} |
| 38 |
|
| 39 |
if REDIS_CACHE_TYPE == 'django-redis': |
| 40 |
CACHES = { |
| 41 |
'default': { |
| 42 |
'BACKEND': 'django_redis.cache.RedisCache', |
| 43 |
'LOCATION': f"redis://{REDIS_CONFIG_1.host}:{REDIS_CONFIG_1.port}/{REDIS_CONFIG_1.db}", |
| 44 |
'OPTIONS': { |
| 45 |
'CLIENT_CLASS': 'django_redis.client.DefaultClient', |
| 46 |
}, |
| 47 |
}, |
| 48 |
} |
| 49 |
elif REDIS_CACHE_TYPE == 'django-redis-cache': |
| 50 |
CACHES = { |
| 51 |
'default': { |
| 52 |
'BACKEND': 'redis_cache.cache.RedisCache', |
| 53 |
'LOCATION': f'{REDIS_CONFIG_1.host}:{REDIS_CONFIG_1.port}', |
| 54 |
'KEY_PREFIX': 'django-rq-tests', |
| 55 |
'OPTIONS': { |
| 56 |
'DB': REDIS_CONFIG_2.db, |
| 57 |
'MAX_ENTRIES': 5000, |
| 58 |
}, |
| 59 |
}, |
| 60 |
} |
| 61 |
|
| 62 |
LOGGING = { |
| 63 |
"version": 1, |
| 64 |
"disable_existing_loggers": False, |
| 65 |
"formatters": { |
| 66 |
"rq_console": { |
| 67 |
"format": "%(asctime)s %(message)s", |
| 68 |
"datefmt": "%H:%M:%S", |
| 69 |
}, |
| 70 |
}, |
| 71 |
"handlers": { |
| 72 |
"rq_console": { |
| 73 |
"level": "DEBUG", |
| 74 |
# "class": "logging.StreamHandler", |
| 75 |
"class": "rq.logutils.ColorizingStreamHandler", |
| 76 |
"formatter": "rq_console", |
| 77 |
"exclude": ["%(asctime)s"], |
| 78 |
}, |
| 79 |
'null': { |
| 80 |
'level': 'DEBUG', |
| 81 |
'class': 'logging.NullHandler', |
| 82 |
}, |
| 83 |
}, |
| 84 |
'loggers': { |
| 85 |
"rq.worker": {"handlers": ['null'], "level": "ERROR"}, |
| 86 |
}, |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
RQ_QUEUES = { |
| 91 |
'default': { |
| 92 |
'HOST': REDIS_CONFIG_1.host, |
| 93 |
'PORT': REDIS_CONFIG_1.port, |
| 94 |
'DB': REDIS_CONFIG_1.db, |
| 95 |
'DEFAULT_TIMEOUT': 500, |
| 96 |
'DEFAULT_RESULT_TTL': 500, |
| 97 |
}, |
| 98 |
'test': { |
| 99 |
'HOST': REDIS_CONFIG_2.host, |
| 100 |
'PORT': REDIS_CONFIG_2.port, |
| 101 |
'DB': REDIS_CONFIG_2.db, |
| 102 |
}, |
| 103 |
'sentinel': { |
| 104 |
'SENTINELS': [(REDIS_CONFIG_1.host, 26736), (REDIS_CONFIG_1.host, 26737)], |
| 105 |
'MASTER_NAME': 'testmaster', |
| 106 |
'DB': REDIS_CONFIG_2.db, |
| 107 |
'USERNAME': 'redis-user', |
| 108 |
'PASSWORD': 'secret', |
| 109 |
'SOCKET_TIMEOUT': 10, |
| 110 |
'SENTINEL_KWARGS': {}, |
| 111 |
}, |
| 112 |
'test1': { |
| 113 |
'HOST': REDIS_CONFIG_2.host, |
| 114 |
'PORT': REDIS_CONFIG_2.port, |
| 115 |
'DB': REDIS_CONFIG_2.db, |
| 116 |
'DEFAULT_TIMEOUT': 400, |
| 117 |
'QUEUE_CLASS': 'tests.fixtures.DummyQueue', |
| 118 |
}, |
| 119 |
'test2': { |
| 120 |
'HOST': REDIS_CONFIG_2.host, |
| 121 |
'PORT': REDIS_CONFIG_2.port, |
| 122 |
'DB': REDIS_CONFIG_2.db, |
| 123 |
}, |
| 124 |
'test3': { |
| 125 |
'HOST': REDIS_CONFIG_2.host, |
| 126 |
'PORT': REDIS_CONFIG_2.port, |
| 127 |
'DB': REDIS_CONFIG_2.db, |
| 128 |
'DEFAULT_RESULT_TTL': 800, |
| 129 |
}, |
| 130 |
'async': { |
| 131 |
'HOST': REDIS_CONFIG_2.host, |
| 132 |
'PORT': REDIS_CONFIG_2.port, |
| 133 |
'DB': REDIS_CONFIG_2.db, |
| 134 |
'ASYNC': False, |
| 135 |
}, |
| 136 |
'url': { |
| 137 |
'URL': 'redis://username:password@host:1234/', |
| 138 |
'DB': 4, |
| 139 |
}, |
| 140 |
'url_with_db': { |
| 141 |
'URL': 'redis://username:password@host:1234/5', |
| 142 |
}, |
| 143 |
'url_default_db': { |
| 144 |
'URL': 'redis://username:password@host:1234', |
| 145 |
}, |
| 146 |
'django_rq_test': { |
| 147 |
'HOST': REDIS_CONFIG_1.host, |
| 148 |
'PORT': REDIS_CONFIG_1.port, |
| 149 |
'DB': REDIS_CONFIG_1.db, |
| 150 |
}, |
| 151 |
'scheduler_scheduler_active_test': { |
| 152 |
'HOST': REDIS_CONFIG_1.host, |
| 153 |
'PORT': REDIS_CONFIG_1.port, |
| 154 |
'DB': REDIS_CONFIG_1.db, |
| 155 |
'ASYNC': False, |
| 156 |
}, |
| 157 |
'scheduler_scheduler_inactive_test': { |
| 158 |
'HOST': REDIS_CONFIG_1.host, |
| 159 |
'PORT': REDIS_CONFIG_1.port, |
| 160 |
'DB': REDIS_CONFIG_1.db, |
| 161 |
'ASYNC': False, |
| 162 |
}, |
| 163 |
'worker_scheduler_active_test': { |
| 164 |
'HOST': REDIS_CONFIG_1.host, |
| 165 |
'PORT': REDIS_CONFIG_1.port, |
| 166 |
'DB': REDIS_CONFIG_1.db, |
| 167 |
'ASYNC': False, |
| 168 |
}, |
| 169 |
'worker_scheduler_inactive_test': { |
| 170 |
'HOST': REDIS_CONFIG_1.host, |
| 171 |
'PORT': REDIS_CONFIG_1.port, |
| 172 |
'DB': REDIS_CONFIG_1.db, |
| 173 |
'ASYNC': False, |
| 174 |
}, |
| 175 |
'django-redis': { |
| 176 |
'USE_REDIS_CACHE': 'default', |
| 177 |
}, |
| 178 |
'django_rq_test2': { |
| 179 |
'HOST': REDIS_CONFIG_1.host, |
| 180 |
'PORT': REDIS_CONFIG_1.port, |
| 181 |
'DB': REDIS_CONFIG_1.db, |
| 182 |
}, |
| 183 |
'test_scheduler': { |
| 184 |
'HOST': REDIS_CONFIG_1.host, |
| 185 |
'PORT': REDIS_CONFIG_1.port, |
| 186 |
'DB': REDIS_CONFIG_1.db, |
| 187 |
'DEFAULT_TIMEOUT': 400, |
| 188 |
}, |
| 189 |
'test_serializer': { |
| 190 |
'HOST': REDIS_CONFIG_1.host, |
| 191 |
'PORT': REDIS_CONFIG_1.port, |
| 192 |
'DB': REDIS_CONFIG_1.db, |
| 193 |
'SERIALIZER': 'rq.serializers.JSONSerializer', |
| 194 |
}, |
| 195 |
} |
| 196 |
RQ = { |
| 197 |
'AUTOCOMMIT': False, |
| 198 |
} |
| 199 |
|
| 200 |
if REDIS_CACHE_TYPE == 'django-redis-cache': |
| 201 |
RQ_QUEUES['django-redis-cache'] = {'USE_REDIS_CACHE': 'django-redis-cache'} |
| 202 |
|
| 203 |
ROOT_URLCONF = 'tests.urls' |
| 204 |
|
| 205 |
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 206 |
|
| 207 |
TEMPLATES = [ |
| 208 |
{ |
| 209 |
'BACKEND': 'django.template.backends.django.DjangoTemplates', |
| 210 |
'DIRS': [os.path.join(BASE_DIR, "templates")], |
| 211 |
'APP_DIRS': False, |
| 212 |
'OPTIONS': { |
| 213 |
'context_processors': [ |
| 214 |
'django.template.context_processors.debug', |
| 215 |
'django.template.context_processors.request', |
| 216 |
'django.contrib.auth.context_processors.auth', |
| 217 |
'django.contrib.messages.context_processors.messages', |
| 218 |
], |
| 219 |
'loaders': [ |
| 220 |
'django.template.loaders.filesystem.Loader', |
| 221 |
'django.template.loaders.app_directories.Loader', |
| 222 |
], |
| 223 |
}, |
| 224 |
}, |
| 225 |
] |
| 226 |
|
| 227 |
|
| 228 |
MIDDLEWARE = ( |
| 229 |
'django.middleware.common.CommonMiddleware', |
| 230 |
'django.contrib.sessions.middleware.SessionMiddleware', |
| 231 |
'django.contrib.auth.middleware.AuthenticationMiddleware', |
| 232 |
'django.contrib.messages.middleware.MessageMiddleware', |
| 233 |
) |
| 234 |
|
| 235 |
MIDDLEWARE_CLASSES = MIDDLEWARE |
| 236 |
|
| 237 |
AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',) |