Ejemplo n.º 1
0
    def test_path_class(self):

        root = Path(__file__, '..', is_file=True)
        root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))
        self.assertEqual(root(), root_path)
        self.assertEqual(root.__root__, root_path)

        web = root.path('public')
        self.assertEqual(web(), os.path.join(root_path, 'public'))
        self.assertEqual(web('css'), os.path.join(root_path, 'public', 'css'))
Ejemplo n.º 2
0
from os import path

from environ import Path, Env

# Django-environ basics
root = Path(__file__) - 2
env = Env(DEBUG=(bool, False),)

# Read a file with environment variables, these variables can be used to set the value of django settings
ENV_FILE = str(env.path('ENV_FILE', default='.env'))
if path.isfile(ENV_FILE):
    Env.read_env(ENV_FILE)
else:
    # unset if no file was found
    ENV_FILE = None

# Build paths inside the project like this: path.join(BASE_DIR, ...)
BASE_DIR = root()

# Django Debug option
DEBUG = env.bool('DEBUG')

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env('SECRET_KEY', default='xt515nl958u+8sbk_e($p%g_$olz9)!y)8+snv*yhsk1!hm(_c')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=[])

# Application definition
Ejemplo n.º 3
0
Django settings for config project.
Generated by 'django-admin startproject' using Django 1.11.4.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
from __future__ import absolute_import
from environ import Path, Env
import os

#####################################
# LOCAL VARS
#####################################

ROOT_DIR = Path(__file__) - 2
APPS_DIR = ROOT_DIR.path('apps')
environ = Env()

#####################################
# SECURITY SETTINGS
#####################################

SECRET_KEY = environ('DJANGO_SECRET_KEY', default='CHANGEME!!!')

DEBUG = environ.bool('DJANGO_DEBUG', False)

ALLOWED_HOSTS = environ.list('DJANGO_ALLOWED_HOSTS',
                             default=['www.yourdomain.com'])

#####################################
Ejemplo n.º 4
0
import environ
from environ import Path
root = Path('/')

env = environ.Env(
    NUMBER_OF_USERS=(int, 0),
    MAX_POSTS_PER_USER=(int, 0),
    MAX_LIKES_PER_USER=(int, 0),
    USERS_URL=(str, 'http://127.0.0.1:8000/api/v1/users/'),
    POSTS_URL=(str, 'http://127.0.0.1:8000/api/v1/posts/'),
    GET_TOKEN_URL=(str, 'http://127.0.0.1:8000/api/v1/auth/token/'),
    REFRESH_TOKEN_URL=(str,
                       'http://127.0.0.1:8000/api/v1/auth/token/refresh/'),
    ANALYTICS_URL=(str, 'http://127.0.0.1:8000/api/v1/analytics/'),
)

environ.Env.read_env()
Ejemplo n.º 5
0
from environ import Env, Path

root = Path(__file__) - 2  # two folders up
BASE_DIR = root()

# set default values and casting
env = Env(DEBUG=(bool, False), )
Env.read_env()

DEBUG = env('DEBUG')

SECRET_KEY = env('SECRET_KEY')

