Пример #1
0
 def setUp(self):
     self.env = Env()
     self._orig_environ = os.environ
     os.environ = {}
     file_path = Path(__file__, is_file=True)('test_env.txt')
     self.env.read_env(file_path,
                       PATH_VAR=Path(__file__, is_file=True).__root__)
Пример #2
0
class FileEnvTests(EnvTests):
    def setUp(self):
        super(FileEnvTests, self).setUp()
        Env.ENVIRON = {}
        self.env = Env()
        file_path = Path(__file__, is_file=True)("test_env.txt")
        self.env.read_env(file_path, PATH_VAR=Path(__file__, is_file=True).__root__)
Пример #3
0
class FileEnvTests(EnvTests):

    def setUp(self):
        super(FileEnvTests, self).setUp()
        Env.ENVIRON = {}
        self.env = Env()
        file_path = Path(__file__, is_file=True)('test_env.txt')
        self.env.read_env(file_path, PATH_VAR=Path(__file__, is_file=True).__root__)
Пример #4
0
class FileEnvTests(EnvTests):

    def setUp(self):
        self.env = Env()
        self._orig_environ = os.environ
        os.environ = {}
        file_path = Path(__file__, is_file=True)('test_env.txt')
        self.env.read_env(file_path, PATH_VAR=Path(__file__, is_file=True).__root__)
Пример #5
0
    def test_database_options_parsing(self):
        url = 'postgres://*****:*****@host:1234/dbname?conn_max_age=600'
        url = Env.db_url_config(url)
        self.assertEqual(url['CONN_MAX_AGE'], 600)

        url = 'mysql://*****:*****@host:1234/dbname?init_command=SET storage_engine=INNODB'
        url = Env.db_url_config(url)
        self.assertEqual(url['OPTIONS'], {
            'init_command': 'SET storage_engine=INNODB',
        })
Пример #6
0
    def test_database_options_parsing(self):
        url = 'postgres://*****:*****@host:1234/dbname?conn_max_age=600'
        url = Env.db_url_config(url)
        self.assertEqual(url['CONN_MAX_AGE'], 600)

        url = 'mysql://*****:*****@host:1234/dbname?init_command=SET storage_engine=INNODB'
        url = Env.db_url_config(url)
        self.assertEqual(url['OPTIONS'], {
            'init_command': 'SET storage_engine=INNODB',
        })
Пример #7
0
def test_decrypt_env(monkeypatch):
    monkeypatch.setattr(Env, "ENVIRON", {
        "TEST_VAR": "ok",
        "TEST_DECRYPT": "prefix-{{ key-name }}-data"
    })

    store = MockStore({"key-name": "secret"})

    env = Env()
    resolve_django_environ(env, store)

    assert env.str("TEST_VAR") == "ok"
    assert env.str("TEST_DECRYPT") == "prefix-secret-data"
Пример #8
0
    def test_base_options_parsing(self):
        url = 'memcache://127.0.0.1:11211/?timeout=0&key_prefix=cache_&key_function=foo.get_key&version=1'
        url = Env.cache_url_config(url)

        self.assertEqual(url['KEY_PREFIX'], 'cache_')
        self.assertEqual(url['KEY_FUNCTION'], 'foo.get_key')
        self.assertEqual(url['TIMEOUT'], 0)
        self.assertEqual(url['VERSION'], 1)

        url = 'redis://127.0.0.1:6379/?timeout=None'
        url = Env.cache_url_config(url)

        self.assertEqual(url['TIMEOUT'], None)
Пример #9
0
    def test_base_options_parsing(self):
        url = 'memcache://127.0.0.1:11211/?timeout=0&key_prefix=cache_&key_function=foo.get_key&version=1'
        url = Env.cache_url_config(url)

        self.assertEqual(url['KEY_PREFIX'], 'cache_')
        self.assertEqual(url['KEY_FUNCTION'], 'foo.get_key')
        self.assertEqual(url['TIMEOUT'], 0)
        self.assertEqual(url['VERSION'], 1)

        url = 'redis://127.0.0.1:6379/?timeout=None'
        url = Env.cache_url_config(url)

        self.assertEqual(url['TIMEOUT'], None)
