Add a test which demonstrates the optparse fallback issue

This commit is contained in:
John R Dietrick 2015-09-16 18:06:52 +08:00
parent cd0f1b4d0c
commit 4fe1c74b35
5 changed files with 36 additions and 0 deletions

View file

View file

View file

@ -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

View file

@ -6,3 +6,4 @@ dj-email-url
dj-search-url
django-cache-url>=1.0.0
six
unittest2

View file

@ -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)