Ticket #14460: managers_regress_test_conversion.diff

File managers_regress_test_conversion.diff, 4.8 KB (added by Gabriel Hurley, 14 years ago)
  • tests/regressiontests/managers_regress/models.py

     
    9898# Will not inherit default manager from parent.
    9999class Child7(Parent):
    100100    pass
    101 
    102 __test__ = {"API_TESTS": """
    103 >>> a1 = Child1.objects.create(name='fred', data='a1')
    104 >>> a2 = Child1.objects.create(name='barney', data='a2')
    105 >>> b1 = Child2.objects.create(name='fred', data='b1', value=1)
    106 >>> b2 = Child2.objects.create(name='barney', data='b2', value=42)
    107 >>> c1 = Child3.objects.create(name='fred', data='c1', comment='yes')
    108 >>> c2 = Child3.objects.create(name='barney', data='c2', comment='no')
    109 >>> d1 = Child4.objects.create(name='fred', data='d1')
    110 >>> d2 = Child4.objects.create(name='barney', data='d2')
    111 >>> e1 = Child5.objects.create(name='fred', comment='yes')
    112 >>> e2 = Child5.objects.create(name='barney', comment='no')
    113 >>> f1 = Child6.objects.create(name='fred', data='f1', value=42)
    114 >>> f2 = Child6.objects.create(name='barney', data='f2', value=42)
    115 >>> g1 = Child7.objects.create(name='fred')
    116 >>> g2 = Child7.objects.create(name='barney')
    117 
    118 >>> Child1.manager1.all()
    119 [<Child1: a1>]
    120 >>> Child1.manager2.all()
    121 [<Child1: a2>]
    122 >>> Child1._default_manager.all()
    123 [<Child1: a1>]
    124 
    125 >>> Child2._default_manager.all()
    126 [<Child2: b1>]
    127 >>> Child2.restricted.all()
    128 [<Child2: b2>]
    129 
    130 >>> Child3._default_manager.all()
    131 [<Child3: c1>]
    132 >>> Child3.manager1.all()
    133 [<Child3: c1>]
    134 >>> Child3.manager2.all()
    135 [<Child3: c2>]
    136 
    137 # Since Child6 inherits from Child4, the corresponding rows from f1 and f2 also
    138 # appear here. This is the expected result.
    139 >>> Child4._default_manager.order_by('data')
    140 [<Child4: d1>, <Child4: d2>, <Child4: f1>, <Child4: f2>]
    141 >>> Child4.manager1.all()
    142 [<Child4: d1>, <Child4: f1>]
    143 
    144 >>> Child5._default_manager.all()
    145 [<Child5: fred>]
    146 
    147 >>> Child6._default_manager.all()
    148 [<Child6: f1>]
    149 
    150 >>> Child7._default_manager.order_by('name')
    151 [<Child7: barney>, <Child7: fred>]
    152 
    153 """}
  • tests/regressiontests/managers_regress/tests.py

     
     1from django.test import TestCase
     2
     3from models import *
     4
     5class ManagersRegressionTests(TestCase):
     6    def test_managers(self):
     7        a1 = Child1.objects.create(name='fred', data='a1')
     8        a2 = Child1.objects.create(name='barney', data='a2')
     9        b1 = Child2.objects.create(name='fred', data='b1', value=1)
     10        b2 = Child2.objects.create(name='barney', data='b2', value=42)
     11        c1 = Child3.objects.create(name='fred', data='c1', comment='yes')
     12        c2 = Child3.objects.create(name='barney', data='c2', comment='no')
     13        d1 = Child4.objects.create(name='fred', data='d1')
     14        d2 = Child4.objects.create(name='barney', data='d2')
     15        e1 = Child5.objects.create(name='fred', comment='yes')
     16        e2 = Child5.objects.create(name='barney', comment='no')
     17        f1 = Child6.objects.create(name='fred', data='f1', value=42)
     18        f2 = Child6.objects.create(name='barney', data='f2', value=42)
     19        g1 = Child7.objects.create(name='fred')
     20        g2 = Child7.objects.create(name='barney')
     21       
     22        self.assertQuerysetEqual(Child1.manager1.all(), ["<Child1: a1>"])
     23        self.assertQuerysetEqual(Child1.manager2.all(), ["<Child1: a2>"])
     24        self.assertQuerysetEqual(Child1._default_manager.all(), ["<Child1: a1>"])
     25       
     26        self.assertQuerysetEqual(Child2._default_manager.all(), ["<Child2: b1>"])
     27        self.assertQuerysetEqual(Child2.restricted.all(), ["<Child2: b2>"])
     28       
     29        self.assertQuerysetEqual(Child3._default_manager.all(), ["<Child3: c1>"])
     30        self.assertQuerysetEqual(Child3.manager1.all(), ["<Child3: c1>"])
     31        self.assertQuerysetEqual(Child3.manager2.all(), ["<Child3: c2>"])
     32       
     33        # Since Child6 inherits from Child4, the corresponding rows from f1 and f2 also
     34        # appear here. This is the expected result.
     35        self.assertQuerysetEqual(Child4._default_manager.order_by('data'), [
     36                "<Child4: d1>",
     37                "<Child4: d2>",
     38                "<Child4: f1>",
     39                "<Child4: f2>"
     40            ]
     41        )
     42        self.assertQuerysetEqual(Child4.manager1.all(), [
     43                "<Child4: d1>",
     44                "<Child4: f1>"
     45            ]
     46        )
     47        self.assertQuerysetEqual(Child5._default_manager.all(), ["<Child5: fred>"])
     48        self.assertQuerysetEqual(Child6._default_manager.all(), ["<Child6: f1>"])
     49        self.assertQuerysetEqual(Child7._default_manager.order_by('name'), [
     50                "<Child7: barney>",
     51                "<Child7: fred>"
     52            ]
     53        )
Back to Top