def test_package_css_disabled(self): with pipeline_settings(PIPELINE_ENABLED=False): template = self.env.from_string(u"""{% stylesheet "screen" %}""") self.assertEqual( u'''<link href="/static/pipeline/css/first.css" rel="stylesheet" type="text/css" /> <link href="/static/pipeline/css/second.css" rel="stylesheet" type="text/css" /> <link href="/static/pipeline/css/urls.css" rel="stylesheet" type="text/css" />''', template.render())
def test_post_process(self): with pipeline_settings(PIPELINE_JS_COMPRESSOR=None, PIPELINE_CSS_COMPRESSOR=None): processed_files = self.storage.post_process(SortedDict({ 'css/first.css': (self.storage, 'css/first.css'), 'images/arrow.png': (self.storage, 'images/arrow.png') })) self.assertTrue(('css/first.css', 'css/first.css', True) in processed_files) self.assertTrue(('images/arrow.png', 'images/arrow.png', True) in processed_files)
def test_post_process(self): storage = PipelineStorage() with pipeline_settings(PIPELINE_JS_COMPRESSOR=None, PIPELINE_CSS_COMPRESSOR=None): processed_files = storage.post_process({}) self.assertTrue(('screen.css', 'screen.css', True) in processed_files) self.assertTrue(('scripts.js', 'scripts.js', True) in processed_files)
def test_package_css_debug(self): with pipeline_settings(DEBUG=True): template = self.env.from_string( u"""{% compressed_css "screen" %}""") self.assertEqual( u'''<link href="/static/pipeline/css/first.css" rel="stylesheet" type="text/css" /> <link href="/static/pipeline/css/second.css" rel="stylesheet" type="text/css" /> <link href="/static/pipeline/css/urls.css" rel="stylesheet" type="text/css" />''', template.render())
def test_middleware_pipeline_disabled(self): CUSTOM_MIDDLEWARE = ( 'django.middleware.gzip.GZipMiddleware', 'pipeline.middleware.MinifyHTMLMiddleware', ) + settings.MIDDLEWARE_CLASSES with self.settings(MIDDLEWARE_CLASSES=CUSTOM_MIDDLEWARE): with pipeline_settings(PIPELINE_ENABLED=False): response = self.client.get(reverse('admin:index')) self.assertIn(b' ', response.content)
def test_middleware_pipeline_disabled(self): CUSTOM_MIDDLEWARE = ( 'django.middleware.gzip.GZipMiddleware', 'pipeline.middleware.MinifyHTMLMiddleware', ) + settings.MIDDLEWARE_CLASSES with self.settings(MIDDLEWARE_CLASSES=CUSTOM_MIDDLEWARE): with pipeline_settings(PIPELINE_ENABLED=False): response = self.client.get(reverse('admin:index')) self.assertIn(' ', response.content)
def test_post_process_no_path(self): """ Test post_process with a storage that doesn't implement the path method. """ with override_settings(STATICFILES_STORAGE='tests.tests.test_storage.PipelineNoPathStorage', PIPELINE_COMPILERS=['tests.tests.test_storage.DummyCSSCompiler']): with pipeline_settings(PIPELINE_JS_COMPRESSOR=None, PIPELINE_CSS_COMPRESSOR=None): staticfiles_storage._setup() try: call_command('collectstatic', verbosity=0, interactive=False) except NotImplementedError: self.fail('Received an error running collectstatic')
def _test_compressor(self, compressor_cls, compress_type, expected_file): override_settings = { ("%s_COMPRESSOR" % compress_type.upper()): compressor_cls, } with pipeline_settings(**override_settings): if compress_type == 'js': result = self.compressor.compress_js( [_('pipeline/js/first.js'), _('pipeline/js/second.js')]) else: result = self.compressor.compress_css( [_('pipeline/css/first.css'), _('pipeline/css/second.css')], os.path.join('pipeline', 'css', os.path.basename(expected_file))) with self.compressor.storage.open(expected_file) as f: expected = f.read() self.assertEqual(smart_bytes(result), expected)
def test_post_process_no_path(self): """ Test post_process with a storage that doesn't implement the path method. """ with override_settings( STATICFILES_STORAGE= 'tests.tests.test_storage.PipelineNoPathStorage', PIPELINE_COMPILERS=[ 'tests.tests.test_storage.DummyCSSCompiler' ]): with pipeline_settings(PIPELINE_JS_COMPRESSOR=None, PIPELINE_CSS_COMPRESSOR=None): staticfiles_storage._setup() try: call_command('collectstatic', verbosity=0, interactive=False) except NotImplementedError: self.fail('Received an error running collectstatic')
def test_post_process_dry_run(self): with pipeline_settings(PIPELINE_JS_COMPRESSOR=None, PIPELINE_CSS_COMPRESSOR=None): processed_files = PipelineStorage().post_process({}, True) self.assertEqual(list(processed_files), [])
def test_package_css_debug(self): with pipeline_settings(PIPELINE=False): template = self.env.from_string(u"""{% compressed_css "screen" %}""") self.assertEqual(u'''<link href="/static/pipeline/css/first.css" rel="stylesheet" type="text/css" /> <link href="/static/pipeline/css/second.css" rel="stylesheet" type="text/css" /> <link href="/static/pipeline/css/urls.css" rel="stylesheet" type="text/css" />''', template.render())
def test_post_process_dry_run(self): with pipeline_settings(PIPELINE_JS_COMPRESSOR=None, PIPELINE_CSS_COMPRESSOR=None): processed_files = self.storage.post_process([], True) self.assertEqual(processed_files, [])