mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
6b4f018b2b
Python docs say, "it's usually not necessary to invoke these methods directly."
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
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):
|
|
"""
|
|
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.assertEqual(
|
|
[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.assertEqual(
|
|
[p.slug for p in SlugPage.objects.filter(descendants__in=[aba])],
|
|
['a', 'a/b', 'a/b/a'],
|
|
)
|
|
self.assertEqual(
|
|
[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))
|