def validate_template(template, namespaces): """ Validates that a template (or it's parents if check_inheritance is True) contain all given namespaces """ if getattr(settings, 'SEKIZAI_IGNORE_VALIDATION', False): return True found = get_namespaces(template) for namespace in namespaces: if namespace not in found: return False return True
def test_get_namespaces(self): self.assertEqual(get_namespaces('easy_inherit.html'), ['css']) self.assertEqual(get_namespaces('inherit/chain.html'), ['css', 'js']) self.assertEqual(get_namespaces('inherit/spacechain.html'), ['css', 'js']) self.assertEqual(get_namespaces('inherit/varchain.html'), []) self.assertEqual(get_namespaces('inherit/subvarchain.html'), []) self.assertEqual(get_namespaces('inherit/nullext.html'), [])
def test_get_namespaces(self): self.assertEqual(get_namespaces("easy_inherit.html"), ["css"]) self.assertEqual(get_namespaces("inherit/chain.html"), ["css", "js"]) self.assertEqual(get_namespaces("inherit/spacechain.html"), ["css", "js"]) self.assertEqual(get_namespaces("inherit/varchain.html"), []) self.assertEqual(get_namespaces("inherit/subvarchain.html"), []) self.assertEqual(get_namespaces("inherit/nullext.html"), [])
def test_get_namespaces_null_ext(self): self.assertEqual(get_namespaces('inherit/nullext.html'), [])
def test_get_namespaces_sub_var_inherit(self): self.assertEqual(get_namespaces('inherit/subvarchain.html'), [])
def test_get_namespaces_space_chain_inherit(self): self.assertEqual(get_namespaces('inherit/spacechain.html'), ['css', 'js'])
def test_get_namespaces_easy_inherit(self): self.assertEqual(get_namespaces('easy_inherit.html'), ['css'])
def test_get_namespaces_space_chain_inherit(self): self.assertEqual( get_namespaces('inherit/spacechain.html'), ['css', 'js'] )
def get_test_namespaces(*args, **kwargs): return get_namespaces(*args, **kwargs)
def test_get_namespaces_var_inherit(self): self.assertEqual(get_namespaces('sekizai_tests/inherit/varchain.html'), [])
def test_get_namespaces_chain_inherit(self): self.assertEqual(get_namespaces('sekizai_tests/inherit/chain.html'), ['css', 'js'])