from django.test import TestCase
from django import template
from django.conf import settings
+ from django.db import connection
+from django.template import loader
+from django.template.loaders import cached
from philo.exceptions import AncestorDoesNotExist
from philo.models import Node, Page, Template
from philo.contrib.penfield.models import Blog, BlogView, BlogEntry
def test_get_path(self):
root = Node.objects.get(slug='root')
+ root2 = Node.objects.get(slug='root')
third = Node.objects.get(slug='third')
- r1 = Node.objects.get(slug='recursive1')
- r2 = Node.objects.get(slug='recursive2')
- pr1 = Node.objects.get(slug='postrecursive1')
-
- # Simple case: straight path to None
- self.assertEqual(root.get_path(), 'root')
- self.assertEqual(third.get_path(), 'root/never/more/second/third')
-
- # Recursive case: Looped path to root None
- self.assertEqual(r1.get_path(), u'\u2026/recursive1/recursive2/recursive3/recursive1')
- self.assertEqual(pr1.get_path(), u'\u2026/recursive3/recursive1/recursive2/recursive3/postrecursive1')
-
- # Simple error case: straight invalid path
- self.assertRaises(AncestorDoesNotExist, root.get_path, root=third)
- self.assertRaises(AncestorDoesNotExist, third.get_path, root=pr1)
-
- # Recursive error case
- self.assertRaises(AncestorDoesNotExist, r1.get_path, root=root)
- self.assertRaises(AncestorDoesNotExist, pr1.get_path, root=third)
+ second2 = Node.objects.get(slug='second2')
+ fifth = Node.objects.get(slug='fifth')
+ e = AncestorDoesNotExist
+
+ self.assertQueryLimit(0, 'root', callable=root.get_path)
+ self.assertQueryLimit(0, '', root2, callable=root.get_path)
+ self.assertQueryLimit(1, 'root/second/third', callable=third.get_path)
+ self.assertQueryLimit(1, 'second/third', root, callable=third.get_path)
+ self.assertQueryLimit(1, e, third, callable=second2.get_path)
- self.assertQueryLimit(1, '? - ?', root, ' - ', 'title', callable=third.get_path)
++ self.assertQueryLimit(1, '? - ?', root, ' - ', 'title', callable=third.get_path)