def setUp(self): """ Set a few things up for each test """ self.css_compiler = StaticCompiler("css") self.js_compiler = StaticCompiler("js") self.client = Client() self.css_compiler.clean_up() self.js_compiler.clean_up() self._assert_clean()
def add_static(ext): """ Add static files to template """ ext = ext.lower() compiler = StaticCompiler(ext) file_list = compiler.get_staticfiles_list() return render_to_string( "mub/context_%s.html" % ext, { "items": file_list, "STATIC_URL": settings.STATIC_URL, "IS_MINIFIED": compiler.is_minified } )
def handle(self, *args, **options): cache.delete(get_cache_key("css")) cache.delete(get_cache_key("js")) css_compiler = StaticCompiler("css") css_compiler.minify(lock=True) js_compiler = StaticCompiler("js") js_compiler.minify(lock=True)
class CleanableCache(TestCase): """ Standardize setup/teardown across tests """ def setUp(self): """ Set a few things up for each test """ self.css_compiler = StaticCompiler("css") self.js_compiler = StaticCompiler("js") self.client = Client() self.css_compiler.clean_up() self.js_compiler.clean_up() self._assert_clean() def tearDown(self): """ Clean things up after each test """ self.css_compiler.clean_up() self.js_compiler.clean_up() self._assert_clean() def _assert_clean(self): """ Assert that the cache dirs do not exist """ self.assertFalse(os.path.isdir(self.css_compiler.cache_location)) self.assertFalse(os.path.isdir(self.js_compiler.cache_location)) def _assert_cache_exists(self, ext): """ Assert that the cache dir exists """ compiler = getattr(self, "%s_compiler" % ext) self.assertTrue(os.path.isdir(compiler.cache_location)) def remove_static_root(self): """ Clear collectstatic location """ if os.path.isdir(settings.STATIC_ROOT): shutil.rmtree(settings.STATIC_ROOT)