def test_domain_minified(self): bundle_manager = AssetManager(json_setup_path, print_minified=True, domain='http://static.test.com') self.assertEqual(bundle_manager.get_html('bundle2.css'), '<link rel="stylesheet" type="text/css" ' 'href="http://static.test.com/styles/bundle2.min.css"/>') self.assertEqual(bundle_manager.get_html('bundle.js'), '<script type="text/javascript" ' 'src="http://static.test.com/scripts/bundle.min.js"></script>')
def test_no_domain_not_minified(self): bundle_manager = AssetManager(json_setup_path, print_minified=False, domain='') self.assertEqual(bundle_manager.get_html('bundle2.css'), '<link rel="stylesheet" type="text/css" ' 'href="/styles/sprite.css"/>' '<link rel="stylesheet" type="text/css" ' 'href="/styles/color.css"/>' '<link rel="stylesheet" type="text/css" ' 'href="/styles/text.css"/>') self.assertEqual(bundle_manager.get_html('bundle.js'), '<script type="text/javascript" ' 'src="/scripts/page1.js"></script>' '<script type="text/javascript" ' 'src="/scripts/page2.js"></script>')
def test_source_minified(self): bundle_manager = AssetManager(json_setup_path, print_minified=True, domain='') bundle_manager.get('bundle.css').minify() bundle_manager.get('bundle.js').minify() self.assertEqual(bundle_manager.get_html('bundle.css', True), '<style type="text/css">.green{color:green}#nice{color:#fff}' '#try{color:#fefefe}#oh{color:#e96}#my{color:#e96}h1' '{font-weight:bold;font-weight:normal}h2.smaller' '{font-size:12px}</style>') self.assertEqual(bundle_manager.get_html('bundle.js', True), '<script type="text/javascript">/* <![CDATA[ */var ' 'helloVariable="hello",sayHello=function(){alert(helloVariable)};' 'sayHello();(function(){alert("hello")})();\n/* ]]> */</script>') _remove_static_files()
def test_source_non_minified(self): bundle_manager = AssetManager(json_setup_path, print_minified=False, domain='') self.assertEqual(bundle_manager.get_html('bundle.css', True), '<style type="text/css">/* final shouldn\'t have comments ' '*/\n.green {\n color: green; /* here either */\n}\n#nice ' '{\n color: #ffffff;\n}\n#try {\n color: #fefefe;\n}\n#oh ' '{\n color: #e96;\n}\n#my {\n color: ' '#ee9966;\n}\n\n</style><style type="text/css">h1 {\n ' 'font-weight: bold;\n font-weight: normal;\n}\nh2.smaller ' '{\n font-size: 12px;\n}</style>') self.assertEqual(bundle_manager.get_html('bundle.js', True), '<script type="text/javascript">/* <![CDATA[ *//* comments ' 'should be stripped */\nvar helloVariable = \'hello\';\nvar ' 'sayHello = function(removed){\n /* in the middle */\n ' 'alert(helloVariable);\n};\nsayHello(); // these should be ' 'too/* ]]> */</script><script type="text/javascript">/* ' '<![CDATA[ */(function(){\n /* comments should be stripped ' '*/\n var helloVariable = \'hello\';\n var sayHello = ' 'function(removed){\n /* in the middle */\n ' 'alert(helloVariable);\n };\n sayHello(); // these ' 'should be too\n})();/* ]]> */</script>')