def test_get_variable_that_is_not_in_python_file(self): with patch('varlet.input', lambda _: "'hello world'"): foo = variable("FOO") # we patched input to return hello world, so that is what we should # get back self.assertEqual(foo, "hello world") # it should be written to the Python file with open("variables.py") as f: self.assertEqual(f.read(), "FOO = 'hello world'\n") # a second call should get the value right back without prompting for input with patch('varlet.input') as m: foo = variable("FOO") self.assertFalse(m.called) self.assertEqual(foo, "hello world")
def test_get_variable_that_is_not_in_python_file_with_default(self, set_startup_hook): default = {"a": 123, (1,2): [1, "b"]} foo = variable("FOO", default=default) # set_startup_hook should be called so the prompt has an initial value self.assertTrue(set_startup_hook.called) # make sure the callback function returns the repr of the default value args, kwargs = set_startup_hook.call_args_list[0] self.assertEqual(args[0](), repr(default)) # it should be called with 0 args to reset the prompt self.assertEqual(set_startup_hook.call_args_list[1], ())
def test_non_valid_python_value(self, print_mock): def func(_, return_values=["asdf", "'foo'"]): return return_values.pop(0) # the first time input return asdf which is not Python # and the second time it returns 'foo' with patch('varlet.input', func): foo = variable("LAME") self.assertTrue("name 'asdf' is not defined" in "".join(map(repr, print_mock.call_args_list))) self.assertEqual(foo, "foo")
def test_non_repr_value(self, print_mock): def func(_, return_values=["object()", "'foo'"]): return return_values.pop(0) # the first time input return object() which is not repr # serializable, and the second time it returns 'foo', which is fine with patch('varlet.input', func): foo = variable("LAME") self.assertTrue("The value must have a repr" in "".join(map(repr, print_mock.call_args_list))) self.assertEqual(foo, "foo")
# # Path constructors # DJANGO_DIR = lambda *path: os.path.normpath( os.path.join(os.path.dirname(__file__), *path)) BASE_DIR = lambda *path: DJANGO_DIR("../", *path) # # System and Debugging # # SECURITY WARNING: don't run with debug turned on in production! # make this True in dev DEBUG = variable("DEBUG", default=False) DEFAULT_FROM_EMAIL = SERVER_EMAIL = '*****@*****.**' # allow the use of wildcards in the INTERAL_IPS setting class IPList(list): # do a unix-like glob match # E.g. '192.168.1.100' would match '192.*' def __contains__(self, ip): return any(fnmatch(ip, ip_pattern) for ip_pattern in self) INTERNAL_IPS = IPList(['10.*', '192.168.*']) ADMINS = variable("ADMINS", default=[("Matt", "*****@*****.**")]) # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = variable("SECRET_KEY", os.urandom(64).decode("latin1"))
import os from fnmatch import fnmatch from django.core.urlresolvers import reverse_lazy from django.contrib.messages import constants as messages from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP, LOGGING, AUTHENTICATION_BACKENDS from varlet import variable try: import pymysql pymysql.install_as_MySQLdb() except ImportError: # pragma: no cover pass here = lambda *path: os.path.normpath(os.path.join(os.path.dirname(__file__), *path)) ROOT = lambda *path: here("../", *path) DEBUG = variable("DEBUG", False) TEMPLATE_DEBUG = DEBUG FFMPEG_BINARY = ROOT("bin/ffmpeg") DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': variable("DB_NAME", 'language'), 'USER': variable("DB_USERNAME", 'root'), 'PASSWORD': variable("DB_PASSWORD", ""), 'HOST': variable("DB_HOST", 'localhost'), 'PORT': '', }, }
except ImportError as e: pass from django.core.urlresolvers import reverse_lazy from django.contrib.messages import constants as messages from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP, LOGGING, AUTHENTICATION_BACKENDS here = lambda *path: os.path.normpath( os.path.join(os.path.dirname(__file__), *path)) ROOT = lambda *path: here("../", *path) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = variable('SECRET_KEY', default=hashlib.sha1(os.urandom(64)).hexdigest()) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = variable('DEBUG', default=True) TEMPLATE_DEBUG = variable('TEMPLATE_DEBUG', default=True) TEMPLATE_DIRS = (here("templates"), ) ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth',
import os import hashlib from fnmatch import fnmatch from django.conf import global_settings from varlet import variable import pymysql pymysql.install_as_MySQLdb() PROJECT_DIR = lambda *args: os.path.abspath(os.path.join(os.path.dirname(__file__), *args)) ROOT_DIR = lambda *args: PROJECT_DIR("../", *args) DEBUG = variable('DEBUG', True) TEMPLATE_DEBUG = DEBUG NOTIFICATION_EMAIL = variable("NOTIFICATION_EMAIL", '*****@*****.**') SERVER_EMAIL = '*****@*****.**' # allow the use of wildcards in the INTERAL_IPS setting class IPList(list): # do a unix-like glob match # E.g. '192.168.1.100' would match '192.*' def __contains__(self, ip): for ip_pattern in self: if fnmatch(ip, ip_pattern): return True return False INTERNAL_IPS = IPList(['10.*', '192.168.*']) LOGGING_CONFIG = 'arcutils.logging.basic'
'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) ROOT_URLCONF = 'konstantin.urls' WSGI_APPLICATION = 'konstantin.wsgi.application' PHANTOMJS_BINARY = ROOT('konstantin/static/bin/phantomjs') CAPTURE_SCRIPT_PATH = ROOT('konstantin/static/bin/capture.js') BROKER_URL = variable("BROKER_URL", 'amqp://*****:*****@localhost:5672') CELERY_ACKS_LATE = True CELERY_RESULTS_BACKEND = 'amqp' # Internationalization # https://docs.djangoproject.com/en/1.6/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True
import os from fnmatch import fnmatch from django.conf import global_settings from varlet import variable import pymysql pymysql.install_as_MySQLdb() PROJECT_DIR = os.path.dirname(__file__) HOME_DIR = os.path.normpath(os.path.join(PROJECT_DIR, '../')) DEBUG = variable("DEBUG", default=False) TEMPLATE_DEBUG = DEBUG # if you're having trouble connecting to LDAP set this to True so you can login # to track, bypassing LDAP group checks LDAP_DISABLED = variable("LDAP_DISABLED", default=False) LDAP = { 'default': { 'host': "ldap://ldap-login.oit.pdx.edu", 'username': '******', 'password': '', 'search_dn': 'dc=pdx,dc=edu' } } # ('Your Name', '*****@*****.**'), ADMINS = variable("ADMINS", []) MANAGERS = ADMINS DATABASES = {
import os from fnmatch import fnmatch from django.conf import global_settings from varlet import variable PROJECT_DIR = os.path.dirname(__file__) HOME_DIR = os.path.normpath(os.path.join(PROJECT_DIR, '../')) DEBUG = variable("DEBUG", False) TEMPLATE_DEBUG = DEBUG # [('Your Name', '*****@*****.**')] ADMINS = variable("ADMINS", []) MANAGERS = ADMINS SERVER_EMAIL = '*****@*****.**' CAS_SERVER_URL = 'https://sso.pdx.edu/cas/login' AUTH_USER_MODEL = 'models.AdminUser' # allow the use of wildcards in the INTERAL_IPS setting class IPList(list): # do a unix-like glob match # E.g. '192.168.1.100' would match '192.*' def __contains__(self, ip): for ip_pattern in self: if fnmatch(ip, ip_pattern): return True return False
try: import pymysql pymysql.install_as_MySQLdb() except ImportError: pass here = lambda *path: os.path.normpath(os.path.join(os.path.dirname(__file__), *path)) ROOT = lambda *path: here("../", *path) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = variable("DEBUG", True) TEMPLATE_DEBUG = True ALLOWED_HOSTS = [] SESSION_COOKIE_DOMAIN = ".nip.io" # Application definition INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages',
from fnmatch import fnmatch from django.core.urlresolvers import reverse_lazy from django.contrib.messages import constants as messages from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP, LOGGING, AUTHENTICATION_BACKENDS from varlet import variable try: import pymysql pymysql.install_as_MySQLdb() except ImportError: pass here = lambda *path: os.path.normpath( os.path.join(os.path.dirname(__file__), *path)) ROOT = lambda *path: here("../", *path) DEBUG = variable("DEBUG", False) TEMPLATE_DEBUG = DEBUG DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': variable("DB_NAME", 'sandbox'), 'USER': variable("DB_USER", 'root'), 'PASSWORD': variable("DB_PASSWORD", ''), 'HOST': variable("DB_HOST", 'localhost'), 'PORT': '', } } ADMINS = [["ssean1", "*****@*****.**"]] """
pymysql.install_as_MySQLdb() except ImportError as e: pass from django.core.urlresolvers import reverse_lazy from django.contrib.messages import constants as messages from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP, LOGGING, AUTHENTICATION_BACKENDS here = lambda *path: os.path.normpath(os.path.join(os.path.dirname(__file__), *path)) ROOT = lambda *path: here("../", *path) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = variable('SECRET_KEY', default=hashlib.sha1(os.urandom(64)).hexdigest()) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = variable('DEBUG', default=True) TEMPLATE_DEBUG = variable('TEMPLATE_DEBUG', default=True) TEMPLATE_DIRS = ( here("templates"), ) ALLOWED_HOSTS = [] # Application definition
) from django.contrib.messages import constants as messages from django.core.urlresolvers import reverse_lazy from varlet import variable # # Path constructors # DJANGO_DIR = lambda *path: os.path.normpath(os.path.join(os.path.dirname(__file__), *path)) BASE_DIR = lambda *path: DJANGO_DIR("../", *path) # # Keys # ALMA_API_KEY = variable("ALMA_API_KEY") # # System and Debugging # # SECURITY WARNING: don't run with debug turned on in production! # make this True in dev DEBUG = variable("DEBUG", default=False) TEMPLATE_DEBUG = DEBUG DEFAULT_FROM_EMAIL = SERVER_EMAIL = '*****@*****.**' # allow the use of wildcards in the INTERAL_IPS setting class IPList(list): # do a unix-like glob match
import os from fnmatch import fnmatch from django.conf import global_settings from varlet import variable PROJECT_DIR = os.path.dirname(__file__) HOME_DIR = os.path.normpath(os.path.join(PROJECT_DIR, '../')) DEBUG = variable("DEBUG", False) TEMPLATE_DEBUG = DEBUG # [('Your Name', '*****@*****.**')] ADMINS = variable("ADMINS", []) MANAGERS = ADMINS SERVER_EMAIL = '*****@*****.**' CAS_SERVER_URL = 'https://sso.pdx.edu/cas/login' AUTH_USER_MODEL = 'models.AdminUser' # allow the use of wildcards in the INTERAL_IPS setting class IPList(list): # do a unix-like glob match # E.g. '192.168.1.100' would match '192.*' def __contains__(self, ip): for ip_pattern in self: if fnmatch(ip, ip_pattern): return True
import os from fnmatch import fnmatch from django.conf import global_settings from varlet import variable import pymysql pymysql.install_as_MySQLdb() PROJECT_DIR = os.path.dirname(__file__) HOME_DIR = os.path.normpath(os.path.join(PROJECT_DIR, '../')) DEBUG = variable("DEBUG", default=False) TEMPLATE_DEBUG = DEBUG # if you're having trouble connecting to LDAP set this to True so you can login # to track, bypassing LDAP group checks LDAP_DISABLED = variable("LDAP_DISABLED", default=False) LDAP = { 'default': { 'host': "ldap://ldap-login.oit.pdx.edu", 'username': '******', 'password': '', 'search_dn': 'dc=pdx,dc=edu' } } # ('Your Name', '*****@*****.**'), ADMINS = variable("ADMINS", []) MANAGERS = ADMINS
from fnmatch import fnmatch from django.core.urlresolvers import reverse_lazy from django.contrib.messages import constants as messages from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP, LOGGING, AUTHENTICATION_BACKENDS from varlet import variable try: import pymysql pymysql.install_as_MySQLdb() except ImportError: # pragma: no cover pass here = lambda *path: os.path.normpath( os.path.join(os.path.dirname(__file__), *path)) ROOT = lambda *path: here("../", *path) DEBUG = variable("DEBUG", False) TEMPLATE_DEBUG = DEBUG FFMPEG_BINARY = ROOT("bin/ffmpeg") DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': variable("DB_NAME", 'language'), 'USER': variable("DB_USERNAME", 'root'), 'PASSWORD': variable("DB_PASSWORD", ""), 'HOST': variable("DB_HOST", 'localhost'), 'PORT': '', }, }