Пример #10
0
    def test_base_options_parsing(self):
        url = "memcache://127.0.0.1:11211/?timeout=0&key_prefix=cache_&key_function=foo.get_key&version=1"
        url = Env.cache_url_config(url)

        self.assertEqual(url["KEY_PREFIX"], "cache_")
        self.assertEqual(url["KEY_FUNCTION"], "foo.get_key")
        self.assertEqual(url["TIMEOUT"], 0)
        self.assertEqual(url["VERSION"], 1)

        url = "redis://127.0.0.1:6379/?timeout=None"
        url = Env.cache_url_config(url)

        self.assertEqual(url["TIMEOUT"], None)
Пример #11
0
    def test_database_options_parsing(self):
        url = 'postgres://*****:*****@host:1234/dbname?conn_max_age=600'
        url = Env.db_url_config(url)
        self.assertEqual(url['CONN_MAX_AGE'], 600)

        url = 'postgres://*****:*****@host:1234/dbname?conn_max_age=None&autocommit=True&atomic_requests=False'
        url = Env.db_url_config(url)
        self.assertEqual(url['CONN_MAX_AGE'], None)
        self.assertEqual(url['AUTOCOMMIT'], True)
        self.assertEqual(url['ATOMIC_REQUESTS'], False)

        url = 'mysql://*****:*****@host:1234/dbname?init_command=SET storage_engine=INNODB'
        url = Env.db_url_config(url)
        self.assertEqual(url['OPTIONS'], {
            'init_command': 'SET storage_engine=INNODB',
        })
Пример #12
0
    def test_postgres_parsing_unix_domain_socket(self):
        url = 'postgres:////var/run/postgresql/db'
        url = Env.db_url_config(url)

        self.assertEqual(url['ENGINE'], DJANGO_POSTGRES)
        self.assertEqual(url['NAME'], 'db')
        self.assertEqual(url['HOST'], '/var/run/postgresql')
Пример #13
0
    def test_postgres_parsing_unix_domain_socket(self):
        url = 'postgres:////var/run/postgresql/db'
        url = Env.db_url_config(url)

        self.assertEqual(url['ENGINE'], DJANGO_POSTGRES)
        self.assertEqual(url['NAME'], 'db')
        self.assertEqual(url['HOST'], '/var/run/postgresql')
Пример #14
0
def member_list(request):
    env = Env()
    MEMBERS_PASSWORD = env('MEMBERS_PASSWORD')

    # handle form submission
    if request.POST:
        pw_form = PasswordForm(request.POST)

        if pw_form.is_valid(
        ) and pw_form.cleaned_data['password'] == MEMBERS_PASSWORD:
            request.session['password'] = pw_form.cleaned_data['password']
            return redirect('members:member_list')

        messages.error(
            request,
            "The password you entered was incorrect, please try again.")

    # form not being submitted, check password
    if (request.session.get('password')
            and request.session['password'] == MEMBERS_PASSWORD):
        member_list = Member.objects.all()
        return render(request, 'members/member_list.html', {
            'member_list': member_list,
        })

    # password is wrong, render form
    pw_form = PasswordForm()
    return render(request, 'members/members_password_form.html', {
        'pw_form': pw_form,
    })
Пример #15
0
    def test_simple_parsing(self):
        url = Env.search_url_config(self.simple_url)

        self.assertEqual(url['ENGINE'],
                         'haystack.backends.simple_backend.SimpleEngine')
        self.assertTrue('INDEX_NAME' not in url)
        self.assertTrue('PATH' not in url)
Пример #16
0
    def test_dbcache_parsing(self):
        url = 'dbcache://my_cache_table'
        url = Env.cache_url_config(url)

        self.assertEqual(url['BACKEND'],
                         'django.core.cache.backends.db.DatabaseCache')
        self.assertEqual(url['LOCATION'], 'my_cache_table')
