Commit ef130bd4 by Chris Reeves

Rewrote Jinja2 tests to test the tags work, else raises failures on exceptions

parent 7f87d3f2
...@@ -9,44 +9,6 @@ from jinja2 import Environment, FileSystemLoader ...@@ -9,44 +9,6 @@ from jinja2 import Environment, FileSystemLoader
from pipeline.packager import PackageNotFound from pipeline.packager import PackageNotFound
from pipeline.jinja2.ext import compressed_css, compressed_js, Jinja2Compressed 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 || {};\nvar 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;};\nwindow.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>\');\nwindow.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): class Jinja2Test(TestCase):
def setUp(self): def setUp(self):
...@@ -65,58 +27,34 @@ class Jinja2Test(TestCase): ...@@ -65,58 +27,34 @@ class Jinja2Test(TestCase):
except PackageNotFound: except PackageNotFound:
pass 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): def test_template_css_function_individual(self):
settings.PIPELINE = False settings.PIPELINE = False
try:
tpl = self.environment.get_template('css.jinja') tpl = self.environment.get_template('css.jinja')
output = tpl.render() tpl.render()
expected = EXPECTED_INDIVIDUAL_CSS except:
self.assertEquals(output, expected) self.fail('Failed to load individual JS')
def test_template_css_function_compressed(self): def test_template_css_function_compressed(self):
settings.PIPELINE = True settings.PIPELINE = True
try:
tpl = self.environment.get_template('css.jinja') tpl = self.environment.get_template('css.jinja')
output = tpl.render() tpl.render()
expected = EXPECTED_COMPRESSED_CSS except:
self.assertEquals(output, expected) self.fail('Failed to load compressed JS')
def test_template_js_function_individual(self): def test_template_js_function_individual(self):
settings.PIPELINE = False settings.PIPELINE = False
try:
tpl = self.environment.get_template('js.jinja') tpl = self.environment.get_template('js.jinja')
output = tpl.render() tpl.render()
expected = EXPECTED_INDIVIDUAL_JS except:
self.assertEquals(output, expected) self.fail('Failed to load individual CSS')
def test_template_js_function_compressed(self): def test_template_js_function_compressed(self):
settings.PIPELINE = True settings.PIPELINE = True
try:
tpl = self.environment.get_template('js.jinja') tpl = self.environment.get_template('js.jinja')
output = tpl.render() tpl.render()
expected = EXPECTED_COMPRESSED_JS except:
self.assertEquals(output, expected) self.fail('Failed to load compressed CSS')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment