From ba7c06eb61f493839e2c1af7015ac0d342e1935d Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 7 Apr 2014 15:41:18 +0200 Subject: [PATCH 1/4] Unittest for #62 --- .../minify/static/css/test-up-to-date-all.css | 3 +++ .../minify/static/css/test-up-to-date.css | 3 +++ jingo_minify/tests.py | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 examples/minify/static/css/test-up-to-date-all.css create mode 100644 examples/minify/static/css/test-up-to-date.css diff --git a/examples/minify/static/css/test-up-to-date-all.css b/examples/minify/static/css/test-up-to-date-all.css new file mode 100644 index 0000000..54cdb8a --- /dev/null +++ b/examples/minify/static/css/test-up-to-date-all.css @@ -0,0 +1,3 @@ +body { + color: chocolate; +} \ No newline at end of file diff --git a/examples/minify/static/css/test-up-to-date.css b/examples/minify/static/css/test-up-to-date.css new file mode 100644 index 0000000..54cdb8a --- /dev/null +++ b/examples/minify/static/css/test-up-to-date.css @@ -0,0 +1,3 @@ +body { + color: chocolate; +} \ No newline at end of file diff --git a/jingo_minify/tests.py b/jingo_minify/tests.py index 80c9c69..d977a64 100644 --- a/jingo_minify/tests.py +++ b/jingo_minify/tests.py @@ -1,9 +1,12 @@ +import os + from django.conf import settings from django.test.utils import override_settings +from django.core.management import call_command import jingo from mock import ANY, call, patch -from nose.tools import eq_ +from nose.tools import eq_, assert_true, assert_false from .utils import get_media_root, get_media_url @@ -296,3 +299,17 @@ def test_js(getmtime, time): for j in settings.MINIFY_BUNDLES['js']['common']]) eq_(s, expected) + + +@override_settings(MINIFY_BUNDLES={'css': {'test-up-to-date': ['css/test-up-to-date.css'], }}, + JAVA_BIN="java") +def test_non_existing_minified_file(): + """Non existing minified file are minified even if concatenated ones are up to date""" + minified_file = os.path.join( + settings.STATIC_ROOT, + 'css', + 'test-up-to-date-min.css' + ) + assert_false(os.path.isfile(minified_file)) + call_command('compress_assets') + assert_true(os.path.isfile(minified_file)) From 2d9f2e61cea2179f6841150778b758eba7d62260 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 7 Apr 2014 15:48:33 +0200 Subject: [PATCH 2/4] Remove file at the end of the test --- jingo_minify/tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jingo_minify/tests.py b/jingo_minify/tests.py index d977a64..7f0d197 100644 --- a/jingo_minify/tests.py +++ b/jingo_minify/tests.py @@ -313,3 +313,4 @@ def test_non_existing_minified_file(): assert_false(os.path.isfile(minified_file)) call_command('compress_assets') assert_true(os.path.isfile(minified_file)) + os.remove(minified_file) From 32dd396905f61c86918578d76e1bca2f34091466 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 7 Apr 2014 15:50:21 +0200 Subject: [PATCH 3/4] Add missing \n at the end of the CSS files --- examples/minify/static/css/test-up-to-date-all.css | 2 +- examples/minify/static/css/test-up-to-date.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/minify/static/css/test-up-to-date-all.css b/examples/minify/static/css/test-up-to-date-all.css index 54cdb8a..cd204e6 100644 --- a/examples/minify/static/css/test-up-to-date-all.css +++ b/examples/minify/static/css/test-up-to-date-all.css @@ -1,3 +1,3 @@ body { color: chocolate; -} \ No newline at end of file +} diff --git a/examples/minify/static/css/test-up-to-date.css b/examples/minify/static/css/test-up-to-date.css index 54cdb8a..cd204e6 100644 --- a/examples/minify/static/css/test-up-to-date.css +++ b/examples/minify/static/css/test-up-to-date.css @@ -1,3 +1,3 @@ body { color: chocolate; -} \ No newline at end of file +} From 3541a95d9f0d807dcb793b41ebcd21bb0e8fa7cb Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 7 Apr 2014 16:06:57 +0200 Subject: [PATCH 4/4] Check also file content --- jingo_minify/tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jingo_minify/tests.py b/jingo_minify/tests.py index 7f0d197..ad607bb 100644 --- a/jingo_minify/tests.py +++ b/jingo_minify/tests.py @@ -313,4 +313,6 @@ def test_non_existing_minified_file(): assert_false(os.path.isfile(minified_file)) call_command('compress_assets') assert_true(os.path.isfile(minified_file)) + with open(minified_file) as f: + eq_(f.read(), "body{color:chocolate}") os.remove(minified_file)