summaryrefslogtreecommitdiff
path: root/tests/foreign_object/test_empty_join.py
diff options
context:
space:
mode:
authorAlex Hill <alex@hill.net.au>2015-07-10 15:52:22 +0800
committerTim Graham <timograham@gmail.com>2015-08-15 07:26:44 -0400
commit98bcdfa8bd902addd4b8cf37d039b3597d58a45c (patch)
tree602c6833ece8dba33e62444ef76161d573d21430 /tests/foreign_object/test_empty_join.py
parentf9636fdf922fe49ff82d02b17d6b34469fcf1fda (diff)
Fixed #25064 -- Allowed empty join columns.
Diffstat (limited to 'tests/foreign_object/test_empty_join.py')
-rw-r--r--tests/foreign_object/test_empty_join.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/foreign_object/test_empty_join.py b/tests/foreign_object/test_empty_join.py
new file mode 100644
index 0000000000..a043595ce2
--- /dev/null
+++ b/tests/foreign_object/test_empty_join.py
@@ -0,0 +1,47 @@
+from django.test import TestCase
+
+from .models import SlugPage
+
+
+class RestrictedConditionsTests(TestCase):
+ def setUp(self):
+ slugs = [
+ 'a',
+ 'a/a',
+ 'a/b',
+ 'a/b/a',
+ 'x',
+ 'x/y/z',
+ ]
+ SlugPage.objects.bulk_create([SlugPage(slug=slug) for slug in slugs])
+
+ def test_restrictions_with_no_joining_columns(self):
+ """
+ Test that it's possible to create a working related field that doesn't
+ use any joining columns, as long as an extra restriction is supplied.
+ """
+ a = SlugPage.objects.get(slug='a')
+ self.assertListEqual(
+ [p.slug for p in SlugPage.objects.filter(ascendants=a)],
+ ['a', 'a/a', 'a/b', 'a/b/a'],
+ )
+ self.assertEqual(
+ [p.slug for p in a.descendants.all()],
+ ['a', 'a/a', 'a/b', 'a/b/a'],
+ )
+
+ aba = SlugPage.objects.get(slug='a/b/a')
+ self.assertListEqual(
+ [p.slug for p in SlugPage.objects.filter(descendants__in=[aba])],
+ ['a', 'a/b', 'a/b/a'],
+ )
+ self.assertListEqual(
+ [p.slug for p in aba.ascendants.all()],
+ ['a', 'a/b', 'a/b/a'],
+ )
+
+ def test_empty_join_conditions(self):
+ x = SlugPage.objects.get(slug='x')
+ message = "Join generated an empty ON clause."
+ with self.assertRaisesMessage(ValueError, message):
+ list(SlugPage.objects.filter(containers=x))