def test_concatenate_and_rewrite(self): css = self.compressor.concatenate_and_rewrite( [_('pipeline/css/first.css'), _('pipeline/css/second.css')], 'css/screen.css') self.assertEquals( """.concat {\n display: none;\n}\n\n.concatenate {\n display: block;\n}\n""", css)
def test_concatenate(self): js = self.compressor.concatenate( [_('pipeline/js/first.js'), _('pipeline/js/second.js')]) self.assertEquals( """function concat() {\n console.log(arguments);\n}\n\nfunction cat() {\n console.log("hello world");\n}\n""", js)
def test_compile(self): paths = self.compiler.compile([ _('pipeline/js/dummy.coffee'), _('pipeline/js/application.js'), ]) self.assertEquals( [_('pipeline/js/dummy.js'), _('pipeline/js/application.js')], paths)
def test_compile_templates(self): templates = self.compressor.compile_templates([_('pipeline/templates/photo/list.jst')]) self.assertEquals(templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'list\'] = template(\'<div class="photo">\\n <img src="<%%= src %%>" />\\n <div class="caption">\\n <%%= caption %%>\\n </div>\\n</div>\');\n""" % TEMPLATE_FUNC) templates = self.compressor.compile_templates([ _('pipeline/templates/video/detail.jst'), _('pipeline/templates/photo/detail.jst') ]) self.assertEqual(templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'video_detail\'] = template(\'<div class="video">\\n <video src="<%%= src %%>" />\\n <div class="caption">\\n <%%= description %%>\\n </div>\\n</div>\');\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""" % TEMPLATE_FUNC)
def test_compile(self): paths = self.compiler.compile([ _('pipeline/js/dummy.coffee'), _('pipeline/js/application.js'), ]) self.assertEquals( [_('pipeline/js/dummy.js'), _('pipeline/js/application.js')], paths )
def test_templates(self): packager = Packager() packages = packager.create_packages({ 'templates': { 'source_filenames': ( _('pipeline/templates/photo/list.jst'), ), 'output_filename': 'templates.js', } }) self.assertEqual(packages['templates'].templates, [_('pipeline/templates/photo/list.jst')])
def test_embeddable(self): self.assertFalse( self.compressor.embeddable(_('pipeline/images/sprite.png'), None)) self.assertFalse( self.compressor.embeddable(_('pipeline/images/arrow.png'), 'datauri')) self.assertTrue( self.compressor.embeddable(_('pipeline/images/embed/arrow.png'), 'datauri')) self.assertFalse( self.compressor.embeddable(_('pipeline/images/arrow.dat'), 'datauri'))
def setUp(self): settings.PIPELINE_CSS = { 'testing': { 'source_filenames': ( _('pipeline/css/first.css'), _('css/third.css'), ), 'manifest': False, 'output_filename': 'testing.css', } } settings.PIPELINE_JS_COMPRESSOR = None settings.PIPELINE_CSS_COMPRESSOR = None self.storage = PipelineStorage()
def test_compile_templates(self): templates = self.compressor.compile_templates( [_('pipeline/templates/photo/list.jst')]) self.assertEquals( templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'list\'] = template(\'<div class="photo">\\n <img src="<%%= src %%>" />\\n <div class="caption">\\n <%%= caption %%>\\n </div>\\n</div>\');\n""" % TEMPLATE_FUNC) templates = self.compressor.compile_templates([ _('pipeline/templates/video/detail.jst'), _('pipeline/templates/photo/detail.jst') ]) self.assertEqual( templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'video_detail\'] = template(\'<div class="video">\\n <video src="<%%= src %%>" />\\n <div class="caption">\\n <%%= description %%>\\n </div>\\n</div>\');\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""" % TEMPLATE_FUNC)
def test_url_rewrite(self): output = self.compressor.concatenate_and_rewrite([ _('pipeline/css/urls.css'), ], 'css/screen.css') self.assertEquals( u"""@font-face { font-family: 'Pipeline'; src: url(../pipeline/fonts/pipeline.eot); src: url(../pipeline/fonts/pipeline.eot?#iefix) format('embedded-opentype'); src: local('☺'), url(../pipeline/fonts/pipeline.woff) format('woff'), url(../pipeline/fonts/pipeline.ttf) format('truetype'), url(../pipeline/fonts/pipeline.svg#IyfZbseF) format('svg'); font-weight: normal; font-style: normal; } .relative-url { background-image: url(../pipeline/images/sprite-buttons.png); } .absolute-url { background-image: url(/images/sprite-buttons.png); } .absolute-full-url { background-image: url(http://localhost/images/sprite-buttons.png); } .no-protocol-url { background-image: url(//images/sprite-buttons.png); }""", output)
def test_package_for(self): packager = Packager() packager.packages['js'] = packager.create_packages({ 'application': { 'source_filenames': ( _('pipeline/js/application.js'), ), 'output_filename': 'application.js' } }) try: packager.package_for('js', 'application') except PackageNotFound: self.fail() try: packager.package_for('js', 'broken') self.fail() except PackageNotFound: pass
def test_url_rewrite(self): output = self.compressor.concatenate_and_rewrite([ _('pipeline/css/urls.css'), ], 'css/screen.css') self.assertEquals(u"""@font-face { font-family: 'Pipeline'; src: url(../pipeline/fonts/pipeline.eot); src: url(../pipeline/fonts/pipeline.eot?#iefix) format('embedded-opentype'); src: local('☺'), url(../pipeline/fonts/pipeline.woff) format('woff'), url(../pipeline/fonts/pipeline.ttf) format('truetype'), url(../pipeline/fonts/pipeline.svg#IyfZbseF) format('svg'); font-weight: normal; font-style: normal; } .relative-url { background-image: url(../pipeline/images/sprite-buttons.png); } .absolute-url { background-image: url(/images/sprite-buttons.png); } .absolute-full-url { background-image: url(http://localhost/images/sprite-buttons.png); } .no-protocol-url { background-image: url(//images/sprite-buttons.png); }""", output)
def test_base_path(self): base_path = self.compressor.base_path( [_('js/templates/form.jst'), _('js/templates/field.jst')]) self.assertEquals(base_path, _('js/templates'))
def test_encoded_content(self, mock): self.compressor.encoded_content(_('pipeline/images/arrow.png')) self.assertTrue(mock.called) mock.reset_mock() self.compressor.encoded_content(_('pipeline/images/arrow.png')) self.assertFalse(mock.called)
def test_concatenate_and_rewrite(self): css = self.compressor.concatenate_and_rewrite([ _('pipeline/css/first.css'), _('pipeline/css/second.css') ], 'css/screen.css') self.assertEquals(""".concat {\n display: none;\n}\n\n.concatenate {\n display: block;\n}\n""", css)
def test_concatenate(self): js = self.compressor.concatenate([ _('pipeline/js/first.js'), _('pipeline/js/second.js') ]) self.assertEquals("""function concat() {\n console.log(arguments);\n}\n\nfunction cat() {\n console.log("hello world");\n}\n""", js)
def test_base_path(self): base_path = self.compressor.base_path([ _('js/templates/form.jst'), _('js/templates/field.jst') ]) self.assertEquals(base_path, _('js/templates'))
def test_embeddable(self): self.assertFalse(self.compressor.embeddable(_('pipeline/images/sprite.png'), None)) self.assertFalse(self.compressor.embeddable(_('pipeline/images/arrow.png'), 'datauri')) self.assertTrue(self.compressor.embeddable(_('pipeline/images/embed/arrow.png'), 'datauri')) self.assertFalse(self.compressor.embeddable(_('pipeline/images/arrow.dat'), 'datauri'))