PageRenderTime 31ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

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