Skip to content

Commit

Permalink
Allow adjusting test settings per environment
Browse files Browse the repository at this point in the history
  • Loading branch information
anrie committed Apr 11, 2015
1 parent 90a5e0c commit 480a0e8
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 92 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -3,6 +3,7 @@ before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 5 # give xvfb some time to start
- export DJANGO_SETTINGS_MODULE=example.conf.travis
install:
- pip install -U tox
script:
Expand Down
Empty file added example/conf/__init__.py
Empty file.
89 changes: 89 additions & 0 deletions example/conf/base.py
@@ -0,0 +1,89 @@
import os
import sys
import logging
import django.template

BASE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir)

DEBUG = True
TEMPLATE_DEBUG = True

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}

TIME_ZONE = 'Europe/Berlin'
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

USE_I18N = True
USE_L10N = True
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
SECRET_KEY = '0pfuvtvasdlkjasd76723"b)lna4*f_-xxkszs4##!+wpo'

ROOT_URLCONF = 'example.urls'


TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)

if django.VERSION[:2] >= (1, 7):
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'easy_thumbnails',
'image_cropping',
'example',
]


if django.VERSION[:2] < (1, 6):
TEST_RUNNER = 'discover_runner.DiscoverRunner'
else:
TEST_RUNNER = 'django.test.runner.DiscoverRunner'

from easy_thumbnails.conf import Settings as thumbnail_settings
THUMBNAIL_PROCESSORS = (
'image_cropping.thumbnail_processors.crop_corners',
) + thumbnail_settings.THUMBNAIL_PROCESSORS

try:
import django_extensions
except ImportError:
pass
else:
INSTALLED_APPS += ['django_extensions']

# disable logging while testing
if len(sys.argv) > 1 and sys.argv[1] == 'test':
logging.disable(logging.CRITICAL)
# use an in-memory db while testing
DATABASES['default']['NAME'] = ':memory:'

IMAGE_CROPPING_THUMB_SIZE = (300, 300)
IMAGE_CROPPING_JQUERY_URL = 'js/jquery.min.js'
THUMBNAIL_DEBUG = True
TEST_HEADLESS = False
2 changes: 2 additions & 0 deletions example/conf/tests.py
@@ -0,0 +1,2 @@
from .base import *
TEST_HEADLESS = True
5 changes: 5 additions & 0 deletions example/conf/travis.py
@@ -0,0 +1,5 @@
from .base import *
TEST_HEADLESS = False
DEBUG = True
TEMPLATE_DEBUG = False
THUMBNAIL_DEBUG = False
90 changes: 1 addition & 89 deletions example/settings.py
@@ -1,89 +1 @@
import os
import sys
import logging
import django.template

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

DEBUG = True
TEMPLATE_DEBUG = True

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite3',
}
}

TIME_ZONE = 'Europe/Berlin'
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

USE_I18N = True
USE_L10N = True
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
SECRET_KEY = '0pfuvtvasdlkjasd76723"b)lna4*f_-xxkszs4##!+wpo'

ROOT_URLCONF = 'example.urls'


TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)

if django.VERSION[:2] >= (1, 7):
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'easy_thumbnails',
'image_cropping',
'example',
]


if django.VERSION[:2] < (1, 6):
TEST_RUNNER = 'discover_runner.DiscoverRunner'
else:
TEST_RUNNER = 'django.test.runner.DiscoverRunner'

from easy_thumbnails.conf import settings as thumbnail_settings
THUMBNAIL_PROCESSORS = (
'image_cropping.thumbnail_processors.crop_corners',
) + thumbnail_settings.THUMBNAIL_PROCESSORS

try:
import django_extensions
except ImportError:
pass
else:
INSTALLED_APPS += ['django_extensions']

# disable logging while testing
if len(sys.argv) > 1 and sys.argv[1] == 'test':
logging.disable(logging.CRITICAL)
# use an in-memory db while testing
DATABASES['default']['NAME'] = ':memory:'

IMAGE_CROPPING_THUMB_SIZE = (300, 300)
IMAGE_CROPPING_JQUERY_URL = 'js/jquery.min.js'
THUMBNAIL_DEBUG = True
HEADLESS = False
from example.conf.tests import *
6 changes: 4 additions & 2 deletions example/tests/test_browser.py
Expand Up @@ -12,12 +12,14 @@
from image_cropping.config import settings
from . import factory

TEST_HEADLESS = getattr(settings, 'TEST_HEADLESS', False)


class BrowserTestBase(object):

@classmethod
def setUpClass(cls):
if settings.HEADLESS:
if TEST_HEADLESS:
cls.display = Display(visible=0, size=(1024, 768))
cls.display.start()
cls.selenium = WebDriver()
Expand All @@ -26,7 +28,7 @@ def setUpClass(cls):
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
if settings.HEADLESS:
if TEST_HEADLESS:
cls.display.stop()
super(BrowserTestBase, cls).tearDownClass()

Expand Down
1 change: 0 additions & 1 deletion tox.ini
Expand Up @@ -20,7 +20,6 @@ deps =
[testenv]
commands = django-admin.py test example
setenv =
DJANGO_SETTINGS_MODULE=example.settings
PYTHONPATH={toxinidir}

[testenv:py27_django14]
Expand Down

0 comments on commit 480a0e8

Please sign in to comment.