diff --git a/configurations/importer.py b/configurations/importer.py index 66cff61..1dad4d7 100644 --- a/configurations/importer.py +++ b/configurations/importer.py @@ -37,9 +37,10 @@ def install(check_options=False): if isinstance(parser, OptionParser): # in case the option_list is set the create_parser # will actually return a OptionParser for backward - # compatibility. It uses BaseCommand.use_argparse - # to decide that, which checks for the option_list list - base.BaseCommand.option_list += configuration_options + # compatibility. In that case we should tack our + # options on to the end of the parser on the way out. + for option in configuration_options: + parser.add_option(option) else: # probably argparse, let's not import argparse though parser.add_argument(CONFIGURATION_ARGUMENT, diff --git a/tests/management/__init__.py b/tests/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/management/commands/__init__.py b/tests/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/management/commands/old_optparse_command.py b/tests/management/commands/old_optparse_command.py new file mode 100644 index 0000000..d7844e5 --- /dev/null +++ b/tests/management/commands/old_optparse_command.py @@ -0,0 +1,16 @@ +from optparse import make_option +from django.core.management.base import BaseCommand + + +class Command(BaseCommand): + + # Used by a specific test to see how unupgraded + # management commands play with configurations. + # See the test code for more details. + + option_list = BaseCommand.option_list + ( + make_option('--arg1', action='store_true'), + ) + + def handle(self, *args, **options): + pass diff --git a/tests/requirements.txt b/tests/requirements.txt index e231ad5..ac59224 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -4,5 +4,6 @@ mock dj-database-url dj-email-url dj-search-url -django-cache-url>=0.6.0 +django-cache-url>=1.0.0 six +unittest2 diff --git a/tests/test_main.py b/tests/test_main.py index fb5ebba..248084d 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,7 +1,9 @@ import os import subprocess import sys +import unittest2 +from django import VERSION as DJANGO_VERSION from django.conf import global_settings from django.test import TestCase from django.core.exceptions import ImproperlyConfigured @@ -108,3 +110,20 @@ class MainTests(TestCase): proc = subprocess.Popen(['django-cadmin', 'runserver', '--help'], stdout=subprocess.PIPE) self.assertIn('--configuration', proc.communicate()[0].decode('utf-8')) + + @unittest2.skipIf(DJANGO_VERSION > (1, 10), 'only applies to Django < 1.10') + def test_deprecated_option_list_command(self): + """ + Verify that the configuration option is correctly added to any + management commands which are still relying on option_list to + add their own custom arguments + + Specific test for a pattern which was deprecated in Django 1.8 + and which will become completely unsupported in Django 1.10. + https://docs.djangoproject.com/en/1.8/howto/custom-management-commands/#custom-commands-options + """ + proc = subprocess.Popen(['django-cadmin', 'old_optparse_command', '--help'], + stdout=subprocess.PIPE) + output = proc.communicate()[0].decode('utf-8') + self.assertIn('--configuration', output) + self.assertIn('--arg1', output) diff --git a/tests/test_values.py b/tests/test_values.py index 482799a..6f76ce4 100644 --- a/tests/test_values.py +++ b/tests/test_values.py @@ -407,20 +407,19 @@ class ValueTests(TestCase): def test_cache_url_value(self): cache_setting = { 'default': { - 'BACKEND': 'redis_cache.cache.RedisCache', - 'KEY_PREFIX': '', - 'LOCATION': 'host:port:1' + 'BACKEND': 'django_redis.cache.RedisCache', + 'LOCATION': 'host:12345:1' } } - cache_url = 'redis://user@host:port/1' + cache_url = 'redis://user@host:12345/1' value = CacheURLValue(cache_url) self.assertEqual(value.default, cache_setting) value = CacheURLValue() self.assertEqual(value.default, {}) - with env(CACHE_URL='redis://user@host:port/1'): + with env(CACHE_URL='redis://user@host:12345/1'): self.assertEqual(value.setup('CACHE_URL'), cache_setting) - with env(CACHE_URL='wrong://user@host:port/1'): - self.assertRaises(KeyError, value.setup, 'TEST') + with env(CACHE_URL='wrong://user@host:12345/1'): + self.assertRaisesRegexp(Exception, 'Unknown backend: "wrong"', value.setup, 'TEST') def test_search_url_value(self): value = SearchURLValue() diff --git a/tox.ini b/tox.ini index f4d0f6c..b8844f2 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,8 @@ envlist = flake8-py33, py{26,py}-dj{14,15,16}, py27-dj{14,15,16,17,18,19}, - py{32,33,34,py}-dj{15,16,17,18,19} + py{32,33,34,py}-dj{15,16,17,18} + py{34,py}-dj19 [testenv] basepython =