Skip to content

Commit

Permalink
Fix postgres drivers detection (#358)
Browse files Browse the repository at this point in the history
* add support for 'short' postgres driver (available when next dj_database_url is released)
* don't pin psycopg2<2.8 in django 2.2+
  • Loading branch information
yakky authored Dec 25, 2019
1 parent 4ce314c commit 4d90ba0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ History
++++++++++++++++++

* Pinned formtools version on django 1.11 to avoid python 2 issues
* Unpinned psycopg2 version for Django 2.2+
* Support "shorthand" postgres django backend

1.2.0 (2019-11-04)
++++++++++++++++++
Expand Down
5 changes: 4 additions & 1 deletion djangocms_installer/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ def parse(args):
requirements.extend(data.REQUIREMENTS['cms-3.6'])

if not args.no_db_driver:
requirements.append(args.db_driver)
if args.db_driver == 'psycopg2' and django_version in ('1.11', '2.0', '2.1'):
requirements.append('psycopg2<2.8')
else:
requirements.append(args.db_driver)
if not args.no_plugins:
if args.cms_version in ('rc', 'develop'):
requirements.extend(data.REQUIREMENTS['plugins-master'])
Expand Down
4 changes: 3 additions & 1 deletion djangocms_installer/config/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@
"""

DRIVERS = {
'django.db.backends.postgresql_psycopg2': 'psycopg2<2.8',
'django.db.backends.postgresql': 'psycopg2',
'django.db.backends.postgresql_psycopg2': 'psycopg2',
'django.contrib.gis.db.backends.postgis': 'postgis',
'django.db.backends.postgresql_postgis': 'postgis',
'django.db.backends.mysql': 'mysqlclient',
'django.db.backends.sqlite3': '',
Expand Down
5 changes: 5 additions & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ def setUp(self):


def get_latest_django(latest_stable=False, latest_1_x=False):
"""
Get latest django version compatible with all the supported django CMS versions.
Takes into account arguments and python version.
"""
if latest_1_x:
dj_ver = '1.11'
match = 'Django<2.0'
Expand Down
13 changes: 10 additions & 3 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_cli_config(self):
self.assertEqual(conf_data.languages, ['en-ca', 'de', 'it'])
self.assertEqual(conf_data.project_directory, self.project_dir)
self.assertEqual(conf_data.db, 'postgres://user:pwd@host/dbname')
self.assertEqual(conf_data.db_driver, 'psycopg2<2.8')
self.assertEqual(conf_data.db_driver, 'psycopg2')

dj_version, dj_match = get_latest_django(latest_stable=True)
cms_version = 'develop'
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_cli_config(self):
self.assertEqual(conf_data.languages, ['en', 'de', 'it'])
self.assertEqual(conf_data.project_directory, self.project_dir)
self.assertEqual(conf_data.db, 'postgres://user:pwd@host/dbname')
self.assertEqual(conf_data.db_driver, 'psycopg2<2.8')
self.assertEqual(conf_data.db_driver, 'psycopg2')

dj_version = '1.11'
cms_version = '3.7'
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_cli_config(self):
self.assertEqual(conf_data.languages, ['en'])
self.assertEqual(conf_data.project_directory, self.project_dir)
self.assertEqual(conf_data.db, 'postgres://user:pwd@host/dbname')
self.assertEqual(conf_data.db_driver, 'psycopg2<2.8')
self.assertEqual(conf_data.db_driver, 'psycopg2')

def test_version_misdj_match(self):
with self.assertRaises(SystemExit):
Expand Down Expand Up @@ -470,6 +470,7 @@ def test_requirements(self):
self.assertTrue(conf_data.requirements.find('cmsplugin-filer') == -1)
self.assertTrue(conf_data.requirements.find('djangocms-file') > -1)
self.assertTrue(conf_data.requirements.find('djangocms-text-ckeditor') > -1)
self.assertTrue(conf_data.requirements.find('psycopg2<2.8') > -1)

conf_data = config.parse([
'-q',
Expand Down Expand Up @@ -497,6 +498,8 @@ def test_requirements(self):
self.assertTrue(conf_data.requirements.find('djangocms-style') > -1)
self.assertTrue(conf_data.requirements.find('djangocms-teaser') == -1)
self.assertTrue(conf_data.requirements.find('djangocms-video') > -1)
self.assertTrue(conf_data.requirements.find('psycopg2') > -1)
self.assertTrue(conf_data.requirements.find('psycopg2<2.8') == -1)

conf_data = config.parse([
'-q',
Expand Down Expand Up @@ -526,6 +529,8 @@ def test_requirements(self):
self.assertTrue(conf_data.requirements.find('djangocms-style') > -1)
self.assertTrue(conf_data.requirements.find('djangocms-teaser') == -1)
self.assertTrue(conf_data.requirements.find('djangocms-video') > -1)
self.assertTrue(conf_data.requirements.find('psycopg2') > -1)
self.assertTrue(conf_data.requirements.find('psycopg2<2.8') == -1)

with self.assertRaises(SystemExit):
dj_version = '1.8'
Expand Down Expand Up @@ -684,6 +689,7 @@ def test_requirements(self):
self.assertTrue(conf_data.requirements.find('south') == -1)

dj_version = '2.1'
dj_match = 'Django<2.2'
requirements_21 = [
'-q',
'--db=postgres://user:pwd@host/dbname',
Expand All @@ -709,6 +715,7 @@ def test_requirements(self):
self.assertTrue(conf_data.requirements.find('djangocms-admin-style/archive/master.zip') > -1)
self.assertTrue(conf_data.requirements.find('djangocms-teaser/archive/master.zip') == -1)
self.assertTrue(conf_data.requirements.find('south') == -1)
self.assertTrue(conf_data.requirements.find('psycopg2<2.8') > -1)

conf_data = config.parse([
'-q',
Expand Down

0 comments on commit 4d90ba0

Please sign in to comment.