class DeploymentConfig(object): # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'replacethiswithsomethingsecret' # SECURITY WARNING: don't run with debug turned on in production! # Set this to True while you are developing DEBUG = BooleanValue(True) POLIS_SITE_ID = Value(None) # Unrestricted staging key (disposable) GMAPS_API_KEY = Value('AIzaSyDVJdClcbq1ioJUeySpPgNiDndQEspN6Ck') # Set this to a "frozen version" in production # See: https://developers.google.com/maps/documentation/javascript/versions#the-frozen-version GMAPS_API_VERSION = Value('3.exp') # See: https://django-configurations.readthedocs.org/en/stable/values/#configurations.values.DatabaseURLValue DATABASES = DatabaseURLValue('sqlite:///tor_councilmatic.db') # See: https://django-configurations.readthedocs.org/en/stable/values/#configurations.values.SearchURLValue # See: https://github.com/dstufft/dj-search-url HAYSTACK_CONNECTIONS = SearchURLValue('simple://') # See: https://django-configurations.readthedocs.org/en/stable/values/#configurations.values.CacheURLValue # See: https://github.com/ghickman/django-cache-url CACHES = CacheURLValue('dummy://') # Set this to flush the cache at /flush-cache/{FLUSH_KEY} FLUSH_KEY = 'super secret junk' # Set this to allow Disqus comments to render DISQUS_SHORTNAME = None # analytics tracking code ANALYTICS_TRACKING_CODE = Value('') HEADSHOT_PATH = os.path.join(os.path.dirname(__file__), '..' '/toronto/static/images/') EXTRA_APPS = ()
def test_boolean_values_assign_false_to_another_booleanvalue(self): value1 = BooleanValue(False) value2 = BooleanValue(value1) self.assertFalse(value1.setup('TEST1')) self.assertFalse(value2.setup('TEST2'))
def test_boolean_values_false(self): value = BooleanValue(True) for falsy in value.false_values: with env(DJANGO_TEST=falsy): self.assertFalse(bool(value.setup('TEST')))
def test_boolean_values_true(self): value = BooleanValue(False) for truthy in value.true_values: with env(DJANGO_TEST=truthy): self.assertTrue(bool(value.setup('TEST')))
class Base(Configuration): SECRET_KEY = SecretValue(environ_prefix=None, environ_required=True, environ_name="SECRET_KEY") DEBUG = BooleanValue(environ_prefix=None, environ_name="DEBUG", default=True) ALLOWED_HOSTS = ListValue(environ_prefix=None, environ_required=True, environ_name="ALLOWED_HOSTS") # Application definition INSTALLED_APPS = [ "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", "cryptprice", ] MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", ] ROOT_URLCONF = "core.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [], "APP_DIRS": True, "OPTIONS": { "context_processors": [ "django.template.context_processors.debug", "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", ], }, }, ] WSGI_APPLICATION = "core.wsgi.application" DATABASES = {"default": {}} AUTH_PASSWORD_VALIDATORS = [ { "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, { "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, { "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] LANGUAGE_CODE = "en-us" TIME_ZONE = "UTC" USE_I18N = True USE_L10N = True USE_TZ = True STATIC_URL = "/static/" # ----> SLACK CONFIGURATION <------ SLACK_BOT_USER_OAUTH_ACCESS_TOKEN = SecretValue( environ_prefix=None, environ_required=True, environ_name="SLACK_BOT_USER_OAUTH_ACCESS_TOKEN", ) SLACK_CLIENT_ID = SecretValue(environ_prefix=None, environ_required=True, environ_name="SLACK_CLIENT_ID") SLACK_CLIENT_SECRET = SecretValue(environ_prefix=None, environ_required=True, environ_name="SLACK_CLIENT_SECRET") SLACK_VERIFICATION_TOKEN = SecretValue( environ_prefix=None, environ_required=True, environ_name="SLACK_VERIFICATION_TOKEN", )
def test_boolean_values_nonboolean(self): value = BooleanValue(True) with env(DJANGO_TEST='nonboolean'): self.assertRaises(ValueError, value.setup, 'TEST')
def test_boolean_values_false(self): value = BooleanValue(True) for falsy in value.false_values: with env(DJANGO_TEST=falsy): self.assertFalse(value.setup('TEST'))
def test_boolean_values_true(self): value = BooleanValue(False) for truthy in value.true_values: with env(DJANGO_TEST=truthy): self.assertTrue(value.setup('TEST'))
class Test(Configuration): BASE_DIR = os.path.abspath( os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir)) ENV_LOADED = BooleanValue(False) DEBUG = True SITE_ID = 1 SECRET_KEY = str(uuid.uuid4()) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(os.path.dirname(__file__), 'test.db'), } } INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.contenttypes', 'django.contrib.sites', 'django.contrib.auth', 'tests', ] ROOT_URLCONF = 'tests.urls' if django.VERSION[:2] < (1, 6): TEST_RUNNER = 'discover_runner.DiscoverRunner' @property def ALLOWED_HOSTS(self): allowed_hosts = super().ALLOWED_HOSTS[:] allowed_hosts.append('base') return allowed_hosts ATTRIBUTE_SETTING = True _PRIVATE_SETTING = 'ryan' @property def PROPERTY_SETTING(self): return 1 def METHOD_SETTING(self): return 2 LAMBDA_SETTING = lambda self: 3 # noqa: E731 PRISTINE_LAMBDA_SETTING = pristinemethod(lambda: 4) @pristinemethod def PRISTINE_FUNCTION_SETTING(): return 5 @classmethod def pre_setup(cls): cls.PRE_SETUP_TEST_SETTING = 6 @classmethod def post_setup(cls): cls.POST_SETUP_TEST_SETTING = 7
class Production(Configuration): SECRET_KEY = SecretValue(environ_name="SECRET_KEY", environ_prefix=None, environ_required=True) DEBUG = BooleanValue(environ_name="DEBUG", environ_prefix=None, default=False) ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.messages", "django.contrib.staticfiles", "rest_framework", "inistock", "corsheaders" ] MIDDLEWARE = [ "corsheaders.middleware.CorsMiddleware", "django.middleware.security.SecurityMiddleware", "django.middleware.common.CommonMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", ] ROOT_URLCONF = "core.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [], "APP_DIRS": True, "OPTIONS": { "context_processors": [ "django.template.context_processors.debug", "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", ], }, }, ] WSGI_APPLICATION = "core.wsgi.application" DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql_psycopg2", "NAME": SecretValue( environ_name="POSTGRES_DB_NAME", environ_prefix=None, environ_required=True, ), "USER": SecretValue( environ_name="POSTGRES_DB_USERNAME", environ_prefix=None, environ_required=True, ), "PASSWORD": SecretValue( environ_name="POSTGRES_DB_PASSWORD", environ_prefix=None, environ_required=True, ), "HOST": SecretValue(environ_name="POSTGRES_HOST", environ_prefix=None, environ_required=True), "PORT": SecretValue(environ_name="POSTGRES_PORT", environ_prefix=None, environ_required=True), } } AUTH_PASSWORD_VALIDATORS = [ { "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, { "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, { "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] REST_FRAMEWORK = { "EXCEPTION_HANDLER": "inistock.exceptions.exception_handler.custom_exception_handler" } LANGUAGE_CODE = "en-us" TIME_ZONE = "UTC" USE_I18N = True USE_L10N = True USE_TZ = True STATIC_URL = "/static/" CORS_ORIGIN_ALLOW_ALL = True CORS_ALLOW_CREDENTIALS = True CORS_ALLOW_HEADERS = [ 'accept', 'accept-encoding', 'authorization', 'content-type', 'dnt', 'origin', "person-id" ]
class Test(Configuration): ENV_LOADED = BooleanValue(False) DEBUG = True SITE_ID = 1 SECRET_KEY = str(uuid.uuid4()) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(os.path.dirname(__file__), 'test.db'), } } INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.contenttypes', 'django.contrib.sites', 'django.contrib.auth', 'django.contrib.admin', 'tests', ] ROOT_URLCONF = 'tests.urls' if django.VERSION[:2] < (1, 6): TEST_RUNNER = 'discover_runner.DiscoverRunner' def TEMPLATE_CONTEXT_PROCESSORS(self): return tuple(Configuration.TEMPLATE_CONTEXT_PROCESSORS) + ( 'tests.settings.base.test_callback', ) ATTRIBUTE_SETTING = True _PRIVATE_SETTING = 'ryan' @property def PROPERTY_SETTING(self): return 1 def METHOD_SETTING(self): return 2 LAMBDA_SETTING = lambda self: 3 PRISTINE_LAMBDA_SETTING = pristinemethod(lambda: 4) @pristinemethod def PRISTINE_FUNCTION_SETTING(): return 5 @classmethod def pre_setup(cls): cls.PRE_SETUP_TEST_SETTING = 6 @classmethod def post_setup(cls): cls.POST_SETUP_TEST_SETTING = 7