Пример #17
0
    def test_common_args_parsing(self):
        excluded_indexes = "myapp.indexes.A,myapp.indexes.B"
        include_spelling = 1
        batch_size = 100
        params = "EXCLUDED_INDEXES=%s&INCLUDE_SPELLING=%s&BATCH_SIZE=%s" % (
            excluded_indexes,
            include_spelling,
            batch_size,
        )
        for url in [
            self.solr_url,
            self.elasticsearch_url,
            self.whoosh_url,
            self.xapian_url,
            self.simple_url,
        ]:
            url = "?".join([url, params])
            url = Env.search_url_config(url)

            self.assertTrue("EXCLUDED_INDEXES" in url.keys())
            self.assertTrue("myapp.indexes.A" in url["EXCLUDED_INDEXES"])
            self.assertTrue("myapp.indexes.B" in url["EXCLUDED_INDEXES"])
            self.assertTrue("INCLUDE_SPELLING" in url.keys())
            self.assertTrue(url["INCLUDE_SPELLING"])
            self.assertTrue("BATCH_SIZE" in url.keys())
            self.assertEqual(url["BATCH_SIZE"], 100)
Пример #18
0
 def test_redis_socket_url(self):
     url = 'redis://:redispass@/path/to/socket.sock?db=0'
     url = Env.cache_url_config(url)
     self.assertEqual(REDIS_DRIVER, url['BACKEND'])
     self.assertEqual(url['LOCATION'],
                      'unix://:redispass@/path/to/socket.sock')
     self.assertEqual(url['OPTIONS'], {'DB': 0})
Пример #19
0
    def test_common_args_parsing(self):
        excluded_indexes = 'myapp.indexes.A,myapp.indexes.B'
        include_spelling = 1
        batch_size = 100
        params = 'EXCLUDED_INDEXES=%s&INCLUDE_SPELLING=%s&BATCH_SIZE=%s' % (
            excluded_indexes,
            include_spelling,
            batch_size
        )
        for url in [
            self.solr_url,
            self.elasticsearch_url,
            self.whoosh_url,
            self.xapian_url,
            self.simple_url,
        ]:
            url = '?'.join([url, params])
            url = Env.search_url_config(url)

            self.assertTrue('EXCLUDED_INDEXES' in url.keys())
            self.assertTrue('myapp.indexes.A' in url['EXCLUDED_INDEXES'])
            self.assertTrue('myapp.indexes.B' in url['EXCLUDED_INDEXES'])
            self.assertTrue('INCLUDE_SPELLING'in url.keys())
            self.assertTrue(url['INCLUDE_SPELLING'])
            self.assertTrue('BATCH_SIZE' in url.keys())
            self.assertEqual(url['BATCH_SIZE'], 100)
Пример #20
0
    def test_database_options_parsing(self):
        url = "postgres://*****:*****@host:1234/dbname?conn_max_age=600"
        url = Env.db_url_config(url)
        self.assertEqual(url["CONN_MAX_AGE"], 600)

        url = "postgres://*****:*****@host:1234/dbname?conn_max_age=None&autocommit=True&atomic_requests=False"
        url = Env.db_url_config(url)
        self.assertEqual(url["CONN_MAX_AGE"], None)
        self.assertEqual(url["AUTOCOMMIT"], True)
        self.assertEqual(url["ATOMIC_REQUESTS"], False)

        url = (
            "mysql://*****:*****@host:1234/dbname?init_command=SET storage_engine=INNODB"
        )
        url = Env.db_url_config(url)
        self.assertEqual(url["OPTIONS"], {"init_command": "SET storage_engine=INNODB",})
Пример #21
0
    def test_postgres_parsing_unix_domain_socket(self):
        url = "postgres:////var/run/postgresql/db"
        url = Env.db_url_config(url)

        self.assertEqual(url["ENGINE"], DJANGO_POSTGRES)
        self.assertEqual(url["NAME"], "db")
        self.assertEqual(url["HOST"], "/var/run/postgresql")
Пример #22
0
    def test_database_options_parsing(self):
        url = 'postgres://*****:*****@host:1234/dbname?conn_max_age=600'
        url = Env.db_url_config(url)
        self.assertEqual(url['CONN_MAX_AGE'], 600)

        url = 'postgres://*****:*****@host:1234/dbname?conn_max_age=None&autocommit=True&atomic_requests=False'
        url = Env.db_url_config(url)
        self.assertEqual(url['CONN_MAX_AGE'], None)
        self.assertEqual(url['AUTOCOMMIT'], True)
        self.assertEqual(url['ATOMIC_REQUESTS'], False)

        url = 'mysql://*****:*****@host:1234/dbname?init_command=SET storage_engine=INNODB'
        url = Env.db_url_config(url)
        self.assertEqual(url['OPTIONS'], {
            'init_command': 'SET storage_engine=INNODB',
        })
