Skip to content

Commit f2366b5

Browse files
committed
Merge pull request jazzband#544 from slafs/slafs/test-against-older-djangos
Add support for older Djangos
2 parents 8b30436 + 235a226 commit f2366b5

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ python:
33
- 3.5
44
sudo: false
55
env:
6+
- TOXENV=py27-django16
7+
- TOXENV=py34-django16
8+
- TOXENV=pypy-django16
9+
- TOXENV=py27-django17
10+
- TOXENV=py34-django17
11+
- TOXENV=pypy-django17
612
- TOXENV=py27-django18
713
- TOXENV=pypy-django18
814
- TOXENV=py34-django18

tests/tests/test_storage.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
from django.contrib.staticfiles.storage import staticfiles_storage
55
from django.core.management import call_command
66
from django.test import TestCase
7-
from django.test.utils import override_settings, modify_settings
7+
from django.test.utils import override_settings
8+
9+
try:
10+
from django.test.utils import modify_settings
11+
except ImportError:
12+
# Django < 1.7
13+
from tests.utils import modify_settings
814

915
from pipeline.collector import default_collector
1016
from pipeline.storage import PipelineStorage

tests/utils.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import os
22

3-
from django.test import override_settings
3+
from django.conf import settings
4+
from django.utils import six
5+
6+
try:
7+
from django.test import override_settings
8+
except ImportError:
9+
# Django < 1.7
10+
from django.test.utils import override_settings
411

512

613
def _(path):
@@ -11,3 +18,51 @@ def _(path):
1118
class pipeline_settings(override_settings):
1219
def __init__(self, **kwargs):
1320
self.options = {'PIPELINE': kwargs}
21+
22+
23+
# Django < 1.7 (copy-pasted from Django 1.7)
24+
class modify_settings(override_settings):
25+
"""
26+
Like override_settings, but makes it possible to append, prepend or remove
27+
items instead of redefining the entire list.
28+
"""
29+
def __init__(self, *args, **kwargs):
30+
if args:
31+
# Hack used when instantiating from SimpleTestCase._pre_setup.
32+
assert not kwargs
33+
self.operations = args[0]
34+
else:
35+
assert not args
36+
self.operations = list(kwargs.items())
37+
38+
def save_options(self, test_func):
39+
if test_func._modified_settings is None:
40+
test_func._modified_settings = self.operations
41+
else:
42+
# Duplicate list to prevent subclasses from altering their parent.
43+
test_func._modified_settings = list(
44+
test_func._modified_settings) + self.operations
45+
46+
def enable(self):
47+
self.options = {}
48+
for name, operations in self.operations:
49+
try:
50+
# When called from SimpleTestCase._pre_setup, values may be
51+
# overridden several times; cumulate changes.
52+
value = self.options[name]
53+
except KeyError:
54+
value = list(getattr(settings, name, []))
55+
for action, items in operations.items():
56+
# items my be a single value or an iterable.
57+
if isinstance(items, six.string_types):
58+
items = [items]
59+
if action == 'append':
60+
value = value + [item for item in items if item not in value]
61+
elif action == 'prepend':
62+
value = [item for item in items if item not in value] + value
63+
elif action == 'remove':
64+
value = [item for item in value if item not in items]
65+
else:
66+
raise ValueError("Unsupported action: %s" % action)
67+
self.options[name] = value
68+
super(modify_settings, self).enable()

tox.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
envlist =
3-
{py27,pypy,py34}-django{18,19},py35-django19,docs
3+
{py27,pypy,py34}-django{16,17,18,19},py35-django19,docs
44

55
[testenv]
66
basepython =
@@ -11,6 +11,8 @@ basepython =
1111
deps =
1212
py{27,py}: mock
1313
py{27,py}: futures
14+
django16: Django>=1.6,<1.7
15+
django17: Django>=1.7,<1.8
1416
django18: Django>=1.8,<1.9
1517
django19: Django>=1.9,<1.10
1618
jinja2

0 commit comments

Comments
 (0)