Repository: joke2k/django-environ
Pull request #111 (2017-03-06 14:35:29)

Support Redshift
Support redshift like [dj-database-url](https://github.com/kennethreitz/dj-database-url/blob/471a786b64ab034a2ea2b624bc599dae64d6ae49/dj_database_url.py#L41)


Patch:
diff --git a/README.rst b/README.rst
index eacbb9c..6a58c62 100644
--- a/README.rst
+++ b/README.rst
@@ -184,6 +184,7 @@ Supported Types
     -  SQLITE: sqlite://
     -  SQLITE with SPATIALITE for GeoDjango: spatialite://
     -  Oracle: oracle://
+    -  Redshift: redshift://
     -  LDAP: ldap://
 - cache_url
     -  Database: dbcache://
diff --git a/environ/environ.py b/environ/environ.py
index 66caf86..e7faf77 100644
--- a/environ/environ.py
+++ b/environ/environ.py
@@ -78,6 +78,7 @@ class Env(object):
         'mysql2': 'django.db.backends.mysql',
         'mysqlgis': 'django.contrib.gis.db.backends.mysql',
         'oracle': 'django.db.backends.oracle',
+        'redshift': 'django_redshift_backend',
         'spatialite': 'django.contrib.gis.db.backends.spatialite',
         'sqlite': 'django.db.backends.sqlite3',
         'ldap': 'ldapdb.backends.ldap',


Test patch:
diff --git a/environ/test.py b/environ/test.py
index 4bdb017..8068354 100644
--- a/environ/test.py
+++ b/environ/test.py
@@ -18,6 +18,7 @@ class BaseTests(unittest.TestCase):
     SQLITE = 'sqlite:////full/path/to/your/database/file.sqlite'
     ORACLE_TNS = 'oracle://user:password@sid/'
     ORACLE = 'oracle://user:password@host:1521/sid'
+    REDSHIFT = 'redshift://user:password@examplecluster.abc123xyz789.us-west-2.redshift.amazonaws.com:5439/dev'
     MEMCACHE = 'memcache://127.0.0.1:11211'
     REDIS = 'rediscache://127.0.0.1:6379:1?client_class=django_redis.client.DefaultClient&password=secret'
     EMAIL = 'smtps://user@domain.com:password@smtp.example.com:587'
@@ -49,6 +50,7 @@ class BaseTests(unittest.TestCase):
                     DATABASE_SQLITE_URL=cls.SQLITE,
                     DATABASE_ORACLE_URL=cls.ORACLE,
                     DATABASE_ORACLE_TNS_URL=cls.ORACLE_TNS,
+                    DATABASE_REDSHIFT_URL=cls.REDSHIFT,
                     CACHE_URL=cls.MEMCACHE,
                     CACHE_REDIS=cls.REDIS,
                     EMAIL_URL=cls.EMAIL,
@@ -196,6 +198,14 @@ class EnvTests(BaseTests):
         self.assertEqual(oracle_config['PASSWORD'], 'password')
         self.assertEqual(oracle_config['PORT'], '1521')
 
+        redshift_config = self.env.db('DATABASE_REDSHIFT_URL')
+        self.assertEqual(redshift_config['ENGINE'], 'django_redshift_backend')
+        self.assertEqual(redshift_config['NAME'], 'dev')
+        self.assertEqual(redshift_config['HOST'], 'examplecluster.abc123xyz789.us-west-2.redshift.amazonaws.com')
+        self.assertEqual(redshift_config['USER'], 'user')
+        self.assertEqual(redshift_config['PASSWORD'], 'password')
+        self.assertEqual(redshift_config['PORT'], 5439)
+
         sqlite_config = self.env.db('DATABASE_SQLITE_URL')
         self.assertEqual(sqlite_config['ENGINE'], 'django.db.backends.sqlite3')
         self.assertEqual(sqlite_config['NAME'], '/full/path/to/your/database/file.sqlite')
diff --git a/environ/test_env.txt b/environ/test_env.txt
index f4c39ca..a8af928 100644
--- a/environ/test_env.txt
+++ b/environ/test_env.txt
@@ -27,3 +27,4 @@ CYRILLIC_VAR=фуубар
 INT_TUPLE=(42,33)
 DATABASE_ORACLE_TNS_URL=oracle://user:password@sid
 DATABASE_ORACLE_URL=oracle://user:password@host:1521/sid
+DATABASE_REDSHIFT_URL=redshift://user:password@examplecluster.abc123xyz789.us-west-2.redshift.amazonaws.com:5439/dev