Пример #23
0
    def test_common_args_parsing(self):
        excluded_indexes = 'myapp.indexes.A,myapp.indexes.B'
        include_spelling = 1
        batch_size = 100
        params = 'EXCLUDED_INDEXES=%s&INCLUDE_SPELLING=%s&BATCH_SIZE=%s' % (
            excluded_indexes,
            include_spelling,
            batch_size
        )
        for url in [
            self.solr_url,
            self.elasticsearch_url,
            self.whoosh_url,
            self.xapian_url,
            self.simple_url,
        ]:
            url = '?'.join([url, params])
            url = Env.search_url_config(url)

            self.assertTrue('EXCLUDED_INDEXES' in url.keys())
            self.assertTrue('myapp.indexes.A' in url['EXCLUDED_INDEXES'])
            self.assertTrue('myapp.indexes.B' in url['EXCLUDED_INDEXES'])
            self.assertTrue('INCLUDE_SPELLING'in url.keys())
            self.assertTrue(url['INCLUDE_SPELLING'])
            self.assertTrue('BATCH_SIZE' in url.keys())
            self.assertEqual(url['BATCH_SIZE'], 100)
Пример #24
0
    def test_locmem_named_parsing(self):
        url = 'locmemcache://unique-snowflake'
        url = Env.cache_url_config(url)

        self.assertEqual(url['BACKEND'],
                         'django.core.cache.backends.locmem.LocMemCache')
        self.assertEqual(url['LOCATION'], 'unique-snowflake')
Пример #25
0
    def test_memcache_pylib_parsing(self):
        url = 'pymemcache://127.0.0.1:11211'
        url = Env.cache_url_config(url)

        self.assertEqual(url['BACKEND'],
                         'django.core.cache.backends.memcached.PyLibMCCache')
        self.assertEqual(url['LOCATION'], '127.0.0.1:11211')
Пример #26
0
    def test_dummycache_parsing(self):
        url = 'dummycache://'
        url = Env.cache_url_config(url)

        self.assertEqual(url['BACKEND'],
                         'django.core.cache.backends.dummy.DummyCache')
        self.assertEqual(url['LOCATION'], '')
Пример #27
0
 def test_redis_socket_url(self):
     url = 'redis://:redispass@/path/to/socket.sock?db=0'
     url = Env.cache_url_config(url)
     self.assertEqual(REDIS_DRIVER, url['BACKEND'])
     self.assertEqual(url['LOCATION'], 'unix://:redispass@/path/to/socket.sock')
     self.assertEqual(url['OPTIONS'], {
         'DB': 0
     })
Пример #28
0
 def test_memory_sqlite_url_warns_about_netloc(self):
     url = "sqlite://missing-slash-path"
     with warnings.catch_warnings(record=True) as w:
         url = Env.db_url_config(url)
         self.assertEqual(url["ENGINE"], "django.db.backends.sqlite3")
         self.assertEqual(url["NAME"], ":memory:")
         self.assertEqual(len(w), 1)
         self.assertTrue(issubclass(w[0].category, UserWarning))
Пример #29
0
    def test_memcache_pylib_parsing(self):
        url = "pymemcache://127.0.0.1:11211"
        url = Env.cache_url_config(url)

        self.assertEqual(
            url["BACKEND"], "django.core.cache.backends.memcached.PyLibMCCache"
        )
        self.assertEqual(url["LOCATION"], "127.0.0.1:11211")
Пример #30
0
    def test_memcache_socket_parsing(self):
        url = "memcache:///tmp/memcached.sock"
        url = Env.cache_url_config(url)

        self.assertEqual(
            url["BACKEND"], "django.core.cache.backends.memcached.MemcachedCache"
        )
        self.assertEqual(url["LOCATION"], "unix:/tmp/memcached.sock")
Пример #31
0
    def test_filecache_parsing(self):
        url = "filecache:///var/tmp/django_cache"
        url = Env.cache_url_config(url)

        self.assertEqual(
            url["BACKEND"], "django.core.cache.backends.filebased.FileBasedCache"
        )
        self.assertEqual(url["LOCATION"], "/var/tmp/django_cache")
