Skip to content

Commit

Permalink
Merge standalone and oscar sandboxes
Browse files Browse the repository at this point in the history
Sharing code between the standalone and Oscar sandbox is tricky with the
current setup. To reduce the amount of code duplication, the sandboxes
have been merged into the same project using django-configurations to
switch the settings. This also simplifies the settings for the tests
and uses the appropriate sandbox settings instead of re-defining them.

Resolves #51.
  • Loading branch information
roadsideseb committed Jul 15, 2014
1 parent 2f614c5 commit e15539c
Show file tree
Hide file tree
Showing 42 changed files with 166 additions and 520 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -29,7 +29,7 @@ env:
- DJANGO="Django>=1.6,<1.7" MODEL_UTILS_VERSION=">2.0" TARGET='test-oscar-fancypages'

# Testing against Django 1.7
- DJANGO="https://github.com/django/django/archive/1.7b4.zip" MODEL_UTILS_VERSION=">2.0" TARGET='test-fancypages'
- DJANGO="https://github.com/django/django/archive/1.7c1.zip" MODEL_UTILS_VERSION=">2.0" TARGET='test-fancypages'
# FIXME: oscar_fancypages currently doesn't support Django 1.7
#- DJANGO="https://github.com/django/django/archive/1.7b4.zip" MODEL_UTILS_VERSION=">2.0" TARGET='test-oscar-fancypages' EXTRA_INSTALLS="git+https://github.com/elbaschid/django-oscar.git@add_support_for_django17#egg=django-oscar-dev"

Expand Down
24 changes: 12 additions & 12 deletions Makefile
Expand Up @@ -18,38 +18,38 @@ dev:
compile-static:
grunt

tests: test-fancypages test-oscar-fancypages
tests: test-standalone-fancypages test-oscar-fancypages

test-fancypages:
test-standalone-fancypages:
@echo "Running Test"
py.test ${PYTEST_OPTS}
@echo "Running PostgreSQL migrations"
${MAKE} test-postgres
${MAKE} test-standalone-postgres
@echo "Running MySQL migrations"
${MAKE} test-mysql
${MAKE} test-standalone-mysql

test-oscar-fancypages:
pip install ${PIP_OPTS} -r requirements_oscar.txt
DJANGO_CONFIGURATION='OscarTest' py.test ${PYTEST_OPTS}
${MAKE} test-ofp-postgres
${MAKE} test-ofp-mysql
${MAKE} test-oscar-postgres
${MAKE} test-oscar-mysql

test-postgres:
test-standalone-postgres:
- psql -h localhost -p ${DJANGO_POSTGRES_PORT} -U postgres -c "DROP DATABASE fp_sandbox;"
psql -h localhost -p ${DJANGO_POSTGRES_PORT} -U postgres -c "CREATE DATABASE fp_sandbox;"
DJANGO_CONFIGURATION="FancypagesPostgres" SANDBOX="fancypages" ./run-migrations.sh
DJANGO_CONFIGURATION="StandaloneFancypagesPostgres" SANDBOX="fancypages" ./run-migrations.sh

test-mysql:
test-standalone-mysql:
- mysql -h 127.0.0.1 -P ${DJANGO_MYSQL_PORT} -u root -e 'DROP DATABASE fp_sandbox;'
mysql -h 127.0.0.1 -P ${DJANGO_MYSQL_PORT} -u root -e 'CREATE DATABASE fp_sandbox;'
DJANGO_CONFIGURATION="FancypagesMysql" SANDBOX="fancypages" ./run-migrations.sh
DJANGO_CONFIGURATION="StandaloneFancypagesMysql" SANDBOX="fancypages" ./run-migrations.sh

test-ofp-postgres:
test-oscar-postgres:
- psql -h localhost -p ${DJANGO_POSTGRES_PORT} -U postgres -c "DROP DATABASE ofp_sandbox;"
psql -h localhost -p ${DJANGO_POSTGRES_PORT} -U postgres -c "CREATE DATABASE ofp_sandbox;"
DJANGO_CONFIGURATION="OscarFancypagesPostgres" SANDBOX="oscar_fancypages" ./run-migrations.sh

test-ofp-mysql:
test-oscar-mysql:
- mysql -h 127.0.0.1 -P ${DJANGO_MYSQL_PORT} -u root -e 'DROP DATABASE ofp_sandbox;'
mysql -h 127.0.0.1 -P ${DJANGO_MYSQL_PORT} -u root -e 'CREATE DATABASE ofp_sandbox;'
DJANGO_CONFIGURATION="OscarFancypagesMysql" SANDBOX="oscar_fancypages" ./run-migrations.sh
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Expand Up @@ -6,7 +6,7 @@


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')
os.environ.setdefault('DJANGO_CONFIGURATION', 'Test')
os.environ.setdefault('DJANGO_CONFIGURATION', 'StandaloneTest')


def pytest_configure():
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion sandboxes/fancypages/manage.py → sandbox/manage.py
Expand Up @@ -5,7 +5,7 @@

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
os.environ.setdefault("DJANGO_CONFIGURATION", "FancypagesSandbox")
os.environ.setdefault("DJANGO_CONFIGURATION", "StandaloneFancypages")

from configurations.management import execute_from_command_line

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions sandbox/settings/__init__.py
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import

from .fancypages import (StandaloneFancypages, # noqa
StandaloneFancypagesPostgres,
StandaloneFancypagesMysql)

from .oscar import (OscarFancypages, # noqa
OscarFancypagesPostgres,
OscarFancypagesMysql)
133 changes: 52 additions & 81 deletions sandboxes/fancypages/settings.py → sandbox/settings/common.py
@@ -1,30 +1,21 @@
# Django settings for sandbox project.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
import os
import django

