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 5eb9697..ac59224 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -6,3 +6,4 @@ dj-email-url dj-search-url django-cache-url>=1.0.0 six +unittest2 diff --git a/tests/test_main.py b/tests/test_main.py index fb5ebba..e6e1dd2 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)