Пример #32
0
    def test_filecache_windows_parsing(self):
        url = "filecache://C:/foo/bar"
        url = Env.cache_url_config(url)

        self.assertEqual(
            url["BACKEND"], "django.core.cache.backends.filebased.FileBasedCache"
        )
        self.assertEqual(url["LOCATION"], "C:/foo/bar")
Пример #33
0
    def test_locmem_named_parsing(self):
        url = "locmemcache://unique-snowflake"
        url = Env.cache_url_config(url)

        self.assertEqual(
            url["BACKEND"], "django.core.cache.backends.locmem.LocMemCache"
        )
        self.assertEqual(url["LOCATION"], "unique-snowflake")
Пример #34
0
    def test_custom_backend(self):
        url = "memcache://127.0.0.1:5400?foo=option&bars=9001"
        backend = "django_redis.cache.RedisCache"
        url = Env.cache_url_config(url, backend)

        self.assertEqual(url["BACKEND"], backend)
        self.assertEqual(url["LOCATION"], "127.0.0.1:5400")
        self.assertEqual(url["OPTIONS"], {"FOO": "option", "BARS": 9001,})
Пример #35
0
 def test_memory_sqlite_url_warns_about_netloc(self):
     url = 'sqlite://missing-slash-path'
     with warnings.catch_warnings(record=True) as w:
         url = Env.db_url_config(url)
         self.assertEqual(url['ENGINE'], 'django.db.backends.sqlite3')
         self.assertEqual(url['NAME'], ':memory:')
         self.assertEqual(len(w), 1)
         self.assertTrue(issubclass(w[0].category, UserWarning))
Пример #36
0
    def test_filecache_windows_parsing(self):
        url = 'filecache://C:/foo/bar'
        url = Env.cache_url_config(url)

        self.assertEqual(
            url['BACKEND'],
            'django.core.cache.backends.filebased.FileBasedCache')
        self.assertEqual(url['LOCATION'], 'C:/foo/bar')
Пример #37
0
 def _get_db_object(self, **options):
     if options['db_url']:
         db_object = Env.db_url_config(options['db_url'])
     else:
         db_object = settings.DATABASES['default']
     db_object['MASTER_USER'] = db_object['USER']
     db_object['MASTER_PASSWORD'] = db_object['PASSWORD']
     return db_object
Пример #38
0
    def test_filecache_parsing(self):
        url = 'filecache:///var/tmp/django_cache'
        url = Env.cache_url_config(url)

        self.assertEqual(
            url['BACKEND'],
            'django.core.cache.backends.filebased.FileBasedCache')
        self.assertEqual(url['LOCATION'], '/var/tmp/django_cache')
Пример #39
0
    def test_memcache_socket_parsing(self):
        url = 'memcache:///tmp/memcached.sock'
        url = Env.cache_url_config(url)

        self.assertEqual(
            url['BACKEND'],
            'django.core.cache.backends.memcached.MemcachedCache')
        self.assertEqual(url['LOCATION'], 'unix:/tmp/memcached.sock')
Пример #40
0
    def test_redis_parsing(self):
        url = 'rediscache://127.0.0.1:6379:1?client_class=django_redis.client.DefaultClient&password=secret'
        url = Env.cache_url_config(url)

        self.assertEqual(url['BACKEND'], 'django_redis.cache.RedisCache')
        self.assertEqual(url['LOCATION'], '127.0.0.1:6379:1')
        self.assertEqual(url['OPTIONS'], {
            'CLIENT_CLASS': 'django_redis.client.DefaultClient',
            'PASSWORD': '******',
        })
Пример #41
0
    def test_smtp_parsing(self):
        url = 'smtps://[email protected]:[email protected]:587'
        url = Env.email_url_config(url)

        self.assertEqual(url['EMAIL_BACKEND'], 'django.core.mail.backends.smtp.EmailBackend')
        self.assertEqual(url['EMAIL_HOST'], 'smtp.example.com')
        self.assertEqual(url['EMAIL_HOST_PASSWORD'], 'password')
        self.assertEqual(url['EMAIL_HOST_USER'], '*****@*****.**')
        self.assertEqual(url['EMAIL_PORT'], 587)
        self.assertEqual(url['EMAIL_USE_TLS'], True)
