Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Get config variables from the environment.
Browse files Browse the repository at this point in the history
Add dj-database-url, django-cache-url, and python-decouple deps.
  • Loading branch information
pmac committed Aug 14, 2015
1 parent e905a4a commit d95b633
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
settings/local.py
*.py[co]
*.sw[po]
.env
.coverage
pip-log.txt
docs/_build
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ script: py.test --cov news
before_install:
- git submodule update --init --recursive
install:
- pip install -r requirements/compiled.txt -r requirements/dev.txt
- pip install -r requirements/compiled.txt -r requirements/dev.txt -r requirements/default.txt
- pip install coveralls
after_success:
# Report coverage results to coveralls.io
Expand Down
22 changes: 3 additions & 19 deletions news/tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ def test_unset_lang(self):
self.assertEqual(expected_result, result)


@override_settings(EXACTTARGET_DATA='data',
EXACTTARGET_OPTIN_STAGE='optin',
EXACTTARGET_CONFIRMATION='confirmation')
class TestGetUserData(TestCase):

def check_get_user(self, master, optin, confirm, error, expected_result):
Expand Down Expand Up @@ -373,25 +376,6 @@ def mock_look_for_user(database, email, token, fields):

self.assertEqual(expected_result, result)

def test_setting_are_sane(self):
# This is more to test that the settings are sane for running the
# tests and complain loudly, than to test the code.
# We need settings for the data table names,
# and also verify that all the table name settings are
# different.
self.assertTrue(hasattr(settings, 'EXACTTARGET_DATA'))
self.assertTrue(settings.EXACTTARGET_DATA)
self.assertTrue(hasattr(settings, 'EXACTTARGET_OPTIN_STAGE'))
self.assertTrue(settings.EXACTTARGET_OPTIN_STAGE)
self.assertTrue(hasattr(settings, 'EXACTTARGET_CONFIRMATION'))
self.assertTrue(settings.EXACTTARGET_CONFIRMATION)
self.assertNotEqual(settings.EXACTTARGET_DATA,
settings.EXACTTARGET_OPTIN_STAGE)
self.assertNotEqual(settings.EXACTTARGET_DATA,
settings.EXACTTARGET_CONFIRMATION)
self.assertNotEqual(settings.EXACTTARGET_OPTIN_STAGE,
settings.EXACTTARGET_CONFIRMATION)

def test_not_in_et(self):
# User not in Exact Target, return None
self.check_get_user(None, None, None, False, None)
Expand Down
5 changes: 5 additions & 0 deletions requirements/default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# TODO use peep. will do when removing vendor.
python-decouple==2.3
dj-database-url==0.3.0
django-cache-url==1.0.0
pathlib==1.0.1
22 changes: 9 additions & 13 deletions settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import os
import sys

if os.getenv('TRAVIS', False):
from settings.travis import * # noqa
else:
try:
from settings.local import * # noqa
except ImportError:
try:
from settings.local import * # noqa
from settings.base import * # noqa
except ImportError:
try:
from settings.base import * # noqa
except ImportError:
sys.stderr.write(
"Error: Tried importing 'settings.local' and 'settings.base' "
"but neither could be found (or they're throwing an "
"ImportError). Please fix and try again.")
raise
sys.stderr.write(
"Error: Tried importing 'settings.local' and 'settings.base' "
"but neither could be found (or they're throwing an "
"ImportError). Please fix and try again.")
raise


CACHES['bad_message_ids'] = {
Expand Down
87 changes: 50 additions & 37 deletions settings/base.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
import os
from os.path import abspath

import dj_database_url
import django_cache_url
from decouple import config, Csv
from pathlib import Path

# Application version.
VERSION = (0, 1)

# Make filepaths relative to settings.
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# ROOT path of the project. A pathlib.Path object.
ROOT_PATH = Path(__file__).resolve().parents[1]
ROOT = str(ROOT_PATH)


def path(*args):
# makes flake8 happier than a lambda
return os.path.join(ROOT, *args)
return abspath(str(ROOT_PATH.joinpath(*args)))


DEBUG = True
DEBUG = config('DEBUG', default=False, cast=bool)
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS
# avoids a warning from django
TEST_RUNNER = 'django.test.runner.DiscoverRunner'

# Production uses MySQL, but Sqlite should be sufficient for local development.
# Our CI server tests against MySQL. See travis.py in this directory
# for an example if you'd like to run MySQL locally, and add that to your
# local.py.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'basket.db',
}
'default': config('DATABASE_URL',
default='sqlite:///basket.db',
cast=dj_database_url.parse),
}
if DATABASES['default']['ENGINE'] == 'django.db.backends.mysql':
DATABASES['default']['OPTIONS'] = {'init_command': 'SET storage_engine=InnoDB'}

