Exemplo n.º 1
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',
        })
Exemplo n.º 2
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',
        })
Exemplo n.º 3
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',
        })
Exemplo n.º 4
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')
Exemplo n.º 5
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")
Exemplo n.º 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 = "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",})
Exemplo n.º 7
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',
        })
Exemplo n.º 8
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')
Exemplo n.º 9
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))
Exemplo n.º 10
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
Exemplo n.º 11
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))
Exemplo n.º 12
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)
Exemplo n.º 13
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')
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
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'], '')
Exemplo n.º 17
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'], '')
Exemplo n.º 18
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'], '')
Exemplo n.º 19
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)
Exemplo n.º 20
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"], "")
Exemplo n.º 21
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"], "")
Exemplo n.º 22
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)
Exemplo n.º 23
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)
Exemplo n.º 24
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'], '')
        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')
Exemplo n.º 25
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)
Exemplo n.º 26
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"], "")
        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")
Exemplo n.º 27
0
def django_db_modify_db_settings(db_url):
    from django.conf import settings

    settings.DATABASES["default"] = Env.db_url_config(db_url)
    del connections["default"]  # have Django recreate the connection later
Exemplo n.º 28
0
def django_db_modify_db_settings(db_url):  # pylint: disable=redefined-outer-name

    settings.DATABASES["default"] = Env.db_url_config(db_url)
    del connections["default"]  # have Django recreate the connection later
Exemplo n.º 29
0
    def test_memory_sqlite_url(self):
        url = 'sqlite://:memory:'
        url = Env.db_url_config(url)

        self.assertEqual(url['ENGINE'], 'django.db.backends.sqlite3')
        self.assertEqual(url['NAME'], ':memory:')
Exemplo n.º 30
0
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'boomslang.wsgi.application'

# Database
# https://docs.djangoproject.com/en/dev/ref/settings/#databases

DATABASES = {
    'default': Env.db_url_config(config['DATABASE_URL']),
}
DATABASES['default']['ATOMIC_REQUESTS'] = True

# Cache
CACHES = {
    'default': Env.cache_url_config(config['REDIS_URL']),
}

# Password validation
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME':
        'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
Exemplo n.º 31
0
    def test_memory_sqlite_url(self):
        url = "sqlite://:memory:"
        url = Env.db_url_config(url)

        self.assertEqual(url["ENGINE"], "django.db.backends.sqlite3")
        self.assertEqual(url["NAME"], ":memory:")
Exemplo n.º 32
0
    def test_memory_sqlite_url(self):
        url = 'sqlite://:memory:'
        url = Env.db_url_config(url)

        self.assertEqual(url['ENGINE'], 'django.db.backends.sqlite3')
        self.assertEqual(url['NAME'], ':memory:')