ALLOWED_HOSTS = ['.nova.jobs']

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'compressor',
    #'core',
    #'signup',
    #'scheduler',
    #'review',
    'homepage',
)
if DEBUG:
    INSTALLED_APPS += (
        'django.contrib.admin',
Ejemplo n.º 6
0
"""Django settings for Startup Organizer Project

Built during Andrew Pinkham's class on Safari Books Online.

https://docs.djangoproject.com/en/2.2/topics/settings/
https://docs.djangoproject.com/en/2.2/ref/settings/
https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
"""

from environ import Env, Path

from .. import checks  # noqa: F401

ENV = Env()

BASE_DIR = Path(__file__) - 3

SECRET_KEY = ENV.str("SECRET_KEY")

DEBUG = ENV.bool("DEBUG", default=False)

ALLOWED_HOSTS = ENV.list(
    "ALLOWED_HOSTS",
    default=["localhost", "127.0.0.1", "0.0.0.0", "::1"],
)

# Application definition

INSTALLED_APPS = [
    "whitenoise.runserver_nostatic",
    "django.contrib.admin",
Ejemplo n.º 7
0
class BaseConfiguration(Configuration):

    DJANGO_SETTINGS_MODULE = values.Value(environ_prefix=None,
                                          default='config.settings.local')

    PROJECT_NAME = 'Orchid'

    BASE_DIR = Path(
        __file__
    ) - 3  # orchid/portfolio/config/settings/base.py - 3 = orchid/portfolio/
    ROOT_URLCONF = 'config.urls'
    WSGI_APPLICATION = 'config.wsgi.application'

    # TODO: make secret key an environment variable
    SECRET_KEY = values.Value(environ_prefix=None, default='LOCAL')

    # Development configuration
    DEBUG = values.BooleanValue(environ_prefix=None, default=True)

    ALLOWED_HOSTS = values.ListValue(['*'])

    DJANGO_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
    ]

    CUSTOM_APPS = [
        # Project apps by dependency chain
        'dashboard',
        'articles',
        'gallery',
        'works',
    ]

    INSTALLED_APPS = DJANGO_APPS + CUSTOM_APPS

    MIDDLEWARE = [
        'django.middleware.security.SecurityMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        # Temporarily disabled for development until I sort out cookies and CSRF tokens.
        # 'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
    ]

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [(BASE_DIR + 'templates/'), (BASE_DIR + '/templates/')],
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.template.context_processors.media',
                    'django.template.context_processors.static',
                    'django.contrib.messages.context_processors.messages',
                ],
            },
        },
    ]

    # Media
    MEDIA_URL = '/media/'
    MEDIA_ROOT = str(BASE_DIR) + 'media/'

    # Data storage
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'orchid',
            'HOST': '127.0.0.1',
            'PORT': '5432',
        }
    }

    # Password validation
    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',
        },
    ]

    # Internationalisation
    LANGUAGE_CODE = 'en-gb'
    USE_I18N = True
    USE_L10N = True
    TIME_ZONE = 'UTC'
    USE_TZ = True

    #
    #   Static files
    #

    # This is the folder where static files are
    STATIC_URL = '/static/'

    # Folder where static files are searched by Django
    STATICFILES_DIRS = [
        join(str(BASE_DIR), 'static'),
        join(str(BASE_DIR), 'media'),
    ]

    # Where staticfiles are collected into
    STATIC_ROOT = str(BASE_DIR) + '/builds/'
Ejemplo n.º 8
0
    def test_comparison(self):

        self.assertTrue(Path('/home') in Path('/'))
        self.assertTrue(Path('/home') not in Path('/other/dir'))

        self.assertTrue(Path('/home') == Path('/home'))
        self.assertTrue(Path('/home') != Path('/home/dev'))

        self.assertEqual(
            Path('/home/foo/').rfind('/'),
            str(Path('/home/foo')).rfind('/'))
        self.assertEqual(
            Path('/home/foo/').find('/home'),
            str(Path('/home/foo/')).find('/home'))
        self.assertEqual(Path('/home/foo/')[1], str(Path('/home/foo/'))[1])

        self.assertEqual(~Path('/home'), Path('/'))
        self.assertEqual(Path('/') + 'home', Path('/home'))
        self.assertEqual(Path('/') + '/home/public', Path('/home/public'))
        self.assertEqual(Path('/home/dev/public') - 2, Path('/home'))
        self.assertEqual(
            Path('/home/dev/public') - 'public', Path('/home/dev'))

        self.assertRaises(TypeError, lambda _: Path('/home/dev/') - 'not int')
Ejemplo n.º 9
0
 def test_path(self):
     root = self.env.path('PATH_VAR')
     self.assertTypeAndValue(Path, Path(self.PATH), root)