from configurations import Configuration, values

import fancypages as fp

def get_location(*path):
""" Get absolute path for path relative to this file's directory. """
return os.path.join(os.path.dirname(os.path.realpath(__file__)), *path)
from configurations import Configuration, values


class FancypagesSandbox(Configuration):
class Common(Configuration):
DEBUG = True
TEMPLATE_DEBUG = DEBUG
SECRET_KEY = values.Value('insecure secret key')

# This is only required for South < 1.0. In version 1.0, South first checks
# for a 'south_migrations' directory before falling back to 'migrations'.
SOUTH_MIGRATION_MODULES = {
'fancypages': 'fancypages.south_migrations',
}

ADMINS = [('Your Name', 'your_email@example.com')]
ADMINS = [('Sebastian Vetter', 'svetter@snowballdigital.com.au')]
MANAGERS = ADMINS

SECRET_KEY = values.Value('insecure secret key')

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

USE_I18N = True
Expand All @@ -35,126 +26,106 @@ class FancypagesSandbox(Configuration):
LANGUAGE_CODE = 'en-gb'
LANGUAGES = (
('de', 'German'),
('en', 'English'),
)
('en', 'English'))

########## FANCYPAGES SETTINGS
FP_FORM_BLOCK_CHOICES = {
'contact-us': {
'name': "Contact Us Form",
'form': 'contact_us.forms.ContactUsForm',
'url': 'contact-us',
'template_name': 'contact_us/contact_us_form.html',
}
}
'template_name': 'contact_us/contact_us_form.html'}}
########## END FANCYPAGES SETTINGS

MEDIA_URL = '/media/'
MEDIA_ROOT = get_location('public/media')

STATIC_URL = '/static/'
STATIC_ROOT = get_location('public/static')
STATICFILES_DIRS = [get_location('static/')]
STATICFILES_DIRS = []
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
'django.contrib.staticfiles.finders.AppDirectoriesFinder')

TEMPLATE_DIRS = [get_location('templates')]
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.template.loaders.app_directories.Loader')
TEMPLATE_CONTEXT_PROCESSORS = [
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.request",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.contrib.messages.context_processors.messages",
)
MIDDLEWARE_CLASSES = (
"django.contrib.messages.context_processors.messages"]
MIDDLEWARE_CLASSES = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'fancypages.middleware.EditorMiddleware',
)

ROOT_URLCONF = 'urls'
'fancypages.middleware.EditorMiddleware']

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
'django.contrib.auth.backends.ModelBackend',)

LOGIN_URL = '/admin/login/'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'wsgi.application'

LOGIN_REDIRECT_URL = '/accounts/'
APPEND_SLASH = True
SITE_ID = 1

ALLOWED_HOSTS = ['*']
SITE_ID = 1

@property
def ROOT_URLCONF(self):
return "{}.urls".format(self.SANDBOX_MODULE)

@property
def WSGI_APPLICATION(self):
return "{}.wsgi.application".format(self.SANDBOX_MODULE)

@classmethod
def pre_setup(cls):
super(FancypagesSandbox, cls).pre_setup()
super(Common, cls).pre_setup()
from fancypages.defaults import FANCYPAGES_SETTINGS
for key, value in FANCYPAGES_SETTINGS.iteritems():
if not hasattr(cls, key):
setattr(cls, key, value)

DATABASES = {
'default': {
@property
def TEMPLATE_DIRS(self):
return [self.get_location('templates')]

@property
def MEDIA_ROOT(self):
return self.get_location('public/media')

@property
def STATIC_ROOT(self):
return self.get_location('public/static')

@property
def DATABASES(self):
return {'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': get_location('db.sqlite3')}}
'NAME': self.get_location('db.sqlite3')}}

@property
def INSTALLED_APPS(self):
import fancypages as fp
def REQUIRED_APPS(self):
apps = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
] + fp.get_required_apps() + fp.get_fancypages_apps()
'django.contrib.admin'] + fp.get_required_apps() + ['contact_us']

if django.VERSION[1] < 7:
apps.append('south')

return apps


class FancypagesPostgres(FancypagesSandbox):
POSTGRES_PORT = values.Value(5432)

@property
def DATABASES(self):
return {'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'fp_sandbox',
'USER': 'postgres',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': self.POSTGRES_PORT}}


class FancypagesMysql(FancypagesSandbox):
MYSQL_PORT = values.Value(3306)

@property
def DATABASES(self):
return {'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'fp_sandbox',
'USER': 'root',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': 3306}}
@classmethod
def get_location(cls, *path):
""" Get absolute path for path relative to this file's directory. """
path = (cls.SANDBOX_MODULE,) + path
return os.path.join(
os.path.dirname(os.path.realpath(__file__)), '..', *path)
43 changes: 43 additions & 0 deletions sandbox/settings/fancypages.py
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
from configurations import values

import fancypages as fp

from . import common


class StandaloneFancypages(common.Common):
SANDBOX_MODULE = 'standalone_fancypages'

@property
def INSTALLED_APPS(self):
return self.REQUIRED_APPS + fp.get_fancypages_apps()


class StandaloneFancypagesPostgres(StandaloneFancypages):
POSTGRES_PORT = values.Value(5432)

@property
def DATABASES(self):
return {'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'fp_sandbox',
'USER': 'postgres',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': self.POSTGRES_PORT}}


class StandaloneFancypagesMysql(StandaloneFancypages):
MYSQL_PORT = values.Value(3306)

@property
def DATABASES(self):
return {'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'fp_sandbox',
'USER': 'root',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': 3306}}

0 comments on commit e15539c

Please sign in to comment.