Skip to content

Commit

Permalink
Simplifies settings setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Dec 7, 2014
1 parent 5e5ba93 commit 780c6cb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 28 deletions.
4 changes: 1 addition & 3 deletions benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
from random import choice
from time import time

if __name__ == '__main__':
from settings import configure
configure()
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')

from django.conf import settings
from django.contrib.auth.models import User, Group
Expand Down
7 changes: 1 addition & 6 deletions benchmark_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
-r requirements.txt
psycopg2
MySQL-python
django-redis
python-memcached
South
-r runtests_requirements.txt

pandas
matplotlib
5 changes: 2 additions & 3 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
# coding: utf-8

from __future__ import unicode_literals
import os
import sys

from settings import configure


if __name__ == '__main__':
configure()
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
from django.test.runner import DiscoverRunner
test_runner = DiscoverRunner()
failures = test_runner.run_tests(['cachalot.tests'])
Expand Down
6 changes: 6 additions & 0 deletions runtests_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-r requirements.txt
psycopg2
MySQL-python
django-redis
python-memcached
South
23 changes: 7 additions & 16 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os

import django
from django.conf import settings


DATABASES = {
Expand Down Expand Up @@ -32,8 +31,8 @@
else:
DATABASES[alias]['TEST'] = {'NAME': test_db_name}

DEFAULT_DATABASE_KEY = os.environ.get('DB_ENGINE', 'sqlite3')
DATABASES['default'] = DATABASES.pop(DEFAULT_DATABASE_KEY)
DATABASES['default'] = DATABASES.pop(os.environ.get('DB_ENGINE', 'sqlite3'))


CACHES = {
'locmem': {
Expand All @@ -48,8 +47,9 @@
'LOCATION': '127.0.0.1:11211',
},
}
DEFAULT_CACHE_KEY = os.environ.get('CACHE_BACKEND', 'locmem')
CACHES['default'] = CACHES.pop(DEFAULT_CACHE_KEY)

CACHES['default'] = CACHES.pop(os.environ.get('CACHE_BACKEND', 'locmem'))


INSTALLED_APPS = [
'cachalot',
Expand All @@ -60,14 +60,5 @@
INSTALLED_APPS.append('south')


def configure():
settings.configure(
INSTALLED_APPS=INSTALLED_APPS,
DATABASES=DATABASES,
CACHES=CACHES,
MIDDLEWARE_CLASSES=(),
PASSWORD_HASHERS=('django.contrib.auth.hashers.MD5PasswordHasher',),
)

if django.VERSION[:2] >= (1, 7):
django.setup()
PASSWORD_HASHERS = ('django.contrib.auth.hashers.MD5PasswordHasher',)
SECRET_KEY = 'it’s not important but we have to set it'

0 comments on commit 780c6cb

Please sign in to comment.