From d964fc398bceedd24ed01aa5f6388fe1e49c4c56 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sun, 26 Apr 2020 23:23:18 +0200 Subject: [PATCH] Drop Python 2 / Django 1.11 (#369) Code compatibility layers to support python, old django will be removed in a future commit / PR --- .gitlab-ci.yml | 5 - .travis.yml | 11 +- README.rst | 40 +---- djangocms_installer/config/__init__.py | 17 +- djangocms_installer/config/data.py | 74 ++------ djangocms_installer/django/__init__.py | 15 +- djangocms_installer/install/__init__.py | 4 +- djangocms_installer/utils.py | 15 +- requirements-test.txt | 2 +- tests/base.py | 59 +++---- tests/config.py | 218 +++++++----------------- tests/django.py | 157 +++++------------ tests/fixtures/configs/config-02.ini | 4 +- tests/fixtures/configs/config-08.ini | 4 +- tests/fixtures/configs/config-10.ini | 2 +- tests/fixtures/configs/config-11.ini | 2 +- tests/main.py | 26 +-- tox.ini | 16 +- 18 files changed, 192 insertions(+), 479 deletions(-) delete mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index c9ed0a3..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,5 +0,0 @@ -# This file is generated by GitLab CI -ci: - script: - - COMMAND="coverage run" tox -epy26,py27,py33,py34 - - if [[ $? -eq 0 ]]; then coverage report; fi \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 40f3b65..0dcd5c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ python: - 3.7 - 3.6 - 3.5 - - 2.7 env: @@ -28,8 +27,7 @@ before_install: # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors install: - - pip install -U setuptools tox virtualenv coveralls - - "if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then export TOX_ENV=py27; fi" + - pip install -U setuptools tox virtualenv coveralls>=2 - "if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then export TOX_ENV=py35; fi" - "if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then export TOX_ENV=py36; fi" - "if [[ $TRAVIS_PYTHON_VERSION == '3.7' ]]; then export TOX_ENV=py37; fi" @@ -40,17 +38,12 @@ install: script: COMMAND='coverage run --source=djangocms_installer' tox -e$TOX_ENV after_success: + - coverage report -m - codecov - coveralls matrix: exclude: - - python: 2.7 - env: TEST='pep8' - - python: 2.7 - env: TEST='isort' - - python: 2.7 - env: TEST='docs' - python: 3.5 env: TEST='pep8' - python: 3.5 diff --git a/README.rst b/README.rst index 8c4e033..e680191 100644 --- a/README.rst +++ b/README.rst @@ -16,28 +16,8 @@ project. Refer to `django CMS Tutorial`_ on how to properly setup your first django CMS project. -.. warning:: For all 1.2 RC django CMS 3.7 rc will be installed by default, **not** latest stable, - to ensure a smoother transition. Likewise "3.7", "stable" and "lts" selector will install - django CMS 3.7rc1 - -.. warning:: Version 1.2 dropped support for Python 3.4, django CMS < 3.6 and Django < 1.11. - More 1.1.x versions may be released after 1.2 is out in case important bugfixes will - be needed. - -.. warning:: Due to some incompatibilities between psycopg2 2.8 and Django 2.1+ we ship with psycopg2 2.7 - when PostgreSQL database is selected, this in turn trigger an outdated psycopg2 warning. To - silence it, add the following to your ``manage.py``: - - .. code-block:: python - - import os - import sys - import warnings - - if __name__ == '__main__': - warnings.filterwarnings( - 'ignore', r'The psycopg2.*release 2\.8', UserWarning, 'psycopg2') - # ... rest of code ... +.. warning:: Version 2.0 dropped support for Python 2.7, django CMS < 3.7 and Django < 2.2. + More 1.2.x versions may be released after 1.2 is out in case important bugfixes will be needed. Usage ----- @@ -88,15 +68,13 @@ Supported versions The current supported version matrix is the following: -+----------------+-------------+-------------+---------------+--------------+--------------+ -| | Django 1.11 | Django 2.0 | Django 2.1 | Django 2.2 | Django 3.0 | -+----------------+-------------+-------------+---------------+--------------+--------------+ -| django CMS 3.6 | Supported | Supported | Supported | Supported | Supported | -+----------------+-------------+-------------+---------------+--------------+--------------+ -| django CMS 3.7 | Supported | Supported | Supported | Supported | Supported | -+----------------+-------------+-------------+---------------+--------------+--------------+ ++----------------+--------------+--------------+ +| | Django 2.2 | Django 3.0 | ++----------------+--------------+--------------+ +| django CMS 3.7 | Supported | Supported | ++----------------+--------------+--------------+ -See `version 1.1`_ for older Django / django CMS versions support +See `version 1.2`_ for older Django / django CMS versions support Any beta and develop version of Django and django CMS, by its very nature, it's not supported, while it still may work. @@ -127,7 +105,7 @@ Please check that the ``.py`` extension is associated correctly with Python inte Python.File="C:\Windows\py.exe" "%1" %* -.. _version 1.1: https://github.com/nephila/djangocms-installer/tree/release/1.1.x#supported-versions +.. _version 1.2: https://github.com/nephila/djangocms-installer/tree/release/1.2.x#supported-versions .. _django CMS Tutorial: https://django-cms.readthedocs.io/en/latest/introduction/index.html .. _installer usage page: http://djangocms-installer.readthedocs.io/en/latest/usage.html diff --git a/djangocms_installer/config/__init__.py b/djangocms_installer/config/__init__.py index 9217894..36838d3 100644 --- a/djangocms_installer/config/__init__.py +++ b/djangocms_installer/config/__init__.py @@ -275,21 +275,14 @@ def parse(args): requirements.extend(data.REQUIREMENTS['cms-master']) elif LooseVersion(cms_version) >= LooseVersion('3.7'): requirements.extend(data.REQUIREMENTS['cms-3.7']) - elif LooseVersion(cms_version) >= LooseVersion('3.6'): - requirements.extend(data.REQUIREMENTS['cms-3.6']) if not args.no_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) + requirements.append(args.db_driver) if not args.no_plugins: if args.cms_version in ('rc', 'develop'): requirements.extend(data.REQUIREMENTS['plugins-master']) elif LooseVersion(cms_version) >= LooseVersion('3.7'): requirements.extend(data.REQUIREMENTS['plugins-3.7']) - elif LooseVersion(cms_version) >= LooseVersion('3.6'): - requirements.extend(data.REQUIREMENTS['plugins-3.6']) requirements.extend(data.REQUIREMENTS['filer']) # Django version check @@ -304,12 +297,8 @@ def parse(args): if django_version == '2.2': requirements.extend(data.REQUIREMENTS['django-2.2']) - elif django_version == '2.1': - requirements.extend(data.REQUIREMENTS['django-2.1']) - elif django_version == '2.0': - requirements.extend(data.REQUIREMENTS['django-2.0']) - elif django_version == '1.11': - requirements.extend(data.REQUIREMENTS['django-1.11']) + elif django_version == '3.0': + requirements.extend(data.REQUIREMENTS['django-3.0']) requirements.extend(data.REQUIREMENTS['default']) diff --git a/djangocms_installer/config/data.py b/djangocms_installer/config/data.py index 91e8dc3..01ffb78 100644 --- a/djangocms_installer/config/data.py +++ b/djangocms_installer/config/data.py @@ -18,37 +18,24 @@ **bust ) DJANGOCMS_BETA = DJANGOCMS_RC -DJANGOCMS_36 = 'django-cms>=3.6,<3.7' +DJANGOCMS_37 = 'django-cms>=3.7,<3.8' -if sys.version_info > (3, 0): - DJANGOCMS_37 = 'django-cms>=3.7,<3.8' -else: - DJANGOCMS_37 = 'django-cms>=3.7,<3.7.2' - -if sys.version_info >= (3, 5): - DJANGOCMS_SUPPORTED = ('3.6', '3.7', 'stable', 'lts', 'develop', 'rc') - DJANGOCMS_STABLE = '3.7' - DJANGOCMS_LTS = '3.7' -else: - DJANGOCMS_SUPPORTED = ('3.6', '3.7', 'stable', 'lts', 'develop', 'rc') - DJANGOCMS_STABLE = '3.7' - DJANGOCMS_LTS = '3.7' +DJANGOCMS_SUPPORTED = ('3.7', 'stable', 'lts', 'develop', 'rc') +DJANGOCMS_STABLE = '3.7' +DJANGOCMS_LTS = '3.7' DJANGOCMS_DEFAULT = DJANGOCMS_STABLE DJANGO_DEVELOP = 'https://github.com/django/django/archive/master.zip?{bust}'.format(**bust) DJANGO_BETA = 'https://github.com/django/django/archive/master.zip?{bust}'.format(**bust) if sys.version_info >= (3, 6): - DJANGO_SUPPORTED = ('1.11', '2.0', '2.1', '2.2', '3.0', 'stable', 'lts') + DJANGO_SUPPORTED = ('2.2', '3.0', 'stable', 'lts') DJANGO_STABLE = '3.0' DJANGO_LTS = '2.2' -elif (3, 6) > sys.version_info >= (3, 5): - DJANGO_SUPPORTED = ('1.11', '2.0', '2.1', '2.2', 'stable', 'lts') +else: + DJANGO_SUPPORTED = ('2.2', 'stable', 'lts') DJANGO_STABLE = '2.2' DJANGO_LTS = '2.2' -else: - DJANGO_SUPPORTED = ('1.11', 'stable', 'lts') - DJANGO_STABLE = '1.11' - DJANGO_LTS = '1.11' + DJANGO_DEFAULT = DJANGO_STABLE CMS_VERSION_MATRIX = { @@ -66,14 +53,12 @@ 'develop': DJANGO_STABLE } VERSION_MATRIX = { - '3.6': ('1.11', '2.1'), - '3.7': ('1.11', '3.0'), - DJANGOCMS_BETA: ('1.11', '3.0'), - DJANGOCMS_RC: ('1.11', '3.0'), - DJANGOCMS_DEVELOP: ('1.11', '2.2', '3.0'), + '3.7': ('2.2', '3.0'), + DJANGOCMS_BETA: ('2.2', '3.0'), + DJANGOCMS_RC: ('2.2', '3.0'), + DJANGOCMS_DEVELOP: ('2.2', '3.0'), } PACKAGE_MATRIX = { - '3.6': DJANGOCMS_36, '3.7': DJANGOCMS_37, DJANGOCMS_RC: DJANGOCMS_RC, DJANGOCMS_BETA: DJANGOCMS_BETA, @@ -87,22 +72,6 @@ 'six', 'pytz', ], - 'django-1.11': [ - 'django-classy-tags>=0.9', - 'django-sekizai>=1.0', - 'django-mptt>0.9', - 'django-formtools>=2.1,<2.2', - ], - 'django-2.0': [ - 'django-classy-tags>=0.9', - 'django-sekizai>=1.0', - 'django-mptt>0.9', - ], - 'django-2.1': [ - 'django-classy-tags>=0.9', - 'django-sekizai>=1.0', - 'django-mptt>0.9', - ], 'django-2.2': [ 'django-classy-tags>=0.9', 'django-sekizai>=1.0', @@ -113,13 +82,6 @@ 'django-sekizai>=1.0', 'django-mptt>0.9', ], - 'reversion-django-1.11': [ - 'django-reversion>=2.0,<2.1', - ], - 'cms-3.6': [ - 'djangocms-admin-style>=1.5,<1.6', - 'django-treebeard>=4.0,<5.0', - ], 'cms-3.7': [ 'djangocms-admin-style>=1.5,<1.6', 'django-treebeard>=4.0,<5.0', @@ -128,18 +90,6 @@ 'https://github.com/divio/djangocms-admin-style/archive/master.zip?{bust}'.format(**bust), 'django-treebeard>=4.0,<5.0', ], - 'plugins-3.6': [ - 'djangocms-text-ckeditor>=3.7,<4.0', - 'djangocms-link>=2.5,<2.7', - 'djangocms-icon>=1.4,<1.6', - 'djangocms-style>=2.2,<2.4', - 'djangocms-googlemap>=1.3,<1.5', - 'djangocms-snippet>=2.2,<2.4', - 'djangocms-video>=2.1,<2.4', - 'djangocms-file>=2.3,<2.5', - 'djangocms-picture>=2.3,<2.5', - 'djangocms-bootstrap4>=1.5,<1.7', - ], 'plugins-3.7': [ 'djangocms-text-ckeditor>=3.7,<4.0', 'djangocms-link>=2.5,<2.7', diff --git a/djangocms_installer/django/__init__.py b/djangocms_installer/django/__init__.py index 8e2ecdf..3a443c2 100644 --- a/djangocms_installer/django/__init__.py +++ b/djangocms_installer/django/__init__.py @@ -10,17 +10,13 @@ import textwrap from copy import copy, deepcopy from distutils.version import LooseVersion +from shlex import quote as shlex_quote from six import iteritems from ..config import data, get_settings from ..utils import chdir, format_val -try: - from shlex import quote as shlex_quote -except ImportError: - from pipes import quote as shlex_quote - def create_project(config_data): """ @@ -122,7 +118,7 @@ def patch_settings(config_data): current_django_version = LooseVersion(django.__version__) declared_django_version = LooseVersion(config_data.django_version) - if not os.path.exists(config_data.settings_path): + if not os.path.exists(config_data.settings_path): # pragma: no cover sys.stderr.write( 'Error while creating target project, ' 'please check the given configuration: {0}\n'.format(config_data.settings_path) @@ -194,10 +190,7 @@ def patch_settings(config_data): item_re = re.compile(r'{0} = [^\]]+\]'.format(item), re.DOTALL | re.MULTILINE) original = item_re.sub('', original) # TEMPLATES is special, so custom regexp needed - if declared_django_version >= LooseVersion('2.0'): - item_re = re.compile(r'TEMPLATES = .+\},\n\s+\},\n]$', re.DOTALL | re.MULTILINE) - else: - item_re = re.compile(r'TEMPLATES = .+\]$', re.DOTALL | re.MULTILINE) + item_re = re.compile(r'TEMPLATES = .+\},\n\s+\},\n]$', re.DOTALL | re.MULTILINE) original = item_re.sub('', original) # DATABASES is a dictionary, so different regexp needed item_re = re.compile(r'DATABASES = [^\}]+\}[^\}]+\}', re.DOTALL | re.MULTILINE) @@ -363,7 +356,7 @@ def setup_database(config_data): sys.stdout.write('Creating admin user\n') if config_data.noinput: create_user(config_data) - else: + else: # pragma: no cover subprocess.check_call(' '.join( [sys.executable, '-W', 'ignore', 'manage.py', 'createsuperuser'] ), shell=True, stderr=subprocess.STDOUT) diff --git a/djangocms_installer/install/__init__.py b/djangocms_installer/install/__init__.py index 073141a..ef5cbe6 100644 --- a/djangocms_installer/install/__init__.py +++ b/djangocms_installer/install/__init__.py @@ -97,7 +97,7 @@ def requirements(req_file, pip_options='', is_file=False, verbose=False): subprocess.check_output(['python', '-msite'], stderr=subprocess.STDOUT) output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) sys.stdout.write(output.decode('utf-8')) - except Exception as e: + except Exception as e: # pragma: no cover logger.error('cmd : %s :%s' % (e.cmd, e.output)) raise @@ -124,7 +124,7 @@ def cleanup_directory(config_data): """ if os.path.exists(config_data.project_directory): choice = False - if config_data.noinput is False and not config_data.verbose: + if config_data.noinput is False and not config_data.verbose: # pragma: no cover choice = query_yes_no( 'The installation failed.\n' 'Do you want to clean up by removing {0}?\n' diff --git a/djangocms_installer/utils.py b/djangocms_installer/utils.py index f8508d3..1676ec3 100644 --- a/djangocms_installer/utils.py +++ b/djangocms_installer/utils.py @@ -102,25 +102,22 @@ def less_than_version(value): if len(items) == 1: items.append(0) items[1] += 1 - if value == '1.11': - return '2.0' - else: - return '.'.join(map(str, items)) + return '.'.join(map(str, items)) class chdir(object): """ Context manager for changing the current working directory """ - def __init__(self, newPath): - self.newPath = newPath + def __init__(self, new_path): + self.new_path = new_path def __enter__(self): - self.savedPath = os.getcwd() - os.chdir(self.newPath) + self.saved_path = os.getcwd() + os.chdir(self.new_path) def __exit__(self, etype, value, traceback): - os.chdir(self.savedPath) + os.chdir(self.saved_path) def format_val(val): diff --git a/requirements-test.txt b/requirements-test.txt index 4edee64..d5cbf9a 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -3,4 +3,4 @@ flake8 tox mock pillow -coverage<5.0 +coverage>=5 diff --git a/tests/base.py b/tests/base.py index 2600e5f..a3f8243 100644 --- a/tests/base.py +++ b/tests/base.py @@ -82,12 +82,9 @@ def tearDown(self): if self.verbose: print('deactivating virtualenv', self.virtualenv_dir) if os.path.exists(SYSTEM_ACTIVATE): - try: - execfile(SYSTEM_ACTIVATE, dict(__file__=SYSTEM_ACTIVATE)) - except NameError: - with open(SYSTEM_ACTIVATE) as f: - code = compile(f.read(), SYSTEM_ACTIVATE, 'exec') - exec(code, dict(__file__=SYSTEM_ACTIVATE)) + with open(SYSTEM_ACTIVATE) as f: + code = compile(f.read(), SYSTEM_ACTIVATE, 'exec') + exec(code, dict(__file__=SYSTEM_ACTIVATE)) sys.executable = os.path.join(os.path.dirname(SYSTEM_ACTIVATE), 'python') super(IsolatedTestClass, self).tearDown() modules = copy(sys.modules) @@ -103,55 +100,41 @@ def setUp(self): self.virtualenv_dir ]) activate_temp = os.path.join(self.virtualenv_dir, 'bin', 'activate_this.py') - try: - execfile(activate_temp, dict(__file__=activate_temp)) - except NameError: - with open(activate_temp) as f: - code = compile(f.read(), activate_temp, 'exec') - exec(code, dict(__file__=activate_temp)) + with open(activate_temp) as f: + code = compile(f.read(), activate_temp, 'exec') + exec(code, dict(__file__=activate_temp)) if self.verbose: print('activating virtualenv', self.virtualenv_dir) sys.executable = os.path.join(self.virtualenv_dir, 'bin', 'python') os.environ['VIRTUAL_ENV'] = self.virtualenv_dir -def get_latest_django(latest_stable=False, latest_1_x=False): +def get_stable_django(latest=False, lts=False): """ - Get latest django version compatible with all the supported django CMS and python versions. + Get django version compatible with all the supported django CMS and python versions. Takes into account arguments and python version. + + Default to lower common version. + + :param latest: Latest stable version + :param lts: Latest lts version """ - if latest_1_x: - dj_ver = '1.11' - match = 'Django<2.0' - elif sys.version_info < (3, 4): - dj_ver = '1.11' - match = 'Django<2.0' - elif sys.version_info < (3, 5): - dj_ver = '2.0' - match = 'Django<2.1' - elif sys.version_info < (3, 6): - dj_ver = '2.2' - match = 'Django<2.3' - else: + if latest and not sys.version_info < (3, 6) and not lts: dj_ver = '3.0' match = 'Django<3.1' + else: + dj_ver = '2.2' + match = 'Django<2.3' return dj_ver, match -def get_latest_djangocms(latest_1_x=False): +def get_stable_djangocms(): """ - Get latest django CMS version compatible with all the supported django and python versions. + Get django CMS version compatible with all the supported django and python versions. Takes into account arguments and python version. """ - if latest_1_x: - dj_ver = '3.7' - match = 'django-cms<3.8' - elif sys.version_info < (3, 5): - dj_ver = '3.7' - match = 'django-cms<3.8' - else: - dj_ver = '3.7' - match = 'django-cms<3.8' + dj_ver = '3.7' + match = 'django-cms<3.8' return dj_ver, match diff --git a/tests/config.py b/tests/config.py index ffdb6c3..ce4a863 100644 --- a/tests/config.py +++ b/tests/config.py @@ -18,45 +18,21 @@ from djangocms_installer.install import check_install from djangocms_installer.utils import less_than_version, supported_versions -from .base import BaseTestClass, get_latest_django, unittest - -latest_stable_django, latest_stable_django_match = get_latest_django() +from .base import BaseTestClass, get_stable_django, unittest class TestConfig(BaseTestClass): - @unittest.skipIf(sys.version_info[0] < 3, - reason='django 2+ only supports python 3') def test_default_config(self): - conf_data = config.parse(['--db=postgres://user:pwd@host/dbname', - '-q', '-p'+self.project_dir, 'example_prj']) - - self.assertEqual(conf_data.project_name, 'example_prj') - - self.assertEqual(conf_data.cms_version, '3.7') - self.assertEqual(conf_data.django_version, latest_stable_django) - self.assertEqual(conf_data.i18n, 'yes') - self.assertEqual(conf_data.reversion, 'yes') - self.assertEqual(conf_data.permissions, 'no') - self.assertEqual(conf_data.use_timezone, 'yes') - self.assertEqual(conf_data.db, 'postgres://user:pwd@host/dbname') - - self.assertEqual(conf_data.no_db_driver, False) - self.assertEqual(conf_data.no_deps, False) - self.assertEqual(conf_data.no_sync, False) - self.assertEqual(conf_data.plugins, False) - self.assertEqual(conf_data.requirements_file, None) + dj_version, dj_match = get_stable_django(latest=True) - @unittest.skipIf(sys.version_info[0] >= 3, - reason='django 2+ does not supports python 2') - def test_default_config_27(self): conf_data = config.parse(['--db=postgres://user:pwd@host/dbname', '-q', '-p'+self.project_dir, 'example_prj']) self.assertEqual(conf_data.project_name, 'example_prj') self.assertEqual(conf_data.cms_version, '3.7') - self.assertEqual(conf_data.django_version, '1.11') + self.assertEqual(conf_data.django_version, dj_version) self.assertEqual(conf_data.i18n, 'yes') self.assertEqual(conf_data.reversion, 'yes') self.assertEqual(conf_data.permissions, 'no') @@ -86,36 +62,7 @@ def test_cli_config(self): '-p'+self.project_dir, 'example_prj']) - dj_version = '1.11' - conf_data = config.parse([ - '-q', - '--db=postgres://user:pwd@host/dbname', - '--cms-version=stable', - '--django-version={0}'.format(dj_version), - '--i18n=no', - '--reversion=no', - '--permissions=no', - '--use-tz=no', - '-tEurope/Rome', - '-len-CA', '-lde', '-lit', - '-p'+self.project_dir, - 'example_prj']) - - self.assertEqual(conf_data.project_name, 'example_prj') - - self.assertEqual(conf_data.cms_version, '3.7') - self.assertEqual(conf_data.django_version, '1.11') - self.assertEqual(conf_data.i18n, 'yes') - self.assertEqual(conf_data.reversion, 'no') - self.assertEqual(conf_data.permissions, 'no') - self.assertEqual(conf_data.use_timezone, 'no') - self.assertEqual(conf_data.timezone, 'Europe/Rome') - 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') - - dj_version, dj_match = get_latest_django(latest_stable=True) + dj_version, dj_match = get_stable_django() cms_version = 'develop' conf_data = config.parse([ '-q', @@ -145,37 +92,6 @@ def test_cli_config(self): self.assertEqual(conf_data.db, 'postgres://user:pwd@host/dbname') self.assertEqual(conf_data.db_driver, 'psycopg2') - dj_version = '1.11' - cms_version = '3.7' - conf_data = config.parse([ - '-q', - '--db=postgres://user:pwd@host/dbname', - '--cms-version=stable', - '--django-version={0}'.format(dj_version), - '--cms-version={0}'.format(cms_version), - '--i18n=no', - '--reversion=no', - '--permissions=no', - '--use-tz=no', - '-tEurope/Rome', - '-len', - '-p' + self.project_dir, - 'example_prj']) - - self.assertEqual(conf_data.project_name, 'example_prj') - - self.assertEqual(str(conf_data.cms_version), cms_version) - self.assertEqual(str(conf_data.django_version), dj_version) - self.assertEqual(conf_data.i18n, 'no') - self.assertEqual(conf_data.reversion, 'no') - self.assertEqual(conf_data.permissions, 'no') - self.assertEqual(conf_data.use_timezone, 'no') - self.assertEqual(conf_data.timezone, 'Europe/Rome') - 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') - def test_version_misdj_match(self): with self.assertRaises(SystemExit): conf_data = config.parse([ @@ -403,11 +319,13 @@ def test_latest_version(self): @unittest.skipIf(sys.version_info[0] < 3, reason='django 2+ only supports python 3') def test_supported_versions(self): - self.assertEqual(supported_versions('stable', 'stable'), (latest_stable_django, '3.7')) - self.assertEqual(supported_versions('stable', '3.1.10'), (latest_stable_django, None)) - self.assertEqual(supported_versions('stable', 'rc'), (latest_stable_django, DJANGOCMS_RC)) - self.assertEqual(supported_versions('stable', 'beta'), (latest_stable_django, DJANGOCMS_BETA)) - self.assertEqual(supported_versions('stable', 'develop'), (latest_stable_django, DJANGOCMS_DEVELOP)) + dj_version, dj_match = get_stable_django(latest=True) + + self.assertEqual(supported_versions('stable', 'stable'), (dj_version, '3.7')) + self.assertEqual(supported_versions('stable', '3.1.10'), (dj_version, None)) + self.assertEqual(supported_versions('stable', 'rc'), (dj_version, DJANGOCMS_RC)) + self.assertEqual(supported_versions('stable', 'beta'), (dj_version, DJANGOCMS_BETA)) + self.assertEqual(supported_versions('stable', 'develop'), (dj_version, DJANGOCMS_DEVELOP)) self.assertEqual(supported_versions('lts', 'rc'), ('2.2', DJANGOCMS_RC)) self.assertEqual(supported_versions('lts', 'lts'), ('2.2', '3.7')) @@ -423,37 +341,11 @@ def test_supported_versions(self): self.assertEqual(supported_versions('1.8', 'lts'), ('1.8', '3.7')) self.assertEqual(supported_versions('1.8.3', 'stable'), (None, '3.6')) - @unittest.skipIf(sys.version_info[0] >= 3, - reason='django 2+ does not supports python 2') - def test_supported_versions_27(self): - - self.assertEqual(supported_versions('stable', 'stable'), ('1.11', '3.7')) - self.assertEqual(supported_versions('stable', '3.1.10'), ('1.11', None)) - self.assertEqual(supported_versions('stable', 'rc'), ('1.11', DJANGOCMS_RC)) - self.assertEqual(supported_versions('stable', 'beta'), ('1.11', DJANGOCMS_BETA)) - self.assertEqual(supported_versions('stable', 'develop'), ('1.11', DJANGOCMS_DEVELOP)) - self.assertEqual(supported_versions('lts', 'rc'), ('1.11', DJANGOCMS_RC)) - self.assertEqual(supported_versions('lts', 'lts'), ('1.11', '3.7')) - - with self.assertRaises(RuntimeError): - supported_versions('stable', '2.4'), ('1.5', '2.4') - with self.assertRaises(RuntimeError): - supported_versions('1.5', 'stable'), ('1.8', '3.1') - - with self.assertRaises(RuntimeError): - self.assertEqual(supported_versions('1.9', 'stable'), ('1.9', '3.5')) - self.assertEqual(supported_versions('1.8', 'stable'), ('1.8', '3.5')) - self.assertEqual(supported_versions('1.9', '3.5'), ('1.9', '3.5')) - self.assertEqual(supported_versions('1.8', 'lts'), ('1.8', '3.7')) - self.assertEqual(supported_versions('1.8.3', 'stable'), (None, '3.6')) - - @unittest.skipIf(sys.version_info[0] < 3, - reason='django 2+ only supports python 3') def test_requirements(self): """ Test for different configuration and package versions """ - dj_version = '1.11' + dj_version, dj_match = get_stable_django(lts=True) conf_data = config.parse([ '-q', '--db=postgres://user:pwd@host/dbname', @@ -463,8 +355,9 @@ def test_requirements(self): '-f', '-p'+self.project_dir, 'example_prj']) + print(conf_data.requirements) self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_37) > -1) - self.assertTrue(conf_data.requirements.find('Django<2.0') > -1) + self.assertTrue(conf_data.requirements.find(dj_match) > -1) self.assertFalse(conf_data.requirements.find('django-reversion') > -1) self.assertTrue(conf_data.requirements.find('djangocms-text-ckeditor>=3.7,<4.0') > -1) self.assertTrue(conf_data.requirements.find('djangocms-admin-style>=1.5') > -1) @@ -472,20 +365,21 @@ 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) + self.assertTrue(conf_data.requirements.find('psycopg2') > -1) + dj_version, dj_match = get_stable_django(latest=True) conf_data = config.parse([ '-q', '--db=postgres://user:pwd@host/dbname', '--i18n=no', '--cms-version=stable', - '--django-version=stable', + '--django-version={}'.format(dj_version), '--reversion=yes', '-p'+self.project_dir, 'example_prj']) self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_37) > -1) - self.assertTrue(conf_data.requirements.find(latest_stable_django_match) > -1) + self.assertTrue(conf_data.requirements.find(dj_match) > -1) self.assertFalse(conf_data.requirements.find('django-reversion') > -1) self.assertTrue(conf_data.requirements.find('cmsplugin-filer') == -1) self.assertTrue(conf_data.requirements.find('djangocms-admin-style') > -1) @@ -501,21 +395,21 @@ def test_requirements(self): 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) + dj_version, dj_match = get_stable_django(lts=True) conf_data = config.parse([ '-q', '--db=postgres://user:pwd@host/dbname', '--i18n=no', '--cms-version=develop', - '--django-version=lts', + '--django-version={}'.format(dj_version), '-f', '--reversion=yes', '-p'+self.project_dir, 'example_prj']) self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_DEVELOP) > -1) - self.assertTrue(conf_data.requirements.find('Django<2.3') > -1) + self.assertTrue(conf_data.requirements.find(dj_match) > -1) self.assertFalse(conf_data.requirements.find('django-reversion') > -1) self.assertTrue(conf_data.requirements.find('djangocms-text-ckeditor') > -1) self.assertTrue(conf_data.requirements.find('djangocms-admin-style') > -1) @@ -532,7 +426,6 @@ def test_requirements(self): 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' @@ -547,7 +440,7 @@ def test_requirements(self): '-p'+self.project_dir, 'example_prj']) - dj_version = '1.11' + dj_version, dj_match = get_stable_django(latest=True) conf_data = config.parse([ '-q', '--db=postgres://user:pwd@host/dbname', @@ -560,17 +453,17 @@ def test_requirements(self): 'example_prj']) self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_DEVELOP) > -1) - self.assertTrue(conf_data.requirements.find('Django<2.0') > -1) + self.assertTrue(conf_data.requirements.find(dj_match) > -1) self.assertFalse(conf_data.requirements.find('django-reversion') > -1) - self.assertTrue(conf_data.requirements.find('django-mptt') > -1) self.assertTrue(conf_data.requirements.find('django-treebeard') > -1) + dj_version, dj_match = get_stable_django() conf_data = config.parse([ '-q', '--db=postgres://user:pwd@host/dbname', '--i18n=no', '--cms-version=develop', - '--django-version=stable', + '--django-version={}'.format(dj_version), '-f', '--reversion=yes', '-z=yes', @@ -578,7 +471,7 @@ def test_requirements(self): 'example_prj']) self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_DEVELOP) > -1) - self.assertTrue(conf_data.requirements.find(latest_stable_django_match) > -1) + self.assertTrue(conf_data.requirements.find(dj_match) > -1) self.assertFalse(conf_data.requirements.find('django-reversion') > -1) self.assertTrue(conf_data.requirements.find('https://github.com/divio/djangocms-link') > -1) self.assertTrue(conf_data.requirements.find('https://github.com/divio/djangocms-style') > -1) @@ -595,7 +488,7 @@ def test_requirements(self): '--db=postgres://user:pwd@host/dbname', '--i18n=no', '--cms-version=3.7', - '--django-version=stable', + '--django-version={}'.format(dj_version), '-f', '--reversion=yes', '-z=yes', @@ -603,18 +496,19 @@ def test_requirements(self): 'example_prj']) self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_37) > -1) - self.assertTrue(conf_data.requirements.find(latest_stable_django_match) > -1) + self.assertTrue(conf_data.requirements.find(dj_match) > -1) self.assertFalse(conf_data.requirements.find('django-reversion') > -1) self.assertTrue(conf_data.requirements.find('djangocms-text-ckeditor>=3.7') > -1) self.assertTrue(conf_data.requirements.find('djangocms-admin-style') > -1) self.assertTrue(conf_data.requirements.find('pytz') > -1) + dj_version, dj_match = get_stable_django(lts=True) conf_data = config.parse([ '-q', '--db=postgres://user:pwd@host/dbname', '--i18n=no', '--cms-version=3.7', - '--django-version=lts', + '--django-version={}'.format(dj_version), '-f', '--reversion=yes', '-z=yes', @@ -622,13 +516,13 @@ def test_requirements(self): 'example_prj']) self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_37) > -1) - self.assertTrue(conf_data.requirements.find('Django<2.3') > -1) + self.assertTrue(conf_data.requirements.find(dj_match) > -1) self.assertFalse(conf_data.requirements.find('django-reversion') > -1) self.assertTrue(conf_data.requirements.find('djangocms-text-ckeditor>=3.7') > -1) self.assertTrue(conf_data.requirements.find('djangocms-admin-style') > -1) self.assertTrue(conf_data.requirements.find('pytz') > -1) - dj_version = '1.11' + dj_version, dj_match = get_stable_django(lts=True) conf_data = config.parse([ '-q', '--db=postgres://user:pwd@host/dbname', @@ -641,14 +535,13 @@ def test_requirements(self): 'example_prj']) self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_DEVELOP) > -1) - self.assertTrue(conf_data.requirements.find('Django<2.0') > -1) - self.assertFalse(conf_data.requirements.find('django-reversion>=1.10,<1.11') > -1) + self.assertTrue(conf_data.requirements.find(dj_match) > -1) self.assertTrue(conf_data.requirements.find('djangocms-text-ckeditor') > -1) self.assertTrue(conf_data.requirements.find('djangocms-admin-style') > -1) self.assertTrue(conf_data.requirements.find('djangocms-teaser') == -1) self.assertTrue(conf_data.requirements.find('south') == -1) - dj_version, dj_match = get_latest_django(latest_stable=True) + dj_version, dj_match = get_stable_django() conf_data = config.parse([ '-q', '--db=postgres://user:pwd@host/dbname', @@ -669,7 +562,7 @@ def test_requirements(self): self.assertTrue(conf_data.requirements.find('djangocms-teaser') == -1) self.assertTrue(conf_data.requirements.find('south') == -1) - dj_version = '1.11' + dj_version, dj_match = get_stable_django(lts=True) conf_data = config.parse([ '-q', '--db=postgres://user:pwd@host/dbname', @@ -683,15 +576,14 @@ def test_requirements(self): 'example_prj']) self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_DEVELOP) > -1) - self.assertTrue(conf_data.requirements.find('Django<2.0') > -1) + self.assertTrue(conf_data.requirements.find(dj_match) > -1) self.assertFalse(conf_data.requirements.find('django-reversion') > -1) self.assertTrue(conf_data.requirements.find('djangocms-text-ckeditor') == -1) 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) - dj_version = '2.1' - dj_match = 'Django<2.2' + dj_version, dj_match = get_stable_django(lts=True) requirements_21 = [ '-q', '--db=postgres://user:pwd@host/dbname', @@ -717,30 +609,32 @@ 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) + self.assertTrue(conf_data.requirements.find('psycopg2') > -1) + dj_version, dj_match = get_stable_django(lts=True) conf_data = config.parse([ '-q', '--db=postgres://user:pwd@host/dbname', '--cms-version=lts', - '--django-version=lts', + '--django-version={}'.format(dj_version), '-p'+self.project_dir, 'example_prj']) self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_37) > -1) - self.assertTrue(conf_data.requirements.find('Django<2.3') > -1) + self.assertTrue(conf_data.requirements.find(dj_match) > -1) + dj_version, dj_match = get_stable_django(latest=True) conf_data = config.parse([ '-q', '--db=postgres://user:pwd@host/dbname', '--cms-version=stable', - '--django-version=stable', + '--django-version={}'.format(dj_version), '-p'+self.project_dir, 'example_prj']) self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_37) > -1) - self.assertTrue(conf_data.requirements.find(latest_stable_django_match) > -1) + self.assertTrue(conf_data.requirements.find(dj_match) > -1) def test_bootstrap(self): """ @@ -891,7 +785,8 @@ def test_show_plugins(self): def test_show_requirements(self): sys.stdout = StringIO() - dj_version = '1.11' + dj_version, dj_match = get_stable_django() + try: conf_data = config.parse([ '-q', @@ -972,6 +867,9 @@ def unused(self, config_data): reason='django 2+ only supports python 3') def test_parse_config_file(self, *args): """Tests .config.__init__._parse_config_file function.""" + dj_version, __ = get_stable_django(latest=True) + dj_lts_version, __ = get_stable_django(lts=True) + with self.assertRaises(SystemExit) as error: config.parse(self.args[0:1] + [self.conf('config-not-exists.ini')] + self.args[1:]) self.assertEqual(7, error.exception.code) @@ -983,36 +881,36 @@ def test_parse_config_file(self, *args): test_data = [ ('config-02.ini', None, ( - ('cms_version', '3.6'), + ('cms_version', '3.7'), ('db', 'postgres://user:pwd@host:54321/dbname'), - ('django_version', '2.1'), + ('django_version', dj_lts_version), )), ('config-03.ini', None, ( ('cms_version', '3.7'), ('i18n', 'no'), - ('django_version', latest_stable_django), + ('django_version', dj_version), )), ('config-04.ini', None, (('cms_version', '3.7'), ('use_timezone', 'no'))), ('config-05.ini', None, (('cms_version', '3.7'), ('timezone', 'Europe/London'))), ('config-06.ini', None, (('cms_version', '3.7'), ('reversion', 'no'))), - ('config-07.ini', None, (('cms_version', '3.7'), ('permissions', 'no'), ('django_version', '2.2'))), + ('config-07.ini', None, (('cms_version', '3.7'), ('permissions', 'no'), ('django_version', dj_lts_version))), ('config-08.ini', None, ( - ('cms_version', '3.6'), + ('cms_version', '3.7'), ('i18n', 'no'), ('languages', ['ru']), - ('django_version', '2.1') + ('django_version', dj_lts_version) )), ('config-09.ini', None, ( ('cms_version', '3.7'), ('i18n', 'yes'), ('languages', ['en', 'ru']), - ('django_version', '2.2') + ('django_version', dj_lts_version) )), - ('config-10.ini', 'django_version', '1.11'), + ('config-10.ini', 'django_version', dj_lts_version), ('config-11.ini', 'project_directory', '/test/me'), ('config-12.ini', None, ( ('bootstrap', True), - ('django_version', '2.2') + ('django_version', dj_lts_version) )), ('config-13.ini', 'templates', '.'), ('config-14.ini', 'starting_page', True), diff --git a/tests/django.py b/tests/django.py index fe55c7a..b9bb297 100644 --- a/tests/django.py +++ b/tests/django.py @@ -11,7 +11,7 @@ from djangocms_installer import config, django, install -from .base import IsolatedTestClass, get_latest_django, get_latest_djangocms, unittest +from .base import IsolatedTestClass, get_stable_django, get_stable_djangocms, unittest class TestDjango(IsolatedTestClass): @@ -30,7 +30,7 @@ class TestDjango(IsolatedTestClass): ) def test_create_project(self): - dj_version, dj_match = get_latest_django(latest_stable=True) + dj_version, dj_match = get_stable_django() config_data = config.parse(['--db=postgres://user:pwd@host/dbname', '--cms-version=develop', '--django=%s' % dj_version, '-q', '-p' + self.project_dir, 'example_prj']) @@ -39,7 +39,7 @@ def test_create_project(self): self.assertTrue(os.path.exists(os.path.join(self.project_dir, 'example_prj'))) def test_django_admin_errors(self): - dj_version, dj_match = get_latest_django(latest_stable=True) + dj_version, dj_match = get_stable_django() config_data = config.parse(['--db=postgres://user:pwd@host/dbname', '--cms-version=develop', '--django=%s' % dj_version, '-q', '-p' + self.project_dir, 'example_prj']) @@ -53,8 +53,8 @@ def test_copy_data(self): """ Test correct file copying with different switches """ - dj_version, dj_match = get_latest_django(latest_stable=True) - cms_stable, cms_match = get_latest_djangocms() + dj_version, dj_match = get_stable_django() + cms_stable, cms_match = get_stable_djangocms() # Basic template config_data = config.parse(['--db=postgres://user:pwd@host/dbname', @@ -117,9 +117,9 @@ def test_copy_data(self): self.assertTrue(os.path.exists(starting_page_py)) self.assertTrue(os.path.exists(starting_page_json)) - def test_patch_111_settings(self): - dj_version, dj_match = get_latest_django(latest_stable=True, latest_1_x=True) - cms_stable, cms_match = get_latest_djangocms(latest_1_x=True) + def test_patch_22_settings(self): + dj_version, dj_match = get_stable_django() + cms_stable, cms_match = get_stable_djangocms() extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py') config_data = config.parse(['--db=sqlite://localhost/test.db', @@ -147,44 +147,13 @@ def test_patch_111_settings(self): self.assertIsNotNone(getattr(project.settings, 'MIDDLEWARE', None)) self.assertIsNone(getattr(project.settings, 'MIDDLEWARE_CLASSES', None)) - def test_patch_111_36_settings(self): - dj_version, dj_match = get_latest_django(latest_1_x=True) - - extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py') - config_data = config.parse(['--db=sqlite://localhost/test.db', - '--lang=en', '--extra-settings=%s' % extra_path, - '--django-version=%s' % dj_version, - '--cms-version=3.6', '--timezone=Europe/Moscow', - '-q', '-u', '-zno', '--i18n=no', - '-p' + self.project_dir, 'test_patch_111_36_settings']) - install.requirements(config_data.requirements) - django.create_project(config_data) - django.patch_settings(config_data) - django.copy_files(config_data) - # settings is importable even in non django environment - sys.path.append(config_data.project_directory) - - project = __import__(config_data.project_name, globals(), locals(), [str('settings')]) - - # checking for django options - self.assertEqual(project.settings.MEDIA_ROOT, - os.path.join(config_data.project_directory, 'media')) - self.assertEqual(project.settings.MEDIA_URL, '/media/') - - # Data from external settings file - self.assertEqual(project.settings.CUSTOM_SETTINGS_VAR, True) - self.assertEqual(project.settings.CMS_PERMISSION, False) - self.assertEqual(set(project.settings.CMS_TEMPLATES), self.templates_basic) - self.assertIsNotNone(getattr(project.settings, 'MIDDLEWARE', None)) - self.assertIsNone(getattr(project.settings, 'MIDDLEWARE_CLASSES', None)) - - def test_patch_django_111_36(self): - dj_version, dj_match = get_latest_django(latest_1_x=True) + def test_patch_django_22_37(self): + dj_version, dj_match = get_stable_django() config_data = config.parse(['--db=sqlite://localhost/test.db', '--lang=en', '--bootstrap=yes', '--django-version=%s' % dj_version, - '--cms-version=3.6', '--timezone=Europe/Moscow', + '--cms-version=3.7', '--timezone=Europe/Moscow', '-q', '-u', '-zno', '--i18n=no', '-p' + self.project_dir, 'test_patch_django_111_36']) @@ -239,38 +208,16 @@ def test_patch_django_111_36(self): self.assertEqual(len(re.findall('MEDIA_ROOT =', settings)), 1) self.assertEqual(len(re.findall('STATICFILES_DIRS', settings)), 1) - def test_patch_django_111_develop(self): - extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py') - config_data = config.parse(['--db=sqlite://localhost/test.db', - '--lang=en', '--extra-settings=%s' % extra_path, - '--django-version=1.11', '-f', - '--cms-version=develop', '--timezone=Europe/Moscow', - '-q', '-u', '-zno', '--i18n=no', - '-p' + self.project_dir, 'test_patch_django_111_develop']) - install.requirements(config_data.requirements) - django.create_project(config_data) - django.patch_settings(config_data) - django.copy_files(config_data) - # settings is importable even in non django environment - sys.path.append(config_data.project_directory) - - project = __import__(config_data.project_name, globals(), locals(), [str('settings')]) - - # checking for django options - self.assertTrue(project.settings.TEMPLATES) - self.assertFalse(getattr(project.settings, 'TEMPLATES_DIR', False)) - self.assertTrue( - config.get_settings().APPHOOK_RELOAD_MIDDLEWARE_CLASS in - project.settings.MIDDLEWARE - ) - @unittest.skipIf(sys.version_info[:2] not in ((3, 6), (3, 7), (3, 8),), reason='django 3.0 only supports python 3.6, 3.7 and 3.8') def test_patch_django_30_develop(self): + dj_version, dj_match = get_stable_django(latest=True) + extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py') params = [ '--db=sqlite://localhost/test.db', '--lang=en', '--extra-settings=%s' % extra_path, - '--django-version=3.0', '-f', '--cms-version=develop', '--timezone=Europe/Moscow', + '--django-version=%s' % dj_version, + '-f', '--cms-version=develop', '--timezone=Europe/Moscow', '-q', '-u', '-zno', '--i18n=no', '-p' + self.project_dir, 'test_patch_django_30_develop' ] @@ -292,14 +239,14 @@ def test_patch_django_30_develop(self): project.settings.MIDDLEWARE ) - @unittest.skipIf(sys.version_info[:2] not in ((3, 5), (3, 6), (3, 7), (3, 8),), - reason='django 2.2 only supports python 3.5-3.8') def test_patch_django_22_rc(self): + dj_version, dj_match = get_stable_django(lts=True) + extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py') params = [ '--db=sqlite://localhost/test.db', '--lang=en', '--extra-settings=%s' % extra_path, - '--django-version=2.2', '-f', '--cms-version=rc', '--timezone=Europe/Moscow', - '-q', '-u', '-zno', '--i18n=no', '-p' + self.project_dir, + '--django-version=%s' % dj_version, '-f', '--cms-version=rc', + '--timezone=Europe/Moscow', '-q', '-u', '-zno', '--i18n=no', '-p' + self.project_dir, 'test_patch_django_22_rc' ] config_data = config.parse(params) @@ -320,43 +267,15 @@ def test_patch_django_22_rc(self): project.settings.MIDDLEWARE ) - @unittest.skipIf(sys.version_info[:2] not in ((3, 5), (3, 6), (3, 7), (3, 8),), - reason='django 2.1 only supports python 3.5-3.8') - def test_patch_django_21_develop(self): + def test_patch_django_22_develop(self): + dj_version, dj_match = get_stable_django(lts=True) extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py') - params = [ - '--db=sqlite://localhost/test.db', '--lang=en', '--extra-settings=%s' % extra_path, - '--django-version=2.1', '-f', '--cms-version=develop', '--timezone=Europe/Moscow', - '-q', '-u', '-zno', '--i18n=no', '-p' + self.project_dir, - 'test_patch_django_21_develop' - ] - config_data = config.parse(params) - install.requirements(config_data.requirements) - django.create_project(config_data) - django.patch_settings(config_data) - django.copy_files(config_data) - # settings is importable even in non django environment - sys.path.append(config_data.project_directory) - - project = __import__(config_data.project_name, globals(), locals(), [str('settings')]) - - # checking for django options - self.assertTrue(project.settings.TEMPLATES) - self.assertFalse(getattr(project.settings, 'TEMPLATES_DIR', False)) - self.assertTrue( - config.get_settings().APPHOOK_RELOAD_MIDDLEWARE_CLASS in - project.settings.MIDDLEWARE - ) - @unittest.skipIf(sys.version_info[:2] not in ((3, 5), (3, 6), (3, 7), (3, 8),), - reason='django 2.0 only supports python 3.5-3.8') - def test_patch_django_20_develop(self): - extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py') params = [ '--db=sqlite://localhost/test.db', '--lang=en', '--extra-settings=%s' % extra_path, - '--django-version=2.0', '-f', '--cms-version=develop', '--timezone=Europe/Moscow', - '-q', '-u', '-zno', '--i18n=no', '-p' + self.project_dir, - 'test_patch_django_20_develop' + '--django-version=%s' % dj_version, '-f', '--cms-version=develop', + '--timezone=Europe/Moscow', '-q', '-u', '-zno', '--i18n=no', '-p' + self.project_dir, + 'test_patch_django_21_develop' ] config_data = config.parse(params) install.requirements(config_data.requirements) @@ -376,9 +295,9 @@ def test_patch_django_20_develop(self): project.settings.MIDDLEWARE ) - def test_patch_django_111_no_plugins(self): - dj_version, dj_match = get_latest_django(latest_1_x=True) - cms_stable, cms_match = get_latest_djangocms(latest_1_x=True) + def test_patch_django_base_no_plugins(self): + dj_version, dj_match = get_stable_django() + cms_stable, cms_match = get_stable_djangocms() extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py') config_data = config.parse(['--db=sqlite://localhost/test.db', @@ -419,8 +338,8 @@ def test_patch_django_111_no_plugins(self): self.assertFalse('cms.plugins.video' in project.settings.INSTALLED_APPS) def test_patch(self): - dj_version, dj_match = get_latest_django(latest_stable=True) - cms_stable, cms_match = get_latest_djangocms() + dj_version, dj_match = get_stable_django() + cms_stable, cms_match = get_stable_djangocms() config_data = config.parse(['--db=sqlite://localhost/test.db', '--lang=en', @@ -507,8 +426,8 @@ def test_patch(self): del (sys.modules["%s.settings" % config_data.project_name]) def test_database_setup_filer(self): - dj_version, dj_match = get_latest_django(latest_stable=True) - cms_stable, cms_match = get_latest_djangocms() + dj_version, dj_match = get_stable_django() + cms_stable, cms_match = get_stable_djangocms() config_data = config.parse(['--db=sqlite://localhost/test.db', '--cms-version=%s' % cms_stable, @@ -552,8 +471,8 @@ def test_database_setup_filer(self): self.assertTrue('image' in row) def test_starting_page(self): - dj_version, dj_match = get_latest_django(latest_stable=True) - cms_stable, cms_match = get_latest_djangocms() + dj_version, dj_match = get_stable_django() + cms_stable, cms_match = get_stable_djangocms() config_data = config.parse(['--db=sqlite://localhost/test.db', '--cms-version=%s' % cms_stable, @@ -582,8 +501,8 @@ def test_starting_page(self): self.assertTrue('TextPlugin' in row) def test_force_django(self): - dj_version, dj_match = get_latest_django(latest_1_x=True) - cms_stable, cms_match = get_latest_djangocms(latest_1_x=True) + dj_version, dj_match = get_stable_django() + cms_stable, cms_match = get_stable_djangocms() config_data = config.parse(['--db=sqlite://localhost/test.db', '-q', '-u', '--starting-page=yes', @@ -598,15 +517,15 @@ def test_force_django(self): django.patch_settings(config_data) self.assertEqual(error.exception.code, 9) self.assertTrue(self.stderr.getvalue().find( - 'Currently installed Django version 1.8.19 differs from the declared 1.11' + 'Currently installed Django version 1.8.19 differs from the declared %s' % dj_version ) > -1) class TestBaseDjango(unittest.TestCase): def test_build_settings(self): """Tests django.__init__._build_settings function.""" - dj_version, dj_match = get_latest_django(latest_stable=True) - cms_stable, cms_match = get_latest_djangocms() + dj_version, dj_match = get_stable_django() + cms_stable, cms_match = get_stable_djangocms() config_data = config.parse(['--db=postgres://user:pwd@host:5432/dbname', '--cms-version=%s' % cms_stable, '--django=%s' % dj_version, diff --git a/tests/fixtures/configs/config-02.ini b/tests/fixtures/configs/config-02.ini index a6372c7..a02660b 100644 --- a/tests/fixtures/configs/config-02.ini +++ b/tests/fixtures/configs/config-02.ini @@ -6,8 +6,8 @@ timezone = reversion = yes permissions = yes languages = -django-version = 2.1 -cms-version = 3.6 +django-version = 2.2 +cms-version = 3.7 parent-dir = . bootstrap = no templates = no diff --git a/tests/fixtures/configs/config-08.ini b/tests/fixtures/configs/config-08.ini index b3035c2..5bb2c4a 100644 --- a/tests/fixtures/configs/config-08.ini +++ b/tests/fixtures/configs/config-08.ini @@ -6,8 +6,8 @@ timezone = Europe/London reversion = no permissions = no languages = ru -django-version = 2.1 -cms-version = 3.6 +django-version = 2.2 +cms-version = 3.7 parent-dir = . bootstrap = no templates = no diff --git a/tests/fixtures/configs/config-10.ini b/tests/fixtures/configs/config-10.ini index 1d50043..30da1ff 100644 --- a/tests/fixtures/configs/config-10.ini +++ b/tests/fixtures/configs/config-10.ini @@ -6,7 +6,7 @@ timezone = Europe/London reversion = no permissions = no languages = en,ru -django-version = 1.11 +django-version = 2.2 cms-version = lts parent-dir = . bootstrap = no diff --git a/tests/fixtures/configs/config-11.ini b/tests/fixtures/configs/config-11.ini index fdde602..b8d1797 100644 --- a/tests/fixtures/configs/config-11.ini +++ b/tests/fixtures/configs/config-11.ini @@ -6,7 +6,7 @@ timezone = Europe/London reversion = no permissions = no languages = en,ru -django-version = 1.11 +django-version = 2.2 cms-version = 3.7 parent-dir = /test/me bootstrap = no diff --git a/tests/main.py b/tests/main.py index 280c2ab..af794c6 100644 --- a/tests/main.py +++ b/tests/main.py @@ -13,14 +13,14 @@ from djangocms_installer import config, install, main -from .base import IsolatedTestClass, get_latest_django, unittest - -latest_stable_django, latest_stable_django_match = get_latest_django() +from .base import IsolatedTestClass, get_stable_django class TestMain(IsolatedTestClass): def test_requirements_invocation(self): + dj_version, dj_match = get_stable_django(latest=True) + with patch('sys.stdout', self.stdout): with patch('sys.stderr', self.stderr): sys.argv = ['main'] + ['--db=sqlite://localhost/test.db', @@ -29,7 +29,7 @@ def test_requirements_invocation(self): 'example_prj'] main.execute() stdout = self.stdout.getvalue() - self.assertTrue(stdout.find(latest_stable_django_match) > -1) + self.assertTrue(stdout.find(dj_match) > -1) self.assertFalse(stdout.find('django-reversion') > -1) self.assertTrue(stdout.find('djangocms-text-ckeditor') > -1) self.assertTrue(stdout.find('djangocms-admin-style') > -1) @@ -47,13 +47,15 @@ def test_requirements_invocation(self): self.assertTrue(stdout.find('djangocms-video') > -1) def cleanup_ask(self): + dj_version, dj_match = get_stable_django() + with patch('sys.stdout', self.stdout): with patch('sys.stderr', self.stderr): conf_data = config.parse([ '-q', '--db=postgres://user:pwd@host/dbname', '--i18n=no', - '--django-version=1.11', + '--django-version=%s' % dj_version, '-f', '-p'+self.project_dir, 'example_prj']) @@ -61,6 +63,8 @@ def cleanup_ask(self): self.assertFalse(os.path.exists(self.project_dir)) def cleanup_skip(self): + dj_version, dj_match = get_stable_django() + with patch('sys.stdout', self.stdout): with patch('sys.stderr', self.stderr): conf_data = config.parse([ @@ -68,7 +72,7 @@ def cleanup_skip(self): '-s', '--db=postgres://user:pwd@host/dbname', '--i18n=no', - '--django-version=1.11', + '--django-version=%s' % dj_version, '-f', '-p'+self.project_dir, 'example_prj']) @@ -76,7 +80,7 @@ def cleanup_skip(self): self.assertTrue(os.path.exists(self.project_dir)) def test_main_invocation(self): - dj_version, dj_match = get_latest_django(latest_stable=True) + dj_version, dj_match = get_stable_django() base_dir = mkdtemp() project_dir = os.path.join(base_dir, 'example_prj') original_dir = os.getcwd() @@ -124,7 +128,7 @@ def test_base_invocation(self): rmtree(base_dir) def test_two_langs_invocation(self): - dj_version, dj_match = get_latest_django(latest_stable=True) + dj_version, dj_match = get_stable_django() with patch('sys.stdout', self.stdout): with patch('sys.stderr', self.stderr): sys.argv = ['main'] + ['--db=sqlite://localhost/test.db', @@ -139,13 +143,13 @@ def test_two_langs_invocation(self): except Exception as e: print(e) - @unittest.skipIf(sys.version_info < (3.5,), - reason='django 2.0+ does not support python < 3.5') def test_develop(self): + dj_version, dj_match = get_stable_django(lts=True) + with patch('sys.stdout', self.stdout): with patch('sys.stderr', self.stderr): sys.argv = ['main'] + ['--db=sqlite://localhost/test.db', - '-len', '--cms-version=develop', '--django=2.2', + '-len', '--cms-version=develop', '--django=%s' % dj_version, '-q', '-u', '-p'+self.project_dir, 'example_prj'] main.execute() diff --git a/tox.ini b/tox.ini index 11c1732..2eeeb38 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] downloadcache = {toxworkdir}/cache -envlist = pep8,isort,docs,py{38,37,36,35,27} +envlist = pep8,isort,docs,py{38,37,36,35} passenv = LANG [testenv] @@ -36,3 +36,17 @@ deps = sphinx-rtd-theme -rrequirements-test.txt skip_install = true + +[isort] +line_length = 99 +skip = migrations, south_migrations +combine_as_imports = true +default_section = THIRDPARTY +include_trailing_comma = true +known_first_party = djangocms_installer +multi_line_output = 5 +not_skip = __init__.py + +[flake8] +exclude = *.egg-info,.git,.settings,.tox,build,dist,docs,requirements,tmp,*migrations*,*south_migrations*,tests,data,.eggs +max-line-length = 99