Skip to content

Commit f1af32b

Browse files
TheBukyTheBuky
authored andcommitted
Fix django-pipeline tests
Change tests after undocumented change in Django.render_js Complet issue: https://code.djangoproject.com/ticket/31892
1 parent 7849959 commit f1af32b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

HISTORY.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ History
1111
of the current version to prevent error while importing. Thank to @vmsp
1212
* Context in django.template.base is removed from Django and
1313
not used anymore in django-pipeline.
14+
* Fixing widgets tests of django-pipeline due to Media.render_js change in
15+
Django. More information in Django ticket #31892
1416

1517
2.0.4
1618
======

pipeline/storage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from io import BytesIO
44

5-
import django
5+
from django import get_version as django_version
66

7-
_CACHED_STATIC_FILES_STORAGE_AVAILABLE = django.VERSION[0] <= 3 and django.VERSION[1] < 1
7+
_CACHED_STATIC_FILES_STORAGE_AVAILABLE = django_version() < '3.1'
88

99
if _CACHED_STATIC_FILES_STORAGE_AVAILABLE:
1010
from django.contrib.staticfiles.storage import CachedStaticFilesStorage

tests/tests/test_forms.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django import get_version as django_version
12
from django.forms import Media
23
from django.test import TestCase
34

@@ -147,6 +148,7 @@ class MyMedia(PipelineFormMedia):
147148
js = ('extra1.js', 'extra2.js')
148149

149150
media = Media(MyMedia)
151+
script_tag = '<script type="text/javascript" src="%s"></script>' if django_version() < '3.1' else '<script src="%s"></script>'
150152

151153
self.assertEqual(
152154
MyMedia.js,
@@ -160,7 +162,7 @@ class MyMedia(PipelineFormMedia):
160162
self.assertEqual(
161163
media.render_js(),
162164
[
163-
'<script type="text/javascript" src="%s"></script>' % path
165+
script_tag % path
164166
for path in (
165167
'/static/extra1.js',
166168
'/static/extra2.js',
@@ -177,6 +179,7 @@ class MyMedia(PipelineFormMedia):
177179
js = ('extra1.js', 'extra2.js')
178180

179181
media = Media(MyMedia)
182+
script_tag = '<script type="text/javascript" src="%s"></script>' if django_version() < '3.1' else '<script src="%s"></script>'
180183

181184
self.assertEqual(
182185
MyMedia.js,
@@ -191,7 +194,7 @@ class MyMedia(PipelineFormMedia):
191194
self.assertEqual(
192195
media.render_js(),
193196
[
194-
'<script type="text/javascript" src="%s"></script>' % path
197+
script_tag % path
195198
for path in (
196199
'/static/extra1.js',
197200
'/static/extra2.js',

0 commit comments

Comments
 (0)