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 and python-decouple deps.
  • Loading branch information
pmac committed Jul 31, 2015
1 parent c2731ea commit 142f116
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 50 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
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
4 changes: 4 additions & 0 deletions requirements/default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TODO use peep. will do when removing vendor.
python-decouple==2.3
dj-database-url==0.3.0
pathlib==1.0.1
74 changes: 43 additions & 31 deletions settings/base.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
import os
from os.path import abspath

from decouple import config, Csv
from dj_database_url import parse as db_url
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:///{}'.format(ROOT_PATH / 'basket.db'),
cast=db_url
),
}

ALLOWED_HOSTS = [
'.allizom.org',
'basket.mozilla.com',
'basket.mozilla.org',
]
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
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 +54,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 +111,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,15 +129,19 @@ 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()

Expand Down

0 comments on commit 142f116

Please sign in to comment.