+ self.assertEqual(Node.objects.get_with_path(*args, **kwargs), expected_result)
+ queries = len(connection.queries) - queries
+ if queries > max:
+ raise AssertionError('"%d" unexpectedly not less than or equal to "%s"' % (queries, max))
+ finally:
+ settings.DEBUG = False
+
+ def test_get_with_path(self):
+ root = Node.objects.get(slug='root')
+ third = Node.objects.get(slug='third')
+ second2 = Node.objects.get(slug='second2')
+ fifth = Node.objects.get(slug='fifth')
+ e = Node.DoesNotExist
+
+ # Empty segments
+ self.assertQueryLimit(0, root, '', root=root)
+ self.assertQueryLimit(0, e, '')
+ self.assertQueryLimit(0, (root, None), '', root=root, absolute_result=False)
+
+ # Absolute result
+ self.assertQueryLimit(1, third, 'root/second/third')
+ self.assertQueryLimit(1, third, 'second/third', root=root)
+ self.assertQueryLimit(1, third, 'root//////second/third///')
+
+ self.assertQueryLimit(1, e, 'root/secont/third')
+ self.assertQueryLimit(1, e, 'second/third')
+
+ # Non-absolute result (binary search)
+ self.assertQueryLimit(2, (second2, 'sub/path/tail'), 'root/second2/sub/path/tail', absolute_result=False)
+ self.assertQueryLimit(3, (second2, 'sub/'), 'root/second2/sub/', absolute_result=False)
+ self.assertQueryLimit(2, e, 'invalid/path/1/2/3/4/5/6/7/8/9/1/2/3/4/5/6/7/8/9/0', absolute_result=False)
+ self.assertQueryLimit(1, (root, None), 'root', absolute_result=False)
+ self.assertQueryLimit(2, (second2, None), 'root/second2', absolute_result=False)
+ self.assertQueryLimit(3, (third, None), 'root/second/third', absolute_result=False)
+
+ # with root != None
+ self.assertQueryLimit(1, (second2, None), 'second2', root=root, absolute_result=False)
+ self.assertQueryLimit(2, (third, None), 'second/third', root=root, absolute_result=False)
+
+ # Preserve trailing slash
+ self.assertQueryLimit(2, (second2, 'sub/path/tail/'), 'root/second2/sub/path/tail/', absolute_result=False)
+
+ # Speed increase for leaf nodes - should this be tested?
+ self.assertQueryLimit(1, (fifth, 'sub/path/tail/len/five'), 'root/second/third/fourth/fifth/sub/path/tail/len/five', absolute_result=False)
\ No newline at end of file