Skip to content

Commit

Permalink
Fix django-pipeline tests
Browse files Browse the repository at this point in the history
Change tests after undocumented change in Django.render_js
Complet issue: https://code.djangoproject.com/ticket/31892
  • Loading branch information
TheBuky authored and TheBuky committed Aug 16, 2020
1 parent 7849959 commit f1af32b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ History
of the current version to prevent error while importing. Thank to @vmsp
* Context in django.template.base is removed from Django and
not used anymore in django-pipeline.
* Fixing widgets tests of django-pipeline due to Media.render_js change in
Django. More information in Django ticket #31892

2.0.4
======
Expand Down
4 changes: 2 additions & 2 deletions pipeline/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from io import BytesIO

import django
from django import get_version as django_version

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

if _CACHED_STATIC_FILES_STORAGE_AVAILABLE:
from django.contrib.staticfiles.storage import CachedStaticFilesStorage
Expand Down
7 changes: 5 additions & 2 deletions tests/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django import get_version as django_version
from django.forms import Media
from django.test import TestCase

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

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

self.assertEqual(
MyMedia.js,
Expand All @@ -160,7 +162,7 @@ class MyMedia(PipelineFormMedia):
self.assertEqual(
media.render_js(),
[
'<script type="text/javascript" src="%s"></script>' % path
script_tag % path
for path in (
'/static/extra1.js',
'/static/extra2.js',
Expand All @@ -177,6 +179,7 @@ class MyMedia(PipelineFormMedia):
js = ('extra1.js', 'extra2.js')

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

self.assertEqual(
MyMedia.js,
Expand All @@ -191,7 +194,7 @@ class MyMedia(PipelineFormMedia):
self.assertEqual(
media.render_js(),
[
'<script type="text/javascript" src="%s"></script>' % path
script_tag % path
for path in (
'/static/extra1.js',
'/static/extra2.js',
Expand Down

0 comments on commit f1af32b

Please sign in to comment.