def test_deactivate_validate_template(self): with SettingsOverride(SEKIZAI_IGNORE_VALIDATION=True): self.assertTrue(validate_template('basic.html', ['js', 'css'])) self.assertTrue(validate_template('basic.html', ['js'])) self.assertTrue(validate_template('basic.html', ['css'])) self.assertTrue(validate_template('basic.html', [])) self.assertTrue(validate_template('basic.html', ['notfound']))
def check_sekizai(output): with output.section("Sekizai") as section: sekizai_installed = is_installed('sekizai') if sekizai_installed: section.success("Sekizai is installed") else: section.error("Sekizai is not installed, could not find 'sekizai' in INSTALLED_APPS") processors = list( chain(*[template['OPTIONS'].get('context_processors', []) for template in settings.TEMPLATES])) if 'sekizai.context_processors.sekizai' in processors: section.success("Sekizai template context processor is installed") else: section.error("Sekizai template context processor is not installed, could not find " "'sekizai.context_processors.sekizai' in TEMPLATES option context_processors") if not sekizai_installed: # sekizai is not installed. # we can't reliable check templates # because template loading won't work return for template, _ in get_cms_setting('TEMPLATES'): if template == constants.TEMPLATE_INHERITANCE_MAGIC: continue if validate_template(template, ['js', 'css']): section.success("Sekizai namespaces 'js' and 'css' found in %r" % template) else: section.error("Sekizai namespaces 'js' and 'css' not found in %r" % template) if section.successful: section.finish_success("Sekizai configuration okay") else: section.finish_error("Sekizai configuration has errors")
def post_patch_check(): """Post patch check, just make sure there isn't any misconfiguration. All the code for checking settings should go here. """ # Ensure templates are set, and more than just the inheritance setting. cms_templates_length = len(settings.CMS_TEMPLATES) if (cms_templates_length < 1 or (cms_templates_length == 1 and settings.CMS_TEMPLATES[0][0] == settings.CMS_TEMPLATE_INHERITANCE_MAGIC)): raise ImproperlyConfigured('Please make sure you specified a CMS_TEMPLATES setting.') # check if is user middleware installed if settings.CMS_PERMISSION and not 'cms.middleware.user.CurrentUserMiddleware' in settings.MIDDLEWARE_CLASSES: raise ImproperlyConfigured('CMS Permission system requires cms.middleware.user.CurrentUserMiddleware.\n' 'Please put it into your MIDDLEWARE_CLASSES in settings file') # check sekizai namespaces try: from django.template.loaders.app_directories import Loader except ImportError: return # south... for template in settings.CMS_TEMPLATES: if template[0] == settings.CMS_TEMPLATE_INHERITANCE_MAGIC: continue if not validate_template(template[0], ['js', 'css']): raise ImproperlyConfigured( "The 'js' and 'css' sekizai namespaces must be present in each template, " "- or a template it inherits from - defined in CMS_TEMPLATES. " "I can't find the namespaces in %r." % template[0] )
def check_sekizai(output): with output.section("Sekizai") as section: if is_installed('sekizai'): section.success("Sekizai is installed") else: section.error("Sekizai is not installed, could not find 'sekizai' in INSTALLED_APPS") if DJANGO_1_7: if 'sekizai.context_processors.sekizai' in settings.TEMPLATE_CONTEXT_PROCESSORS: section.success("Sekizai template context processor is installed") else: section.error("Sekizai template context processor is not installed, could not find 'sekizai.context_processors.sekizai' in TEMPLATE_CONTEXT_PROCESSORS") else: processors = list(chain(*[template['OPTIONS'].get('context_processors', []) for template in settings.TEMPLATES])) if 'sekizai.context_processors.sekizai' in processors: section.success("Sekizai template context processor is installed") else: section.error("Sekizai template context processor is not installed, could not find 'sekizai.context_processors.sekizai' in TEMPLATES option context_processors") for template, _ in get_cms_setting('TEMPLATES'): if template == constants.TEMPLATE_INHERITANCE_MAGIC: continue if validate_template(template, ['js', 'css']): section.success("Sekizai namespaces 'js' and 'css' found in %r" % template) else: section.error("Sekizai namespaces 'js' and 'css' not found in %r" % template) if section.successful: section.finish_success("Sekizai configuration okay") else: section.finish_error("Sekizai configuration has errors")
def test_validate_template_notfound(self): self.assertFalse(validate_template('basic.html', ['notfound']))
def test_validate_template_empty(self): self.assertTrue(validate_template('basic.html', []))
def test_validate_template_css(self): self.assertTrue(validate_template('basic.html', ['css']))
def test_validate_template(self): self.assertTrue(validate_template('basic.html', ['js', 'css'])) self.assertTrue(validate_template('basic.html', ['js'])) self.assertTrue(validate_template('basic.html', ['css'])) self.assertTrue(validate_template('basic.html', [])) self.assertFalse(validate_template('basic.html', ['notfound']))
def validate_test_template(*args, **kwargs): return validate_template(*args, **kwargs)
def test_validate_template_js(self): self.assertTrue(validate_template('sekizai_tests/basic.html', ['js']))
def test_validate_template_js_css(self): self.assertTrue(validate_template('basic.html', ['js', 'css']))
def test_validate_template(self): self.assertTrue(validate_template("basic.html", ["js", "css"])) self.assertTrue(validate_template("basic.html", ["js"])) self.assertTrue(validate_template("basic.html", ["css"])) self.assertTrue(validate_template("basic.html", [])) self.assertFalse(validate_template("basic.html", ["notfound"]))