Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Migrated null_fk_ordering doctests. Thanks to Stephan Jaekel.

Backport of r13933 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13941 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ccd6a6783baef1980cbe2f04a038eaecf23742ef 1 parent a9e0305
Russell Keith-Magee authored September 28, 2010
37  tests/regressiontests/null_fk_ordering/models.py
@@ -47,40 +47,3 @@ class Meta:
47 47
 
48 48
     def __unicode__(self):
49 49
         return self.comment_text
50  
-
51  
-
52  
-__test__ = {'API_TESTS': """
53  
-# Regression test for #7512 -- ordering across nullable Foreign Keys shouldn't
54  
-# exclude results
55  
->>> author_1 = Author.objects.create(name='Tom Jones')
56  
->>> author_2 = Author.objects.create(name='Bob Smith')
57  
->>> article_1 = Article.objects.create(title='No author on this article')
58  
->>> article_2 = Article.objects.create(author=author_1, title='This article written by Tom Jones')
59  
->>> article_3 = Article.objects.create(author=author_2, title='This article written by Bob Smith')
60  
-
61  
-# We can't compare results directly (since different databases sort NULLs to
62  
-# different ends of the ordering), but we can check that all results are
63  
-# returned.
64  
->>> len(list(Article.objects.all())) == 3
65  
-True
66  
-
67  
->>> s = SystemInfo.objects.create(system_name='System Info')
68  
->>> f = Forum.objects.create(system_info=s, forum_name='First forum')
69  
->>> p = Post.objects.create(forum=f, title='First Post')
70  
->>> c1 = Comment.objects.create(post=p, comment_text='My first comment')
71  
->>> c2 = Comment.objects.create(comment_text='My second comment')
72  
->>> s2 = SystemInfo.objects.create(system_name='More System Info')
73  
->>> f2 = Forum.objects.create(system_info=s2, forum_name='Second forum')
74  
->>> p2 = Post.objects.create(forum=f2, title='Second Post')
75  
->>> c3 = Comment.objects.create(comment_text='Another first comment')
76  
->>> c4 = Comment.objects.create(post=p2, comment_text='Another second comment')
77  
-
78  
-# We have to test this carefully. Some databases sort NULL values before
79  
-# everything else, some sort them afterwards. So we extract the ordered list
80  
-# and check the length. Before the fix, this list was too short (some values
81  
-# were omitted).
82  
->>> len(list(Comment.objects.all())) == 4
83  
-True
84  
-
85  
-"""
86  
-}
39  tests/regressiontests/null_fk_ordering/tests.py
... ...
@@ -0,0 +1,39 @@
  1
+from django.test import TestCase
  2
+
  3
+from regressiontests.null_fk_ordering.models import *
  4
+
  5
+class 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)

0 notes on commit ccd6a67

Please sign in to comment.
Something went wrong with that request. Please try again.