Пример #42
0
    def test_database_ldap_url(self):
        url = 'ldap://cn=admin,dc=nodomain,dc=org:[email protected]/'
        url = Env.db_url_config(url)

        self.assertEqual(url['ENGINE'], 'ldapdb.backends.ldap')
        self.assertEqual(url['HOST'], 'ldap.nodomain.org')
        self.assertEqual(url['PORT'], None)
        self.assertEqual(url['NAME'], 'ldap://ldap.nodomain.org')
        self.assertEqual(url['USER'], 'cn=admin,dc=nodomain,dc=org')
        self.assertEqual(url['PASSWORD'], 'some_secret_password')
Пример #43
0
    def test_cleardb_parsing(self):
        url = 'mysql://*****:*****@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true'
        url = Env.db_url_config(url)

        self.assertEqual(url['ENGINE'], 'django.db.backends.mysql')
        self.assertEqual(url['NAME'], 'heroku_97681db3eff7580')
        self.assertEqual(url['HOST'], 'us-cdbr-east.cleardb.com')
        self.assertEqual(url['USER'], 'bea6eb025ca0d8')
        self.assertEqual(url['PASSWORD'], '69772142')
        self.assertEqual(url['PORT'], None)
Пример #44
0
    def test_mysql_no_password(self):
        url = 'mysql://travis@localhost/test_db'
        url = Env.db_url_config(url)

        self.assertEqual(url['ENGINE'], 'django.db.backends.mysql')
        self.assertEqual(url['NAME'], 'test_db')
        self.assertEqual(url['HOST'], 'localhost')
        self.assertEqual(url['USER'], 'travis')
        self.assertEqual(url['PASSWORD'], '')
        self.assertEqual(url['PORT'], '')
Пример #45
0
    def test_redis_multi_location_parsing(self):
        url = 'rediscache://host1:6379,host2:6379,host3:9999/1'
        url = Env.cache_url_config(url)

        self.assertEqual(url['BACKEND'], REDIS_DRIVER)
        self.assertEqual(url['LOCATION'], [
            'redis://host1:6379/1',
            'redis://host2:6379/1',
            'redis://host3:9999/1',
        ])
Пример #46
0
    def test_postgres_parsing(self):
        url = 'postgres://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn'
        url = Env.db_url_config(url)

        self.assertEqual(url['ENGINE'], DJANGO_POSTGRES)
        self.assertEqual(url['NAME'], 'd8r82722r2kuvn')
        self.assertEqual(url['HOST'], 'ec2-107-21-253-135.compute-1.amazonaws.com')
        self.assertEqual(url['USER'], 'uf07k1i6d8ia0v')
        self.assertEqual(url['PASSWORD'], 'wegauwhgeuioweg')
        self.assertEqual(url['PORT'], 5431)
Пример #47
0
    def test_mysql_gis_parsing(self):
        url = 'mysqlgis://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn'
        url = Env.db_url_config(url)

        self.assertEqual(url['ENGINE'], 'django.contrib.gis.db.backends.mysql')
        self.assertEqual(url['NAME'], 'd8r82722r2kuvn')
        self.assertEqual(url['HOST'], 'ec2-107-21-253-135.compute-1.amazonaws.com')
        self.assertEqual(url['USER'], 'uf07k1i6d8ia0v')
        self.assertEqual(url['PASSWORD'], 'wegauwhgeuioweg')
        self.assertEqual(url['PORT'], 5431)
Пример #48
0
    def test_options_parsing(self):
        url = 'filecache:///var/tmp/django_cache?timeout=60&max_entries=1000&cull_frequency=0'
        url = Env.cache_url_config(url)

        self.assertEqual(url['BACKEND'], 'django.core.cache.backends.filebased.FileBasedCache')
        self.assertEqual(url['LOCATION'], '/var/tmp/django_cache')
        self.assertEqual(url['TIMEOUT'], 60)
        self.assertEqual(url['OPTIONS'], {
            'MAX_ENTRIES': 1000,
            'CULL_FREQUENCY': 0,
        })
