def test_override_options(self): url = 'mysql://*****:*****@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' url = connection_url.config(url, {'OPTIONS': {'MAX_CONNECTIONS': 120}}, OPTIONS={'TIMEOUT': 100}) assert url['OPTIONS'] == { 'TIMEOUT': 100, }
def test_default_settings(self): engine = 'django_mysqlpool.backends.mysqlpool' conn_max_age = 600 url = 'mysql://*****:*****@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' url = connection_url.config(url, {'ENGINE':engine, 'CONN_MAX_AGE': conn_max_age}) assert url['ENGINE'] == 'django.db.backends.mysql' assert url['CONN_MAX_AGE'] == conn_max_age
def test_oracle_tns(self): url = 'oracle://*****:*****@/tnsname' url = connection_url.config(url) assert url['ENGINE'] == 'django.db.backends.oracle' assert url['USER'] == 'scott' assert url['PASSWORD'] == 'tiger' assert url['NAME'] == 'tnsname' assert url['HOST'] == '' assert url['PORT'] == ''
def test_oracle_gis(self): url = 'oraclegis://*****:*****@oraclehost:1521/hr' url = connection_url.config(url) assert url['ENGINE'] == 'django.contrib.gis.db.backends.oracle' assert url['NAME'] == 'hr' assert url['HOST'] == 'oraclehost' assert url['USER'] == 'scott' assert url['PASSWORD'] == 'tiger' assert url['PORT'] == 1521
def test_cleardb(self): url = 'mysql://*****:*****@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' url = connection_url.config(url) assert url['ENGINE'] == 'django.db.backends.mysql' assert url['NAME'] == 'heroku_97681db3eff7580' assert url['HOST'] == 'us-cdbr-east.cleardb.com' assert url['USER'] == 'bea6eb025ca0d8' assert url['PASSWORD'] == '69772142' assert url['PORT'] == ''
def test_postgres_with_special_characters(self): url = 'postgres://%23user:%[email protected]:5431/%23database' url = connection_url.config(url) assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' assert url['NAME'] == '#database' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == '#user' assert url['PASSWORD'] == '#password' assert url['PORT'] == 5431
def test_postgres_search_path(self): url = 'postgres://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?currentSchema=otherschema' url = connection_url.config(url) assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == 'uf07k1i6d8ia0v' assert url['PASSWORD'] == 'wegauwhgeuioweg' assert url['PORT'] == 5431 assert url['OPTIONS']['options'] == '-c search_path=otherschema'
def test_postgis(self): url = 'postgis://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn' url = connection_url.config(url) assert url['ENGINE'] == 'django.contrib.gis.db.backends.postgis' assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == 'uf07k1i6d8ia0v' assert url['PASSWORD'] == 'wegauwhgeuioweg' assert url['PORT'] == 5431
def test_mysql_connector(self): url = 'mysql-connector://uf07k1i6d8ia0v:[email protected]:5431/d8r82722r2kuvn' url = connection_url.config(url) assert url['ENGINE'] == 'mysql.connector.django' assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == 'uf07k1i6d8ia0v' assert url['PASSWORD'] == 'wegauwhgeuioweg' assert url['PORT'] == 5431
def test_postgres_unix_socket(self): url = 'postgres://%2Fvar%2Frun%2Fpostgresql/d8r82722r2kuvn' url = connection_url.config(url) assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == '/var/run/postgresql' assert url['USER'] == '' assert url['PASSWORD'] == '' assert url['PORT'] == ''
def test_override_options(self): url = 'mysql://*****:*****@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' url = connection_url.config(url, {'OPTIONS': { 'MAX_CONNECTIONS': 120 }}, OPTIONS={'TIMEOUT': 100}) assert url['OPTIONS'] == { 'TIMEOUT': 100, }
def test_default_settings(self): engine = 'django_mysqlpool.backends.mysqlpool' conn_max_age = 600 url = 'mysql://*****:*****@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' url = connection_url.config(url, { 'ENGINE': engine, 'CONN_MAX_AGE': conn_max_age }) assert url['ENGINE'] == 'django.db.backends.mysql' assert url['CONN_MAX_AGE'] == conn_max_age
def test_default_options(self): conn_max_age = 600 url = 'mysql://*****:*****@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' url = connection_url.config(url, {'CONN_MAX_AGE': conn_max_age, 'OPTIONS': {'MAX_CONNECTIONS': 120, 'TIMEOUT': 100}}) assert url['CONN_MAX_AGE'] == conn_max_age assert url['OPTIONS'] == { 'reconnect': 'true', 'MAX_CONNECTIONS': 120, 'TIMEOUT': 100, }
def test_database_url_with_options(self): # Test full options os.environ['DATABASE_URL'] = 'postgres://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?sslrootcert=rds-combined-ca-bundle.pem&sslmode=verify-full' url = connection_url.config('DATABASE_URL') assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == 'uf07k1i6d8ia0v' assert url['PASSWORD'] == 'wegauwhgeuioweg' assert url['PORT'] == 5431 assert url['OPTIONS'] == { 'sslrootcert': 'rds-combined-ca-bundle.pem', 'sslmode': 'verify-full' } # Test empty options os.environ['DATABASE_URL'] = 'postgres://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?' url = connection_url.config('DATABASE_URL') assert 'OPTIONS' not in url
def test_database_url_with_options(self): # Test full options os.environ[ 'DATABASE_URL'] = 'postgres://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?sslrootcert=rds-combined-ca-bundle.pem&sslmode=verify-full' url = connection_url.config('DATABASE_URL') assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == 'uf07k1i6d8ia0v' assert url['PASSWORD'] == 'wegauwhgeuioweg' assert url['PORT'] == 5431 assert url['OPTIONS'] == { 'sslrootcert': 'rds-combined-ca-bundle.pem', 'sslmode': 'verify-full' } # Test empty options os.environ[ 'DATABASE_URL'] = 'postgres://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?' url = connection_url.config('DATABASE_URL') assert 'OPTIONS' not in url
def test_database_url(self): os.environ.pop('DATABASE_URL', None) self.assertRaises(connection_url.ImproperlyConfigured, connection_url.config, 'DATABASE_URL') os.environ['DATABASE_URL'] = 'postgres://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn' url = connection_url.config('DATABASE_URL') assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == 'uf07k1i6d8ia0v' assert url['PASSWORD'] == 'wegauwhgeuioweg' assert url['PORT'] == 5431
def test_database_url(self): os.environ.pop('DATABASE_URL', None) self.assertRaises(connection_url.ImproperlyConfigured, connection_url.config, 'DATABASE_URL') os.environ[ 'DATABASE_URL'] = 'postgres://*****:*****@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn' url = connection_url.config('DATABASE_URL') assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == 'uf07k1i6d8ia0v' assert url['PASSWORD'] == 'wegauwhgeuioweg' assert url['PORT'] == 5431
def test_default_options(self): conn_max_age = 600 url = 'mysql://*****:*****@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' url = connection_url.config( url, { 'CONN_MAX_AGE': conn_max_age, 'OPTIONS': { 'MAX_CONNECTIONS': 120, 'TIMEOUT': 100 } }) assert url['CONN_MAX_AGE'] == conn_max_age assert url['OPTIONS'] == { 'reconnect': 'true', 'MAX_CONNECTIONS': 120, 'TIMEOUT': 100, }
def test_oracle_dsn(self): url = ('oracle://*****:*****@/' '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' '(HOST=oraclehost)(PORT=1521)))' '(CONNECT_DATA=(SID=hr)))') url = connection_url.config(url) assert url['ENGINE'] == 'django.db.backends.oracle' assert url['USER'] == 'scott' assert url['PASSWORD'] == 'tiger' assert url['HOST'] == '' assert url['PORT'] == '' dsn = ('(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' '(HOST=oraclehost)(PORT=1521)))' '(CONNECT_DATA=(SID=hr)))') assert url['NAME'] == dsn
def test_oracle_dsn(self): url = ( 'oracle://*****:*****@/' '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' '(HOST=oraclehost)(PORT=1521)))' '(CONNECT_DATA=(SID=hr)))' ) url = connection_url.config(url) assert url['ENGINE'] == 'django.db.backends.oracle' assert url['USER'] == 'scott' assert url['PASSWORD'] == 'tiger' assert url['HOST'] == '' assert url['PORT'] == '' dsn = ( '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' '(HOST=oraclehost)(PORT=1521)))' '(CONNECT_DATA=(SID=hr)))' ) assert url['NAME'] == dsn
'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 = 'backend.wsgi.application' DATABASES = {} DATABASES['default'] = connection_url.config(os.getenv("DATABASE_URL")) # Password validation # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME':
def test_memory_sqlite_url(self): url = 'sqlite://:memory:' url = connection_url.config(url) assert url['ENGINE'] == 'django.db.backends.sqlite3' assert url['NAME'] == ':memory:'
def test_engine_setting(self): engine = 'django_mysqlpool.backends.mysqlpool' url = 'mysql://*****:*****@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' url = connection_url.config(url, ENGINE=engine) assert url['ENGINE'] == engine
def test_conn_max_age_setting(self): conn_max_age = 600 url = 'mysql://*****:*****@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' url = connection_url.config(url, CONN_MAX_AGE=conn_max_age) assert url['CONN_MAX_AGE'] == conn_max_age
'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 = 'shorten_link.wsgi.application' # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases DATABASES = {'default': connection_url.config(os.getenv("JAWSDB_MARIA_URL"))} # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME':
"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 = "project.wsgi.application" # Database # https://docs.djangoproject.com/en/3.0/ref/settings/#databases DATABASES = {"default": connection_url.config(config("DATABASE_URL"))} DEFAULT_AUTO_FIELD = "django.db.models.AutoField" # Password validation # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, { "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, { "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
'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 = 'project.wsgi.application' # Database # https://docs.djangoproject.com/en/3.0/ref/settings/#databases DATABASES = {'default': connection_url.config(data["DATABASE_URL"])} # Password validation # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME':
load_dotenv() # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'w7q6*^(nnwbs^4n45$&u4$d87tae%#=q_^0a6q8yy3cci+%=+n' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = "True" == os.getenv("DEBUG") # Configure database DATABASES = {'default': connection_url.config('DATABASE_URL')} ALLOWED_HOSTS = [ 'https://mmpp-calgary-hacks-2021.herokuapp.com/', 'localhost', '127.0.0.1' ] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'corsheaders', 'rest_framework', 'hackathon' ] MIDDLEWARE = [
'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 = 'mainbackend.wsgi.application' DATABASE_URL = os.environ.get( 'DATABASE_URL' ) # or "postgres://*****:*****@ec2-52-31-233-101.eu-west-1.compute.amazonaws.com:5432/dbs1ak1olamhnl" #.get("DATABASE_URL") DATABASES = {} DATABASES['default'] = connection_url.config(DATABASE_URL) DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis' AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', },