Added tests for sprites and inline images.
This commit is contained in:
@@ -9,11 +9,12 @@ from scss import (
|
|||||||
Scss, dequote, log, SourceFile, SassRule, config,
|
Scss, dequote, log, SourceFile, SassRule, config,
|
||||||
)
|
)
|
||||||
|
|
||||||
from django_pyscss.utils import find_one_file
|
from django_pyscss.utils import find_one_file, find_all_files
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: It's really gross to modify this global settings variable.
|
||||||
# This is where PyScss is supposed to find the image files for making sprites.
|
# This is where PyScss is supposed to find the image files for making sprites.
|
||||||
config.STATIC_ROOT = find_one_file
|
config.STATIC_ROOT = find_all_files
|
||||||
config.STATIC_URL = staticfiles_storage.url('scss/')
|
config.STATIC_URL = staticfiles_storage.url('scss/')
|
||||||
|
|
||||||
# This is where PyScss places the sprite files.
|
# This is where PyScss places the sprite files.
|
||||||
|
|||||||
1
setup.py
1
setup.py
@@ -17,6 +17,7 @@ install_requires = [
|
|||||||
'PyScss>=1.2.0',
|
'PyScss>=1.2.0',
|
||||||
]
|
]
|
||||||
tests_require = [
|
tests_require = [
|
||||||
|
'Pillow',
|
||||||
'django-compressor>=1.3',
|
'django-compressor>=1.3',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -102,3 +102,22 @@ STATICFILES_FINDERS = (
|
|||||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# LOGGING
|
||||||
|
LOGGING = {
|
||||||
|
'version': 1,
|
||||||
|
'disable_existing_loggers': True,
|
||||||
|
'handlers': {
|
||||||
|
'console':{
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'class': 'logging.StreamHandler',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'loggers': {
|
||||||
|
'': {
|
||||||
|
'handlers': ['console'],
|
||||||
|
'propagate': True,
|
||||||
|
'level': 'INFO',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
BIN
testproject/testproject/static/images/loading.gif
Normal file
BIN
testproject/testproject/static/images/loading.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
@@ -1,66 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
from django.test import TestCase
|
|
||||||
from django.test.utils import override_settings
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
from django_pyscss.scss import DjangoScss
|
|
||||||
|
|
||||||
from tests.utils import clean_css
|
|
||||||
|
|
||||||
|
|
||||||
compiler = DjangoScss(scss_opts={
|
|
||||||
# No compress so that I can compare more easily
|
|
||||||
'compress': 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
def compile_string(string):
|
|
||||||
return compiler.compile(scss_string=string)
|
|
||||||
|
|
||||||
|
|
||||||
IMPORT_FOO = """
|
|
||||||
@import "css/foo.scss";
|
|
||||||
"""
|
|
||||||
|
|
||||||
with open(os.path.join(settings.BASE_DIR, 'testproject', 'static', 'css', 'foo.scss')) as f:
|
|
||||||
FOO_CONTENTS = f.read()
|
|
||||||
|
|
||||||
|
|
||||||
IMPORT_APP1 = """
|
|
||||||
@import "css/app1.scss";
|
|
||||||
"""
|
|
||||||
|
|
||||||
with open(os.path.join(settings.BASE_DIR, 'testapp1', 'static', 'css', 'app1.scss')) as f:
|
|
||||||
APP1_CONTENTS = f.read()
|
|
||||||
|
|
||||||
|
|
||||||
IMPORT_APP2 = """
|
|
||||||
@import "css/app2.scss";
|
|
||||||
"""
|
|
||||||
|
|
||||||
APP2_CONTENTS = FOO_CONTENTS + APP1_CONTENTS
|
|
||||||
|
|
||||||
|
|
||||||
class ImportTestMixin(object):
|
|
||||||
def test_import_from_staticfiles_dirs(self):
|
|
||||||
actual = compile_string(IMPORT_FOO)
|
|
||||||
self.assertEqual(clean_css(actual), clean_css(FOO_CONTENTS))
|
|
||||||
|
|
||||||
def test_import_from_app(self):
|
|
||||||
actual = compile_string(IMPORT_APP1)
|
|
||||||
self.assertEqual(clean_css(actual), clean_css(APP1_CONTENTS))
|
|
||||||
|
|
||||||
def test_imports_within_file(self):
|
|
||||||
actual = compile_string(IMPORT_APP2)
|
|
||||||
self.assertEqual(clean_css(actual), clean_css(APP2_CONTENTS))
|
|
||||||
|
|
||||||
|
|
||||||
@override_settings(DEBUG=True)
|
|
||||||
class FindersImportTest(ImportTestMixin, TestCase):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@override_settings(DEBUG=False)
|
|
||||||
class StorageImportTest(ImportTestMixin, TestCase):
|
|
||||||
pass
|
|
||||||
103
tests/test_scss.py
Normal file
103
tests/test_scss.py
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.test.utils import override_settings
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
from django_pyscss.scss import DjangoScss
|
||||||
|
|
||||||
|
from tests.utils import clean_css
|
||||||
|
|
||||||
|
|
||||||
|
compiler = DjangoScss(scss_opts={
|
||||||
|
# No compress so that I can compare more easily
|
||||||
|
'compress': 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def compile_string(string):
|
||||||
|
return compiler.compile(scss_string=string)
|
||||||
|
|
||||||
|
|
||||||
|
IMPORT_FOO = """
|
||||||
|
@import "css/foo.scss";
|
||||||
|
"""
|
||||||
|
|
||||||
|
with open(os.path.join(settings.BASE_DIR, 'testproject', 'static', 'css', 'foo.scss')) as f:
|
||||||
|
FOO_CONTENTS = f.read()
|
||||||
|
|
||||||
|
|
||||||
|
IMPORT_APP1 = """
|
||||||
|
@import "css/app1.scss";
|
||||||
|
"""
|
||||||
|
|
||||||
|
with open(os.path.join(settings.BASE_DIR, 'testapp1', 'static', 'css', 'app1.scss')) as f:
|
||||||
|
APP1_CONTENTS = f.read()
|
||||||
|
|
||||||
|
|
||||||
|
IMPORT_APP2 = """
|
||||||
|
@import "css/app2.scss";
|
||||||
|
"""
|
||||||
|
|
||||||
|
APP2_CONTENTS = FOO_CONTENTS + APP1_CONTENTS
|
||||||
|
|
||||||
|
|
||||||
|
class ImportTestMixin(object):
|
||||||
|
def test_import_from_staticfiles_dirs(self):
|
||||||
|
actual = compile_string(IMPORT_FOO)
|
||||||
|
self.assertEqual(clean_css(actual), clean_css(FOO_CONTENTS))
|
||||||
|
|
||||||
|
def test_import_from_app(self):
|
||||||
|
actual = compile_string(IMPORT_APP1)
|
||||||
|
self.assertEqual(clean_css(actual), clean_css(APP1_CONTENTS))
|
||||||
|
|
||||||
|
def test_imports_within_file(self):
|
||||||
|
actual = compile_string(IMPORT_APP2)
|
||||||
|
self.assertEqual(clean_css(actual), clean_css(APP2_CONTENTS))
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(DEBUG=True)
|
||||||
|
class FindersImportTest(ImportTestMixin, TestCase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(DEBUG=False)
|
||||||
|
class StorageImportTest(ImportTestMixin, TestCase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
INLINE_IMAGE = """
|
||||||
|
.loading {
|
||||||
|
background: inline_image('images/loading.gif') center no-repeat;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
INLINED_IMAGE_EXPECTED = """
|
||||||
|
.loading {
|
||||||
|
background: url(data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABs0lEQVR4nKXTzUojQRDA8X9/zJCIECRfiDCDBHKZq+QR8nJ5Hl/AQ2QgxyCOoCAy8eIkAxLy0dPWnkzQ7JpdtqAv3fSP6qouJSL8T9jvGy8vLzKdTsmyjDzPGY1G6q+B29tbubm5YTab4b3n4+Njd1ZVlYgIWmuMMeoASNNUrq+vWa/XDAYDkiTh8vJyByil8N7jnCMMQ7HWqh2Q57mMx2OccwyHQ4bD4UHaxhglIuKcY71eU6/XxRijNMDDwwNFUXB1dfXby7t0rVVaa5xzbDYbADTA8/MzWmuSJPmpXp8IVVXtAAtQFAVBEBBF0VEgDENVVZV47/eA1hprLUr92DEAvPfinENrvX/C+fk5QRAwm82OAqvVCuccxpg9EMcxxhienp6OAmVZst1uCcNwD/R6PbrdLo+Pj0wmkz/+7dfXV3l7e8Nay8nJCQDqcxbu7u4kTVNEhH6/TxzHdDodlFKUZclisWA+n1Or1YiiiGazqb4AAPf395JlGe/v71hrCcPwy2o0GlxcXNDpdHbVVt+ncT6fS57nFEXBcrkkCALOzs5otVq0221OT0+/tOoA+Nf4BawEx9v4UlbsAAAAAElFTkSuQmCC) center no-repeat;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
SPRITE_MAP = """
|
||||||
|
$widgets: sprite-map('images/icons/widget-*.png');
|
||||||
|
|
||||||
|
.foo {
|
||||||
|
background: sprite($widgets, 'widget-skull-and-crossbones');
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar {
|
||||||
|
background: sprite($widgets, 'widget-google-map');
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class AssetsTest(TestCase):
|
||||||
|
def test_inline_image(self):
|
||||||
|
actual = compile_string(INLINE_IMAGE)
|
||||||
|
self.assertEqual(clean_css(actual), clean_css(INLINED_IMAGE_EXPECTED))
|
||||||
|
|
||||||
|
def test_sprite_images(self):
|
||||||
|
actual = compile_string(SPRITE_MAP)
|
||||||
|
# pyScss puts a cachebuster query string on the end of the URLs, lets
|
||||||
|
# just check that it made the file that we expected.
|
||||||
|
self.assertIn('KUZdBAnPCdlG5qfocw9GYw.png', actual)
|
||||||
Reference in New Issue
Block a user