From f1af32bdb2f6f249c232d88771834c624ee13111 Mon Sep 17 00:00:00 2001 From: TheBuky Date: Sun, 16 Aug 2020 22:17:16 +0000 Subject: [PATCH] Fix django-pipeline tests Change tests after undocumented change in Django.render_js Complet issue: https://code.djangoproject.com/ticket/31892 --- HISTORY.rst | 2 ++ pipeline/storage.py | 4 ++-- tests/tests/test_forms.py | 7 +++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index f616359b..c979f1f3 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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 ====== diff --git a/pipeline/storage.py b/pipeline/storage.py index a7fed8c3..0ea6f42c 100644 --- a/pipeline/storage.py +++ b/pipeline/storage.py @@ -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 diff --git a/tests/tests/test_forms.py b/tests/tests/test_forms.py index 78abca5f..58234b40 100644 --- a/tests/tests/test_forms.py +++ b/tests/tests/test_forms.py @@ -1,3 +1,4 @@ +from django import get_version as django_version from django.forms import Media from django.test import TestCase @@ -147,6 +148,7 @@ class MyMedia(PipelineFormMedia): js = ('extra1.js', 'extra2.js') media = Media(MyMedia) + script_tag = '' if django_version() < '3.1' else '' self.assertEqual( MyMedia.js, @@ -160,7 +162,7 @@ class MyMedia(PipelineFormMedia): self.assertEqual( media.render_js(), [ - '' % path + script_tag % path for path in ( '/static/extra1.js', '/static/extra2.js', @@ -177,6 +179,7 @@ class MyMedia(PipelineFormMedia): js = ('extra1.js', 'extra2.js') media = Media(MyMedia) + script_tag = '' if django_version() < '3.1' else '' self.assertEqual( MyMedia.js, @@ -191,7 +194,7 @@ class MyMedia(PipelineFormMedia): self.assertEqual( media.render_js(), [ - '' % path + script_tag % path for path in ( '/static/extra1.js', '/static/extra2.js',