Пример #49
0
    def test_solr_multicore_parsing(self):
        timeout = 360
        index = 'solr_index'
        url = '%s/%s?TIMEOUT=%s' % (self.solr_url, index, timeout)
        url = Env.search_url_config(url)

        self.assertEqual(url['ENGINE'], 'haystack.backends.solr_backend.SolrEngine')
        self.assertEqual(url['URL'], 'http://127.0.0.1:8983/solr/solr_index')
        self.assertEqual(url['TIMEOUT'], timeout)
        self.assertTrue('INDEX_NAME' not in url)
        self.assertTrue('PATH' not in url)
Пример #50
0
    def test_custom_backend(self):
        url = 'memcache://127.0.0.1:5400?foo=option&bars=9001'
        backend = 'django_redis.cache.RedisCache'
        url = Env.cache_url_config(url, backend)

        self.assertEqual(url['BACKEND'], backend)
        self.assertEqual(url['LOCATION'], '127.0.0.1:5400')
        self.assertEqual(url['OPTIONS'], {
            'FOO': 'option',
            'BARS': 9001,
        })
Пример #51
0
    def test_xapian_parsing(self):
        flags = 'myflags'
        url = '%s?FLAGS=%s' % (self.xapian_url, flags)
        url = Env.search_url_config(url)

        self.assertEqual(url['ENGINE'], 'haystack.backends.xapian_backend.XapianEngine')
        self.assertTrue('PATH' in url.keys())
        self.assertEqual(url['PATH'], '/home/search/xapian_index')
        self.assertTrue('FLAGS' in url.keys())
        self.assertEqual(url['FLAGS'], flags)
        self.assertTrue('INDEX_NAME' not in url)