ALLOWED_HOSTS = [
'.allizom.org',
'basket.mozilla.com',
'basket.mozilla.org',
]
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
CACHES = {
'default': config('CACHE_URL',
default='locmem://',
cast=django_cache_url.parse)
}

ALLOWED_HOSTS = config('ALLOWED_HOSTS',
default='.allizom.org, basket.mozilla.com, basket.mozilla.org',
cast=Csv())
SESSION_COOKIE_SECURE = config('SESSION_COOKIE_SECURE', True, cast=bool)
CSRF_COOKIE_SECURE = config('CSRF_COOKIE_SECURE', True, cast=bool)

TIME_ZONE = 'America/Los_Angeles'
USE_TZ = True
Expand All @@ -49,7 +61,7 @@ def path(*args):
STATIC_URL = '/static/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = '0D8AE44F-5714-40EF-9AC8-4AC6EB556161'
SECRET_KEY = config('SECRET_KEY')

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
Expand Down Expand Up @@ -106,13 +118,16 @@ def path(*args):
DEFAULT_WELCOME_MESSAGE_ID = '39'

# Name of the database where we put someone's token when they confirm
EXACTTARGET_CONFIRMATION = 'Confirmation'
EXACTTARGET_INTERESTS = 'GET_INVOLVED'
EXACTTARGET_USE_SANDBOX = False

# This is a token that bypasses the news app auth in certain ways to
# make debugging easier
# SUPERTOKEN = <token>
EXACTTARGET_CONFIRMATION = config('EXACTTARGET_CONFIRMATION', None)
EXACTTARGET_INTERESTS = config('EXACTTARGET_INTERESTS', None)
EXACTTARGET_USE_SANDBOX = config('EXACTTARGET_USE_SANDBOX', False, cast=bool)
EXACTTARGET_USER = config('EXACTTARGET_USER', None)
EXACTTARGET_PASS = config('EXACTTARGET_PASS', None)
EXACTTARGET_DATA = config('EXACTTARGET_DATA', None)
EXACTTARGET_OPTIN_STAGE = config('EXACTTARGET_OPTIN_STAGE', None)
SUPERTOKEN = config('SUPERTOKEN')
ET_CLIENT_ID = config('ET_CLIENT_ID', None)
ET_CLIENT_SECRET = config('ET_CLIENT_SECRET', None)

CORS_ORIGIN_ALLOW_ALL = True
CORS_URLS_REGEX = r'^/news/.*$'
Expand All @@ -121,24 +136,22 @@ def path(*args):
RATELIMIT_VIEW = 'news.views.ratelimited'

# Uncomment these to use Celery, use eager for local dev
CELERY_ALWAYS_EAGER = False
BROKER_HOST = 'localhost'
BROKER_PORT = 5672
BROKER_USER = 'basket'
BROKER_PASSWORD = 'basket'
BROKER_VHOST = 'basket'
CELERY_ALWAYS_EAGER = config('CELERY_ALWAYS_EAGER', DEBUG, cast=bool)
BROKER_HOST = config('BROKER_HOST', 'localhost')
BROKER_PORT = config('BROKER_PORT', 5672, cast=int)
BROKER_USER = config('BROKER_USER', 'basket')
BROKER_PASSWORD = config('BROKER_PASSWORD', 'basket')
BROKER_VHOST = config('BROKER_VHOST', 'basket')
CELERY_DISABLE_RATE_LIMITS = True
CELERY_IGNORE_RESULT = True

STATSD_HOST = config('STATSD_HOST', 'localhost')
STATSD_PORT = config('STATSD_PORT', 8125, cast=int)
STATSD_PREFIX = config('STATSD_PREFIX', None)

import djcelery # noqa
djcelery.setup_loader()

CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
},
}

LOGGING = {
'version': 1,
'disable_existing_loggers': True,
Expand Down
26 changes: 0 additions & 26 deletions settings/travis.py

This file was deleted.

0 comments on commit d95b633

Please sign in to comment.