|
4 | 4 | from django.template import Template, Context, TemplateSyntaxError
|
5 | 5 | from django.test import TestCase
|
6 | 6 | from django.conf import settings as django_settings
|
| 7 | +from django.core.files.storage import get_storage_class |
7 | 8 | from BeautifulSoup import BeautifulSoup
|
8 | 9 |
|
9 | 10 | from compressor import CssCompressor, JsCompressor
|
@@ -341,3 +342,53 @@ def test_css_tag_with_app_savvy_storage(self):
|
341 | 342 | context = { 'MEDIA_URL': settings.MEDIA_URL }
|
342 | 343 | out = u'<link rel="stylesheet" href="/media/CACHE/css/5dbaaa331670.css" type="text/css" charset="utf-8" />'
|
343 | 344 | 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(' ')) |
0 commit comments