'Test the inheritance magic for templates'

def test_templates(self):

    parent = create_page('parent', 'nav_playground.html', 'en')
    child = create_page('child', 'nav_playground.html', 'en', parent=parent)
    grand_child = create_page('grand    child', 'nav_playground.html', 'en', parent=child)
    child2 = create_page('child2', 'col_two.html', 'en', parent=parent)
    grand_child2 = create_page('grand    child2', 'nav_playground.html', 'en', parent=child2)
    child.template = constants.TEMPLATE_INHERITANCE_MAGIC
    grand_child.template = constants.TEMPLATE_INHERITANCE_MAGIC
    child.save()
    grand_child.save()
    grand_child2.template = constants.TEMPLATE_INHERITANCE_MAGIC
    grand_child2.save()
    delattr(grand_child, '_template_cache')
    with self.assertNumQueries(1):
        self.assertEqual(child.template, constants.TEMPLATE_INHERITANCE_MAGIC)
        self.assertEqual(parent.get_template_name(), grand_child.get_template_name())
    with self.assertNumQueries(0):
        grand_child.get_template()
    delattr(grand_child2, '_template_cache')
    with self.assertNumQueries(1):
        self.assertEqual(child2.template, 'col_two.html')
        self.assertEqual(child2.get_template_name(), grand_child2.get_template_name())
    with self.assertNumQueries(0):
        grand_child2.get_template()
    parent.template = constants.TEMPLATE_INHERITANCE_MAGIC
    parent.save()
    self.assertEqual(parent.template, constants.TEMPLATE_INHERITANCE_MAGIC)
    self.assertEqual(parent.get_template(), get_cms_setting('TEMPLATES')[0][0])
    self.assertEqual(parent.get_template_name(), get_cms_setting('TEMPLATES')[0][1])
