Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-pipeline
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-pipeline
Commits
3303786e
Commit
3303786e
authored
Jun 20, 2011
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more test on compressor logic
parent
3e188779
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
15 deletions
+59
-15
tests/static/images/arrow.png
+0
-0
tests/static/images/embed/arrow.png
+0
-0
tests/tests/compressor.py
+59
-15
No files found.
tests/static/images/arrow.png
0 → 100644
View file @
3303786e
107 Bytes
tests/static/images/embed/arrow.png
0 → 100644
View file @
3303786e
107 Bytes
tests/tests/compressor.py
View file @
3303786e
import
base64
import
os
from
mock
import
patch
from
django.test
import
TestCase
from
pipeline.conf
import
settings
from
pipeline.compressors
import
Compressor
from
pipeline.compressors.yui
import
YUICompressor
class
CompressorTest
(
TestCase
):
def
setUp
(
self
):
self
.
compressor
=
Compressor
()
self
.
old_pipeline_url
=
settings
.
PIPELINE_URL
self
.
old_pipeline_root
=
settings
.
PIPELINE_ROOT
settings
.
PIPELINE_URL
=
'http://localhost/static/'
def
test_js_compressor_class
(
self
):
compressor
=
Compressor
()
self
.
assertEquals
(
compressor
.
js_compressor
,
YUICompressor
)
self
.
assertEquals
(
self
.
compressor
.
js_compressor
,
YUICompressor
)
def
test_css_compressor_class
(
self
):
compressor
=
Compressor
()
self
.
assertEquals
(
compressor
.
css_compressor
,
YUICompressor
)
self
.
assertEquals
(
self
.
compressor
.
css_compressor
,
YUICompressor
)
def
test_concatenate_and_rewrite
(
self
):
compressor
=
Compressor
()
css
=
compressor
.
concatenate_and_rewrite
([
os
.
path
.
join
(
settings
.
PIPELINE_ROOT
,
'css/first.css'
),
os
.
path
.
join
(
settings
.
PIPELINE_ROOT
,
'css/second.css'
)
css
=
self
.
compressor
.
concatenate_and_rewrite
([
'css/first.css'
,
'css/second.css'
])
self
.
assertEquals
(
""".concat {
\n
display: none;
\n
}
\n
.concatenate {
\n
display: block;
\n
}"""
,
css
)
def
test_concatenate
(
self
):
compressor
=
Compressor
()
js
=
compressor
.
concatenate
([
os
.
path
.
join
(
settings
.
PIPELINE_ROOT
,
'js/first.js'
),
os
.
path
.
join
(
settings
.
PIPELINE_ROOT
,
'js/second.js'
)
js
=
self
.
compressor
.
concatenate
([
'js/first.js'
,
'js/second.js'
])
self
.
assertEquals
(
"""(function() { function concat() {
\n
console.log(arguments);
\n
}
\n
function cat() {
\n
console.log("hello world");
\n
} }).call(this);"""
,
js
)
@patch.object
(
base64
,
'b64encode'
)
def
test_encoded_content
(
self
,
mock
):
encoded
=
self
.
compressor
.
encoded_content
(
'images/arrow.png'
)
self
.
assertTrue
(
mock
.
called
)
mock
.
reset_mock
()
encoded
=
self
.
compressor
.
encoded_content
(
'images/arrow.png'
)
self
.
assertFalse
(
mock
.
called
)
def
test_relative_path
(
self
):
settings
.
PIPELINE_ROOT
=
'/var/www/static/'
relative_path
=
self
.
compressor
.
relative_path
(
'/var/www/static/images/sprite.png'
)
self
.
assertEquals
(
relative_path
,
'/images/sprite.png'
)
def
test_absolute_path
(
self
):
absolute_path
=
self
.
compressor
.
absolute_path
(
'../../images/sprite.png'
,
'css/plugins/gallery.css'
)
self
.
assertEquals
(
absolute_path
,
'images/sprite.png'
)
absolute_path
=
self
.
compressor
.
absolute_path
(
'/images/sprite.png'
,
'css/plugins/gallery.css'
)
self
.
assertEquals
(
absolute_path
,
'/images/sprite.png'
)
def
test_template_name
(
self
):
name
=
self
.
compressor
.
template_name
(
'templates/photo/detail.jst'
,
'templates/'
)
self
.
assertEquals
(
name
,
'photo_detail'
)
name
=
self
.
compressor
.
template_name
(
'templates/photo_edit.jst'
,
''
)
self
.
assertEquals
(
name
,
'photo_edit'
)
def
test_embeddable
(
self
):
self
.
assertFalse
(
self
.
compressor
.
embeddable
(
'images/sprite.png'
,
None
))
self
.
assertFalse
(
self
.
compressor
.
embeddable
(
'images/arrow.png'
,
'datauri'
))
self
.
assertTrue
(
self
.
compressor
.
embeddable
(
'images/embed/arrow.png'
,
'datauri'
))
self
.
assertFalse
(
self
.
compressor
.
embeddable
(
'images/arrow.dat'
,
'datauri'
))
def
test_construct_asset_path
(
self
):
asset_path
=
self
.
compressor
.
construct_asset_path
(
"../../images/sprite.png"
,
"css/plugins/gallery.css"
)
self
.
assertEquals
(
asset_path
,
"http://localhost/static/images/sprite.png"
)
asset_path
=
self
.
compressor
.
construct_asset_path
(
"/images/sprite.png"
,
"css/plugins/gallery.css"
)
self
.
assertEquals
(
asset_path
,
"http://localhost/static/images/sprite.png"
)
def
test_url_rewrite
(
self
):
compressor
=
Compressor
()
output
=
compressor
.
concatenate_and_rewrite
([
os
.
path
.
join
(
settings
.
PIPELINE_ROOT
,
'css/urls.css'
),
output
=
self
.
compressor
.
concatenate_and_rewrite
([
'css/urls.css'
,
])
self
.
assertEquals
(
""".relative-url {
background-image: url(http://localhost/static/images/sprite-buttons.png);
...
...
@@ -52,3 +95,4 @@ class CompressorTest(TestCase):
def
tearDown
(
self
):
settings
.
PIPELINE_URL
=
self
.
old_pipeline_url
settings
.
PIPELINE_ROOT
=
self
.
old_pipeline_root
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment