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
cd14104f
Commit
cd14104f
authored
Jan 02, 2016
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve tests
parent
b68d46e7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
42 deletions
+45
-42
tests/tests/test_compressor.py
+21
-17
tests/tests/test_glob.py
+23
-24
tests/tests/test_template.py
+1
-1
No files found.
tests/tests/test_compressor.py
View file @
cd14104f
...
@@ -2,14 +2,17 @@
...
@@ -2,14 +2,17 @@
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
import
base64
import
base64
import
os
import
io
import
io
import
os
import
sys
try
:
try
:
from
mock
import
patch
from
mock
import
patch
except
ImportError
:
except
ImportError
:
from
unittest.mock
import
patch
# noqa
from
unittest.mock
import
patch
# noqa
from
unittest
import
skipIf
from
django.test
import
TestCase
from
django.test
import
TestCase
from
pipeline.compressors
import
Compressor
,
TEMPLATE_FUNC
,
\
from
pipeline.compressors
import
Compressor
,
TEMPLATE_FUNC
,
\
...
@@ -74,32 +77,32 @@ class CompressorTest(TestCase):
...
@@ -74,32 +77,32 @@ class CompressorTest(TestCase):
self
.
assertEqual
(
base_path
,
_
(
'js/templates'
))
self
.
assertEqual
(
base_path
,
_
(
'js/templates'
))
def
test_absolute_path
(
self
):
def
test_absolute_path
(
self
):
absolute_path
=
self
.
compressor
.
absolute_path
(
'../../images/sprite.png'
,
absolute_path
=
self
.
compressor
.
absolute_path
(
'css/plugins/'
)
'
../../images/sprite.png'
,
'
css/plugins/'
)
self
.
assertEqual
(
absolute_path
,
'images/sprite.png'
)
self
.
assertEqual
(
absolute_path
,
'images/sprite.png'
)
absolute_path
=
self
.
compressor
.
absolute_path
(
'/images/sprite.png'
,
absolute_path
=
self
.
compressor
.
absolute_path
(
'css/plugins/'
)
'
/images/sprite.png'
,
'
css/plugins/'
)
self
.
assertEqual
(
absolute_path
,
'/images/sprite.png'
)
self
.
assertEqual
(
absolute_path
,
'/images/sprite.png'
)
def
test_template_name
(
self
):
def
test_template_name
(
self
):
name
=
self
.
compressor
.
template_name
(
'templates/photo/detail.jst'
,
name
=
self
.
compressor
.
template_name
(
'templates/'
)
'templates/
photo/detail.jst'
,
'templates/
'
)
self
.
assertEqual
(
name
,
'photo_detail'
)
self
.
assertEqual
(
name
,
'photo_detail'
)
name
=
self
.
compressor
.
template_name
(
'templates/photo_edit.jst'
,
''
)
name
=
self
.
compressor
.
template_name
(
'templates/photo_edit.jst'
,
''
)
self
.
assertEqual
(
name
,
'photo_edit'
)
self
.
assertEqual
(
name
,
'photo_edit'
)
name
=
self
.
compressor
.
template_name
(
'templates
\
photo
\
detail.jst'
,
name
=
self
.
compressor
.
template_name
(
'templates
\\
'
)
'templates
\
photo
\
detail.jst'
,
'templates
\
\
'
)
self
.
assertEqual
(
name
,
'photo_detail'
)
self
.
assertEqual
(
name
,
'photo_detail'
)
@pipeline_settings
(
TEMPLATE_SEPARATOR
=
'/'
)
@pipeline_settings
(
TEMPLATE_SEPARATOR
=
'/'
)
def
test_template_name_separator
(
self
):
def
test_template_name_separator
(
self
):
name
=
self
.
compressor
.
template_name
(
'templates/photo/detail.jst'
,
name
=
self
.
compressor
.
template_name
(
'templates/'
)
'templates/
photo/detail.jst'
,
'templates/
'
)
self
.
assertEqual
(
name
,
'photo/detail'
)
self
.
assertEqual
(
name
,
'photo/detail'
)
name
=
self
.
compressor
.
template_name
(
'templates/photo_edit.jst'
,
''
)
name
=
self
.
compressor
.
template_name
(
'templates/photo_edit.jst'
,
''
)
self
.
assertEqual
(
name
,
'photo_edit'
)
self
.
assertEqual
(
name
,
'photo_edit'
)
name
=
self
.
compressor
.
template_name
(
'templates
\
photo
\
detail.jst'
,
name
=
self
.
compressor
.
template_name
(
'templates
\\
'
)
'templates
\
photo
\
detail.jst'
,
'templates
\
\
'
)
self
.
assertEqual
(
name
,
'photo/detail'
)
self
.
assertEqual
(
name
,
'photo/detail'
)
def
test_compile_templates
(
self
):
def
test_compile_templates
(
self
):
...
@@ -118,11 +121,11 @@ class CompressorTest(TestCase):
...
@@ -118,11 +121,11 @@ class CompressorTest(TestCase):
self
.
assertFalse
(
self
.
compressor
.
embeddable
(
_
(
'pipeline/images/arrow.dat'
),
'datauri'
))
self
.
assertFalse
(
self
.
compressor
.
embeddable
(
_
(
'pipeline/images/arrow.dat'
),
'datauri'
))
def
test_construct_asset_path
(
self
):
def
test_construct_asset_path
(
self
):
asset_path
=
self
.
compressor
.
construct_asset_path
(
"../../images/sprite.png"
,
asset_path
=
self
.
compressor
.
construct_asset_path
(
"css/plugins/gallery.css"
,
"css/gallery.css"
)
"
../../images/sprite.png"
,
"
css/plugins/gallery.css"
,
"css/gallery.css"
)
self
.
assertEqual
(
asset_path
,
"../images/sprite.png"
)
self
.
assertEqual
(
asset_path
,
"../images/sprite.png"
)
asset_path
=
self
.
compressor
.
construct_asset_path
(
"/images/sprite.png"
,
asset_path
=
self
.
compressor
.
construct_asset_path
(
"css/plugins/gallery.css"
,
"css/gallery.css"
)
"
/images/sprite.png"
,
"
css/plugins/gallery.css"
,
"css/gallery.css"
)
self
.
assertEqual
(
asset_path
,
"/images/sprite.png"
)
self
.
assertEqual
(
asset_path
,
"/images/sprite.png"
)
def
test_url_rewrite
(
self
):
def
test_url_rewrite
(
self
):
...
@@ -170,6 +173,7 @@ class CompressorTest(TestCase):
...
@@ -170,6 +173,7 @@ class CompressorTest(TestCase):
}
}
"""
,
output
)
"""
,
output
)
@skipIf
(
sys
.
platform
.
startswith
(
"win"
),
"requires posix platform"
)
def
test_compressor_subprocess_unicode
(
self
):
def
test_compressor_subprocess_unicode
(
self
):
path
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
path
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
content
=
io
.
open
(
path
+
'/assets/css/unicode.css'
,
encoding
=
"utf-8"
)
.
read
()
content
=
io
.
open
(
path
+
'/assets/css/unicode.css'
,
encoding
=
"utf-8"
)
.
read
()
...
...
tests/tests/test_glob.py
View file @
cd14104f
...
@@ -52,48 +52,47 @@ class GlobTest(TestCase):
...
@@ -52,48 +52,47 @@ class GlobTest(TestCase):
glob
.
staticfiles_storage
=
self
.
old_storage
glob
.
staticfiles_storage
=
self
.
old_storage
def
test_glob_literal
(
self
):
def
test_glob_literal
(
self
):
self
.
assertSequenceEqual
(
self
.
glob
(
'a'
),
self
.
assertSequenceEqual
(
self
.
glob
(
'a'
),
[
self
.
normpath
(
'a'
)])
[
self
.
normpath
(
'a'
)])
self
.
assertSequenceEqual
(
self
.
glob
(
'a'
,
'D'
),
[
self
.
normpath
(
'a'
,
'D'
)])
self
.
assertSequenceEqual
(
self
.
glob
(
'a'
,
'D'
),
self
.
assertSequenceEqual
(
self
.
glob
(
'aab'
),
[
self
.
normpath
(
'aab'
)])
[
self
.
normpath
(
'a'
,
'D'
)])
self
.
assertSequenceEqual
(
self
.
glob
(
'aab'
),
[
self
.
normpath
(
'aab'
)])
self
.
assertSequenceEqual
(
self
.
glob
(
'zymurgy'
),
[])
self
.
assertSequenceEqual
(
self
.
glob
(
'zymurgy'
),
[])
def
test_glob_one_directory
(
self
):
def
test_glob_one_directory
(
self
):
self
.
assertSequenceEqual
(
self
.
glob
(
'a*'
),
self
.
assertSequenceEqual
(
map
(
self
.
normpath
,
[
'a'
,
'aab'
,
'aaa'
]))
self
.
glob
(
'a*'
),
map
(
self
.
normpath
,
[
'a'
,
'aab'
,
'aaa'
]))
self
.
assertSequenceEqual
(
self
.
glob
(
'*a'
),
self
.
assertSequenceEqual
(
map
(
self
.
normpath
,
[
'a'
,
'aaa'
]))
self
.
glob
(
'*a'
),
map
(
self
.
normpath
,
[
'a'
,
'aaa'
]))
self
.
assertSequenceEqual
(
self
.
glob
(
'aa?'
),
self
.
assertSequenceEqual
(
map
(
self
.
normpath
,
[
'aaa'
,
'aab'
]))
self
.
glob
(
'aa?'
),
map
(
self
.
normpath
,
[
'aaa'
,
'aab'
]))
self
.
assertSequenceEqual
(
self
.
glob
(
'aa[ab]'
),
self
.
assertSequenceEqual
(
map
(
self
.
normpath
,
[
'aaa'
,
'aab'
]))
self
.
glob
(
'aa[ab]'
),
map
(
self
.
normpath
,
[
'aaa'
,
'aab'
]))
self
.
assertSequenceEqual
(
self
.
glob
(
'*q'
),
[])
self
.
assertSequenceEqual
(
self
.
glob
(
'*q'
),
[])
def
test_glob_nested_directory
(
self
):
def
test_glob_nested_directory
(
self
):
if
os
.
path
.
normcase
(
"abCD"
)
==
"abCD"
:
if
os
.
path
.
normcase
(
"abCD"
)
==
"abCD"
:
# case-sensitive filesystem
# case-sensitive filesystem
self
.
assertSequenceEqual
(
self
.
glob
(
'a'
,
'bcd'
,
'E*'
),
self
.
assertSequenceEqual
(
[
self
.
normpath
(
'a'
,
'bcd'
,
'EF'
)])
self
.
glob
(
'a'
,
'bcd'
,
'E*'
),
[
self
.
normpath
(
'a'
,
'bcd'
,
'EF'
)])
else
:
else
:
# case insensitive filesystem
# case insensitive filesystem
self
.
assertSequenceEqual
(
self
.
glob
(
'a'
,
'bcd'
,
'E*'
),
[
self
.
assertSequenceEqual
(
self
.
glob
(
'a'
,
'bcd'
,
'E*'
),
[
self
.
normpath
(
'a'
,
'bcd'
,
'EF'
),
self
.
normpath
(
'a'
,
'bcd'
,
'EF'
),
self
.
normpath
(
'a'
,
'bcd'
,
'efg'
)
self
.
normpath
(
'a'
,
'bcd'
,
'efg'
)
])
])
self
.
assertSequenceEqual
(
self
.
glob
(
'a'
,
'bcd'
,
'*g'
),
self
.
assertSequenceEqual
(
[
self
.
normpath
(
'a'
,
'bcd'
,
'efg'
)])
self
.
glob
(
'a'
,
'bcd'
,
'*g'
),
[
self
.
normpath
(
'a'
,
'bcd'
,
'efg'
)])
def
test_glob_directory_names
(
self
):
def
test_glob_directory_names
(
self
):
self
.
assertSequenceEqual
(
self
.
glob
(
'*'
,
'D'
),
self
.
assertSequenceEqual
(
[
self
.
normpath
(
'a'
,
'D'
)])
self
.
glob
(
'*'
,
'D'
),
[
self
.
normpath
(
'a'
,
'D'
)])
self
.
assertSequenceEqual
(
self
.
glob
(
'*'
,
'*a'
),
[])
self
.
assertSequenceEqual
(
self
.
glob
(
'*'
,
'*a'
),
[])
self
.
assertSequenceEqual
(
self
.
glob
(
'a'
,
'*'
,
'*'
,
'*a'
),
self
.
assertSequenceEqual
(
[
self
.
normpath
(
'a'
,
'bcd'
,
'efg'
,
'ha'
)])
self
.
glob
(
'a'
,
'*'
,
'*'
,
'*a'
),
self
.
assertSequenceEqual
(
self
.
glob
(
'?a?'
,
'*F'
),
[
self
.
normpath
(
'a'
,
'bcd'
,
'efg'
,
'ha'
)])
self
.
assertSequenceEqual
(
self
.
glob
(
'?a?'
,
'*F'
),
map
(
self
.
normpath
,
[
os
.
path
.
join
(
'aaa'
,
'zzzF'
),
map
(
self
.
normpath
,
[
os
.
path
.
join
(
'aaa'
,
'zzzF'
),
os
.
path
.
join
(
'aab'
,
'F'
)]))
os
.
path
.
join
(
'aab'
,
'F'
)]))
def
test_glob_directory_with_trailing_slash
(
self
):
def
test_glob_directory_with_trailing_slash
(
self
):
# We are verifying that when there is wildcard pattern which
# We are verifying that when there is wildcard pattern which
...
...
tests/tests/test_template.py
View file @
cd14104f
...
@@ -14,7 +14,7 @@ from tests.utils import pipeline_settings
...
@@ -14,7 +14,7 @@ from tests.utils import pipeline_settings
class
JinjaTest
(
TestCase
):
class
JinjaTest
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
env
=
Environment
(
extensions
=
[
PipelineExtension
],
self
.
env
=
Environment
(
extensions
=
[
PipelineExtension
],
loader
=
PackageLoader
(
'pipeline'
,
'templates'
))
loader
=
PackageLoader
(
'pipeline'
,
'templates'
))
def
test_no_package
(
self
):
def
test_no_package
(
self
):
template
=
self
.
env
.
from_string
(
u"""{
%
stylesheet "unknow"
%
}"""
)
template
=
self
.
env
.
from_string
(
u"""{
%
stylesheet "unknow"
%
}"""
)
...
...
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