PageRenderTime 253ms CodeModel.GetById 171ms app.highlight 5ms RepoModel.GetById 75ms app.codeStats 1ms

/tests/regressiontests/null_fk_ordering/tests.py

https://code.google.com/p/mango-py/
Python | 39 lines | 24 code | 5 blank | 10 comment | 0 complexity | 18a456d3bc630aa66c9b318edc861b9f MD5 | raw file
 1from django.test import TestCase
 2
 3from regressiontests.null_fk_ordering.models import *
 4
 5class NullFkOrderingTests(TestCase):
 6
 7    def test_ordering_across_null_fk(self):
 8        """
 9        Regression test for #7512
10
11        ordering across nullable Foreign Keys shouldn't exclude results
12        """
13        author_1 = Author.objects.create(name='Tom Jones')
14        author_2 = Author.objects.create(name='Bob Smith')
15        article_1 = Article.objects.create(title='No author on this article')
16        article_2 = Article.objects.create(author=author_1, title='This article written by Tom Jones')
17        article_3 = Article.objects.create(author=author_2, title='This article written by Bob Smith')
18
19        # We can't compare results directly (since different databases sort NULLs to
20        # different ends of the ordering), but we can check that all results are
21        # returned.
22        self.assertTrue(len(list(Article.objects.all())) == 3)
23
24        s = SystemInfo.objects.create(system_name='System Info')
25        f = Forum.objects.create(system_info=s, forum_name='First forum')
26        p = Post.objects.create(forum=f, title='First Post')
27        c1 = Comment.objects.create(post=p, comment_text='My first comment')
28        c2 = Comment.objects.create(comment_text='My second comment')
29        s2 = SystemInfo.objects.create(system_name='More System Info')
30        f2 = Forum.objects.create(system_info=s2, forum_name='Second forum')
31        p2 = Post.objects.create(forum=f2, title='Second Post')
32        c3 = Comment.objects.create(comment_text='Another first comment')
33        c4 = Comment.objects.create(post=p2, comment_text='Another second comment')
34
35        # We have to test this carefully. Some databases sort NULL values before
36        # everything else, some sort them afterwards. So we extract the ordered list
37        # and check the length. Before the fix, this list was too short (some values
38        # were omitted).
39        self.assertTrue(len(list(Comment.objects.all())) == 4)