From 628335f2d9b7a62cb662da43999637d234853990 Mon Sep 17 00:00:00 2001 From: Jaye Doepke Date: Wed, 2 May 2018 11:10:20 -0500 Subject: [PATCH] Add EXPECTED_POSTGRES_ENGINE --- test_dj_database_url.py | 46 +++++++++++++---------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/test_dj_database_url.py b/test_dj_database_url.py index e92a69e..b168192 100644 --- a/test_dj_database_url.py +++ b/test_dj_database_url.py @@ -11,6 +11,12 @@ import dj_database_url POSTGIS_URL = 'postgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn' +# Django deprecated the `django.db.backends.postgresql_psycopg2` in 2.0. +# https://docs.djangoproject.com/en/2.0/releases/2.0/#id1 +EXPECTED_POSTGRES_ENGINE = 'django.db.backends.postgresql' +if DJANGO_VERSION < (2, 0): + EXPECTED_POSTGRES_ENGINE = 'django.db.backends.postgresql_psycopg2' + class DatabaseTestSuite(unittest.TestCase): @@ -18,10 +24,7 @@ class DatabaseTestSuite(unittest.TestCase): url = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn' url = dj_database_url.parse(url) - if DJANGO_VERSION < (2, 0): - assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' - else: - assert url['ENGINE'] == 'django.db.backends.postgresql' + assert url['ENGINE'] == EXPECTED_POSTGRES_ENGINE assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == 'uf07k1i6d8ia0v' @@ -32,10 +35,7 @@ class DatabaseTestSuite(unittest.TestCase): url = 'postgres://%2Fvar%2Frun%2Fpostgresql/d8r82722r2kuvn' url = dj_database_url.parse(url) - if DJANGO_VERSION < (2, 0): - assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' - else: - assert url['ENGINE'] == 'django.db.backends.postgresql' + assert url['ENGINE'] == EXPECTED_POSTGRES_ENGINE assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == '/var/run/postgresql' assert url['USER'] == '' @@ -45,10 +45,7 @@ class DatabaseTestSuite(unittest.TestCase): url = 'postgres://%2FUsers%2Fpostgres%2FRuN/d8r82722r2kuvn' url = dj_database_url.parse(url) - if DJANGO_VERSION < (2, 0): - assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' - else: - assert url['ENGINE'] == 'django.db.backends.postgresql' + assert url['ENGINE'] == EXPECTED_POSTGRES_ENGINE assert url['HOST'] == '/Users/postgres/RuN' assert url['USER'] == '' assert url['PASSWORD'] == '' @@ -58,10 +55,7 @@ class DatabaseTestSuite(unittest.TestCase): url = 'postgres://ieRaekei9wilaim7:wegauwhgeuioweg@[2001:db8:1234::1234:5678:90af]:5431/d8r82722r2kuvn' url = dj_database_url.parse(url) - if DJANGO_VERSION < (2, 0): - assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' - else: - assert url['ENGINE'] == 'django.db.backends.postgresql' + assert url['ENGINE'] == EXPECTED_POSTGRES_ENGINE assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == '2001:db8:1234::1234:5678:90af' assert url['USER'] == 'ieRaekei9wilaim7' @@ -71,10 +65,7 @@ class DatabaseTestSuite(unittest.TestCase): def test_postgres_search_path_parsing(self): url = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?currentSchema=otherschema' url = dj_database_url.parse(url) - if DJANGO_VERSION < (2, 0): - assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' - else: - assert url['ENGINE'] == 'django.db.backends.postgresql' + assert url['ENGINE'] == EXPECTED_POSTGRES_ENGINE assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == 'uf07k1i6d8ia0v' @@ -87,10 +78,7 @@ class DatabaseTestSuite(unittest.TestCase): url = 'postgres://%23user:%23password@ec2-107-21-253-135.compute-1.amazonaws.com:5431/%23database' url = dj_database_url.parse(url) - if DJANGO_VERSION < (2, 0): - assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' - else: - assert url['ENGINE'] == 'django.db.backends.postgresql' + assert url['ENGINE'] == EXPECTED_POSTGRES_ENGINE assert url['NAME'] == '#database' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == '#user' @@ -162,10 +150,7 @@ class DatabaseTestSuite(unittest.TestCase): url = dj_database_url.config() - if DJANGO_VERSION < (2, 0): - assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' - else: - assert url['ENGINE'] == 'django.db.backends.postgresql' + assert url['ENGINE'] == EXPECTED_POSTGRES_ENGINE assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == 'uf07k1i6d8ia0v' @@ -219,10 +204,7 @@ class DatabaseTestSuite(unittest.TestCase): os.environ['DATABASE_URL'] = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?sslrootcert=rds-combined-ca-bundle.pem&sslmode=verify-full' url = dj_database_url.config() - if DJANGO_VERSION < (2, 0): - assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2' - else: - assert url['ENGINE'] == 'django.db.backends.postgresql' + assert url['ENGINE'] == EXPECTED_POSTGRES_ENGINE assert url['NAME'] == 'd8r82722r2kuvn' assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com' assert url['USER'] == 'uf07k1i6d8ia0v'