Пример #52
0
    def test_elasticsearch_parsing(self):
        timeout = 360
        url = '%s?TIMEOUT=%s' % (self.elasticsearch_url, timeout)
        url = Env.search_url_config(url)

        self.assertEqual(url['ENGINE'], 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine')
        self.assertTrue('INDEX_NAME' in url.keys())
        self.assertEqual(url['INDEX_NAME'], 'index')
        self.assertTrue('TIMEOUT' in url.keys())
        self.assertEqual(url['TIMEOUT'], timeout)
        self.assertTrue('PATH' not in url)
Пример #53
0
    def test_whoosh_parsing(self):
        storage = 'file'  # or ram
        post_limit = 128 * 1024 * 1024
        url = '%s?STORAGE=%s&POST_LIMIT=%s' % (self.whoosh_url, storage, post_limit)
        url = Env.search_url_config(url)

        self.assertEqual(url['ENGINE'], 'haystack.backends.whoosh_backend.WhooshEngine')
        self.assertTrue('PATH' in url.keys())
        self.assertEqual(url['PATH'], '/home/search/whoosh_index')
        self.assertTrue('STORAGE' in url.keys())
        self.assertEqual(url['STORAGE'], storage)
        self.assertTrue('POST_LIMIT' in url.keys())
        self.assertEqual(url['POST_LIMIT'], post_limit)
        self.assertTrue('INDEX_NAME' not in url)
Пример #54
0
from django.core.exceptions import ImproperlyConfigured
from django.urls import reverse_lazy

from environ import Env

from inloop.accounts import constance as accounts_constance
from inloop.gitload import constance as gitload_constance
from inloop.solutions import constance as solutions_constance

if sys.getfilesystemencoding() != "utf-8":
    raise ImproperlyConfigured("LANG must be a utf-8 locale")

PACKAGE_DIR = Path(__file__).resolve().parent
BASE_DIR = PACKAGE_DIR.parent

env = Env()

SECRET_KEY = env("SECRET_KEY")
DEBUG = env.bool("DEBUG", default=False)
ALLOWED_HOSTS = [host.strip() for host in env.list("ALLOWED_HOSTS")]
INTERNAL_IPS = [ip.strip() for ip in env.list("INTERNAL_IPS", default="")]

SITE_ID = 1

INSTALLED_APPS = [
    "inloop.accounts",
    "inloop.common",
    "inloop.grading",
    "inloop.solutions",
    "inloop.tasks",
    "inloop.testrunner",
Пример #55
0
# -*- coding: utf-8 -*-
from multiprocessing import cpu_count

from environ import Env

env = Env()

bind = '0.0.0.0:80'

reload = env.bool('GUNICORN_RELOAD', default=False)
workers = env.int('GUNICORN_WORKERS', default=(cpu_count() * 2 + 1))

loglevel = env.str('GUNICORN_LOG_LEVEL', default='error')
errorlog = '-'  # stderr
accesslog = '-' if env.bool('GUNICORN_ACCESS_LOG', default=False) else None
Пример #56
0
REPO_PATH = dirname(PROJECT_PATH)
REPO_NAME = "op-accesso" or basename(REPO_PATH)

CONFIG_DIR = 'config'
CONFIG_PATH = join(REPO_PATH, CONFIG_DIR)

RESOURCE_DIR = 'resources'
RESOURCES_PATH = join(REPO_PATH, RESOURCE_DIR)

# Add our project to our pythonpath, this way we don't need to type our project
# name in our dotted import paths:
path.append(PROJECT_PATH)

# load environment variables
Env.read_env(normpath(join(CONFIG_PATH, '.env')))
env = Env()
########## END PATH CONFIGURATION


########## DEBUG CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = env.bool('DEBUG', False)

# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
TEMPLATE_DEBUG = DEBUG
########## END DEBUG CONFIGURATION


########## MANAGER CONFIGURATION
ADMIN_EMAIL = env.str('ADMIN_EMAIL', 'admin@%s.com' % PROJECT_NAME)
Пример #57
0
# Django settings for project project.
import os
from environ import Env, Path
import pathlib
from django.core.exceptions import ImproperlyConfigured

DEBUG = False


PROJECT_ROOT = pathlib.Path(__file__).parent.parent.parent
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

env = Env(DEBUG=(bool, False),)
Env.read_env('.env')
DEBUG = env('DEBUG')

ADMINS = (
    ('Greg Azevedo', '*****@*****.**'),
)

MANAGERS = ADMINS


# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'UTC'
Пример #58
0
REPO_PATH = dirname(PROJECT_PATH)
REPO_NAME = "open_partecipate" or basename(REPO_PATH)

CONFIG_DIR = 'config'
CONFIG_PATH = join(REPO_PATH, CONFIG_DIR)

RESOURCE_DIR = 'resources'
RESOURCES_PATH = join(REPO_PATH, RESOURCE_DIR)

# Add our project to our pythonpath, this way we don't need to type our project
# name in our dotted import paths:
path.append(PROJECT_PATH)

# load environment variables
Env.read_env(normpath(join(CONFIG_PATH, '.env')))
env = Env()
########## END PATH CONFIGURATION


########## DEBUG CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = env.bool('DEBUG', False)

# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
TEMPLATE_DEBUG = DEBUG
########## END DEBUG CONFIGURATION


########## MANAGER CONFIGURATION
ADMIN_EMAIL = env('ADMIN_EMAIL', default='admin@%s.com' % PROJECT_NAME)
Пример #59
0
import os

from environ import Env


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
assert os.path.isfile(os.path.join(BASE_DIR, 'manage.py'))

env = Env()
env.read_env(os.path.join(BASE_DIR, '.env'))

DEBUG = env.bool('DEBUG', default=False)
SECRET_KEY = env.str('SECRET_KEY', default=('' if not DEBUG else 'xxx'))

DATABASES = {
    'default': env.db_url(
        default='psql://*****:*****@postgres/tallessa',
    ),
}

CACHES = {'default': env.cache_url(default='locmemcache://')}

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

    'rest_framework',
Пример #60
0
from __future__ import absolute_import, unicode_literals
import os

from django import VERSION as DJANGO_VERSION
from django.utils.translation import ugettext_lazy as _
from environ import Env

env = Env()


######################
# MEZZANINE SETTINGS #
######################

# The following settings are already defined with default values in
# the ``defaults.py`` module within each of Mezzanine's apps, but are
# common enough to be put here, commented out, for conveniently
# overriding. Please consult the settings documentation for a full list
# of settings Mezzanine implements:
# http://mezzanine.jupo.org/docs/configuration.html#default-settings

# Controls the ordering and grouping of the admin menu.
#
# ADMIN_MENU_ORDER = (
#     ("Content", ("pages.Page", "blog.BlogPost",
#        "generic.ThreadedComment", (_("Media Library"), "media-library"),)),
#     ("Site", ("sites.Site", "redirects.Redirect", "conf.Setting")),
#     ("Users", ("auth.User", "auth.Group",)),
# )