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
ef130bd4
Commit
ef130bd4
authored
Jul 27, 2012
by
Chris Reeves
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrote Jinja2 tests to test the tags work, else raises failures on exceptions
parent
7f87d3f2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
78 deletions
+16
-78
tests/tests/jinja2.py
+16
-78
No files found.
tests/tests/jinja2.py
View file @
ef130bd4
...
...
@@ -9,44 +9,6 @@ from jinja2 import Environment, FileSystemLoader
from
pipeline.packager
import
PackageNotFound
from
pipeline.jinja2.ext
import
compressed_css
,
compressed_js
,
Jinja2Compressed
EXPECTED_INDIVIDUAL_CSS
=
u'<link href="/static/css/first.css" rel="'
\
'stylesheet" type="text/css" />
\n
<link href="/static/css/second.css" '
\
'rel="stylesheet" type="text/css" />
\n
<link href="/static/css'
\
'/urls.css" rel="stylesheet" type="text/css" />'
EXPECTED_COMPRESSED_CSS
=
u'<link href="/static/screen.css" rel="stylesheet" '
\
'type="text/css" />'
EXPECTED_INDIVIDUAL_JS
=
u'<script type="text/javascript" src="/static/js/'
\
'first.js" charset="utf-8"></script>
\n
<script type="text/'
\
'javascript" src="/static/js/second.js" charset="utf-8">'
\
'</script>
\n
<script type="text/javascript" src="/static/js/'
\
'application.js" charset="utf-8"></script>
\n
<script '
\
'type="text/javascript" charset="utf-8">
\n
window.JST = '
\
'window.JST || {};
\n
var template = function(str){var fn = '
\
'new Function(
\'
obj
\'
,
\'
var __p=[],print=function(){__p.'
\
'push.apply(__p,arguments);};with(obj||{}){__p.push(
\\\'\'
+'
\
'str.replace(/
\\\\
/g,
\'\\\\\\\\\'
).replace(/
\'
/g, "
\\\\\'
").'
\
'replace(/<
%
=([
\\
s
\\
S]+?)
%
>/g,function(match,code){'
\
'return "
\'
,"+code.replace(/
\\\\\'
/g, "
\'
")+",
\'
";}).'
\
'replace(/<
%
([
\\
s
\\
S]+?)
%
>/g,function(match,code){return '
\
'"
\'
);"+code.replace(/
\\\\\'
/g, "
\'
").replace(/[
\\
r
\\
n
\\
t]/g'
\
',
\'
\'
)+"__p.push(
\'
";}).replace(/
\\
r/g,
\'\\\\
r
\'
).replace'
\
'(/
\\
n/g,
\'\\\\
n
\'
).replace(/
\\
t/g,
\'\\\\
t
\'
)+"
\'
);}'
\
'return __p.join(
\'\'
);");return fn;};
\n
window.JST[
\'
'
\
'photo_detail
\'
] = template(
\'
<div class="photo">
\\
n '
\
'<img src="<
%
= src
%
>" />
\\
n <div class="caption">
\\
n '
\
'<
%
= caption
%
> by <
%
= author
%
>
\\
n </div>
\\
n</div>
\'
);
\n
'
\
'window.JST[
\'
photo_list
\'
] = template(
\'
<div class="photo'
\
'">
\\
n <img src="<
%
= src
%
>" />
\\
n <div class="caption">
\\
n '
\
'<
%
= caption
%
>
\\
n </div>
\\
n</div>
\'
);
\n
window.JST[
\'
'
\
'video_detail
\'
] = template(
\'
<div class="video">
\\
n <video '
\
'src="<
%
= src
%
>" />
\\
n <div class="caption">
\\
n <
%
= '
\
'description
%
>
\\
n </div>
\\
n</div>
\'
);
\n\n
</script>'
EXPECTED_COMPRESSED_JS
=
u'<script type="text/css" src="/static/scripts.'
\
'css" charset="utf-8"></script>'
class
Jinja2Test
(
TestCase
):
def
setUp
(
self
):
...
...
@@ -65,58 +27,34 @@ class Jinja2Test(TestCase):
except
PackageNotFound
:
pass
def
test_render_css_debug_is_not_compressed
(
self
):
settings
.
PIPELINE
=
False
compress
=
Jinja2Compressed
(
'css'
)
output
=
compress
.
html
(
'screen'
)
expected
=
EXPECTED_INDIVIDUAL_CSS
self
.
assertEqual
(
output
,
expected
)
def
test_render_css_not_debug_is_compressed
(
self
):
settings
.
PIPELINE
=
True
compress
=
Jinja2Compressed
(
'css'
)
output
=
compress
.
html
(
'screen'
)
expected
=
EXPECTED_COMPRESSED_CSS
self
.
assertEqual
(
output
,
expected
)
def
test_render_js_debug_is_not_compressed
(
self
):
settings
.
PIPELINE
=
False
compress
=
Jinja2Compressed
(
'js'
)
output
=
compress
.
html
(
'scripts'
)
expected
=
EXPECTED_INDIVIDUAL_JS
self
.
assertEqual
(
output
,
expected
)
def
test_render_js_not_debug_is_compressed
(
self
):
settings
.
PIPELINE
=
True
compress
=
Jinja2Compressed
(
'js'
)
output
=
compress
.
html
(
'scripts'
)
expected
=
EXPECTED_COMPRESSED_JS
self
.
assertEqual
(
output
,
expected
)
def
test_template_css_function_individual
(
self
):
settings
.
PIPELINE
=
False
try
:
tpl
=
self
.
environment
.
get_template
(
'css.jinja'
)
output
=
tpl
.
render
()
ex
pected
=
EXPECTED_INDIVIDUAL_CSS
self
.
assertEquals
(
output
,
expected
)
tpl
.
render
()
ex
cept
:
self
.
fail
(
'Failed to load individual JS'
)
def
test_template_css_function_compressed
(
self
):
settings
.
PIPELINE
=
True
try
:
tpl
=
self
.
environment
.
get_template
(
'css.jinja'
)
output
=
tpl
.
render
()
ex
pected
=
EXPECTED_COMPRESSED_CSS
self
.
assertEquals
(
output
,
expected
)
tpl
.
render
()
ex
cept
:
self
.
fail
(
'Failed to load compressed JS'
)
def
test_template_js_function_individual
(
self
):
settings
.
PIPELINE
=
False
try
:
tpl
=
self
.
environment
.
get_template
(
'js.jinja'
)
output
=
tpl
.
render
()
ex
pected
=
EXPECTED_INDIVIDUAL_JS
self
.
assertEquals
(
output
,
expected
)
tpl
.
render
()
ex
cept
:
self
.
fail
(
'Failed to load individual CSS'
)
def
test_template_js_function_compressed
(
self
):
settings
.
PIPELINE
=
True
try
:
tpl
=
self
.
environment
.
get_template
(
'js.jinja'
)
output
=
tpl
.
render
()
ex
pected
=
EXPECTED_COMPRESSED_JS
self
.
assertEquals
(
output
,
expected
)
tpl
.
render
()
ex
cept
:
self
.
fail
(
'Failed to load compressed CSS'
)
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