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 admin_ordering doctests. Thanks to Sebastian Hillig.

Backport of r13881 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13901 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3a66f15a68c589de07251f3de6e155ddf0422af2 1 parent 3640abd
Russell Keith-Magee authored
36  tests/regressiontests/admin_ordering/models.py
@@ -8,39 +8,3 @@ class Band(models.Model):
8 8
 
9 9
     class Meta:
10 10
         ordering = ('name',)
11  
-
12  
-__test__ = {'API_TESTS': """
13  
-
14  
-Let's make sure that ModelAdmin.queryset uses the ordering we define in
15  
-ModelAdmin rather that ordering defined in the model's inner Meta
16  
-class.
17  
-
18  
->>> from django.contrib.admin.options import ModelAdmin
19  
-
20  
->>> b1 = Band(name='Aerosmith', bio='', rank=3)
21  
->>> b1.save()
22  
->>> b2 = Band(name='Radiohead', bio='', rank=1)
23  
->>> b2.save()
24  
->>> b3 = Band(name='Van Halen', bio='', rank=2)
25  
->>> b3.save()
26  
-
27  
-The default ordering should be by name, as specified in the inner Meta class.
28  
-
29  
->>> ma = ModelAdmin(Band, None)
30  
->>> [b.name for b in ma.queryset(None)]
31  
-[u'Aerosmith', u'Radiohead', u'Van Halen']
32  
-
33  
-
34  
-Let's use a custom ModelAdmin that changes the ordering, and make sure it
35  
-actually changes.
36  
-
37  
->>> class BandAdmin(ModelAdmin):
38  
-...     ordering = ('rank',) # default ordering is ('name',)
39  
-...
40  
-
41  
->>> ma = BandAdmin(Band, None)
42  
->>> [b.name for b in ma.queryset(None)]
43  
-[u'Radiohead', u'Van Halen', u'Aerosmith']
44  
-
45  
-"""
46  
-}
39  tests/regressiontests/admin_ordering/tests.py
... ...
@@ -0,0 +1,39 @@
  1
+from django.test import TestCase
  2
+from django.contrib.admin.options import ModelAdmin
  3
+
  4
+from models import Band
  5
+
  6
+class TestAdminOrdering(TestCase):
  7
+    """
  8
+    Let's make sure that ModelAdmin.queryset uses the ordering we define in
  9
+    ModelAdmin rather that ordering defined in the model's inner Meta
  10
+    class.
  11
+    """
  12
+
  13
+    def setUp(self):
  14
+        b1 = Band(name='Aerosmith', bio='', rank=3)
  15
+        b1.save()
  16
+        b2 = Band(name='Radiohead', bio='', rank=1)
  17
+        b2.save()
  18
+        b3 = Band(name='Van Halen', bio='', rank=2)
  19
+        b3.save()
  20
+
  21
+    def test_default_ordering(self):
  22
+        """
  23
+        The default ordering should be by name, as specified in the inner Meta
  24
+        class.
  25
+        """
  26
+        ma = ModelAdmin(Band, None)
  27
+        names = [b.name for b in ma.queryset(None)]
  28
+        self.assertEqual([u'Aerosmith', u'Radiohead', u'Van Halen'], names)
  29
+
  30
+    def test_specified_ordering(self):
  31
+        """
  32
+        Let's use a custom ModelAdmin that changes the ordering, and make sure
  33
+        it actually changes.
  34
+        """
  35
+        class BandAdmin(ModelAdmin):
  36
+            ordering = ('rank',) # default ordering is ('name',)
  37
+        ma = BandAdmin(Band, None)
  38
+        names = [b.name for b in ma.queryset(None)]
  39
+        self.assertEqual([u'Radiohead', u'Van Halen', u'Aerosmith'], names)

0 notes on commit 3a66f15

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