Merge remote-tracking branch 'jdietrick/master' into upstream

Conflicts:
	.travis.yml
This commit is contained in:
James Keys 2015-12-18 09:51:46 +07:00
commit 0a4f776df1
8 changed files with 49 additions and 12 deletions

View file

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

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

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

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)

View file

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

View file

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