Skip to content

Commit c1c2fa6

Browse files
committed
Tests for storage
1 parent deeaf61 commit c1c2fa6

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

tests/core/media/core/css/test.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
margin: 0px;
3+
}

tests/core/tests.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.template import Template, Context, TemplateSyntaxError
55
from django.test import TestCase
66
from django.conf import settings as django_settings
7+
from django.core.files.storage import get_storage_class
78
from BeautifulSoup import BeautifulSoup
89

910
from compressor import CssCompressor, JsCompressor
@@ -341,3 +342,53 @@ def test_css_tag_with_app_savvy_storage(self):
341342
context = { 'MEDIA_URL': settings.MEDIA_URL }
342343
out = u'<link rel="stylesheet" href="/media/CACHE/css/5dbaaa331670.css" type="text/css" charset="utf-8" />'
343344
self.assertEqual(out, render(template, context))
345+
346+
def test_can_get_css_from_one_app(self):
347+
template = u"""{% load compress %}{% compress css %}
348+
<link rel="stylesheet" href="/media/core/css/test.css" type="text/css" charset="utf-8">
349+
{% endcompress %}
350+
"""
351+
context = { 'MEDIA_URL': settings.MEDIA_URL }
352+
out = u'<link rel="stylesheet" href="/media/CACHE/css/553cd2310726.css" type="text/css" charset="utf-8" />'
353+
self.assertEqual(out, render(template, context))
354+
355+
expected_content = u"""
356+
body {
357+
margin: 0px;
358+
}
359+
""".replace('\n', '')
360+
361+
storage = get_storage_class(settings.STORAGE)
362+
file_dir = os.path.dirname(__file__)
363+
file_path = os.path.abspath(os.path.join(file_dir, '../media/cache/css/553cd2310726.css'))
364+
actual_content = open(file_path, 'r').read().replace('\n', '')
365+
366+
self.assertEqual(expected_content.strip(' '),
367+
actual_content.strip(' '))
368+
369+
def test_can_get_css_from_many_apps(self):
370+
template = u"""{% load compress %}{% compress css %}
371+
<link rel="stylesheet" href="/media/core/css/test.css" type="text/css" charset="utf-8">
372+
<link rel="stylesheet" href="/media/otherapp/css/test2.css" type="text/css" charset="utf-8">
373+
{% endcompress %}
374+
"""
375+
context = { 'MEDIA_URL': settings.MEDIA_URL }
376+
out = u'<link rel="stylesheet" href="/media/CACHE/css/d191838f3e88.css" type="text/css" charset="utf-8" />'
377+
self.assertEqual(out, render(template, context))
378+
379+
expected_content = u"""
380+
body {
381+
margin: 0px;
382+
}
383+
body {
384+
background: red;
385+
}
386+
""".replace('\n', '')
387+
388+
storage = get_storage_class(settings.STORAGE)
389+
file_dir = os.path.dirname(__file__)
390+
file_path = os.path.abspath(os.path.join(file_dir, '../media/cache/css/d191838f3e88.css'))
391+
actual_content = open(file_path, 'r').read().replace('\n', '')
392+
393+
self.assertEqual(expected_content.strip(' '),
394+
actual_content.strip(' '))

tests/otherapp/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background: red;
3+
}

tests/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
INSTALLED_APPS = [
1616
'core',
17+
'otherapp',
1718
'compressor',
1819
]
1920
TEMPLATE_LOADERS = (

0 commit comments

Comments
 (0)