Code

Ticket #7136: shell_results_rev7513.py

File shell_results_rev7513.py, 5.4 KB (added by socrates, 6 years ago)

This file is to easily reproduce the shell results and see the situation before and after the patch (this version includes the models)

Line 
1#
2# models.py
3#
4
5from django.db import models
6
7class Vehicle(models.Model):
8        name = models.TextField()
9       
10        def __unicode__(self):
11                return u"A vehicle called %s" % self.name
12
13class Car(Vehicle):
14        wheels = models.PositiveIntegerField(default=4)
15
16        def __unicode__(self):
17                return u"A car called %(name)s with %(wheels)s wheels" % \
18                        {'name': self.name, 'wheels': self.wheels}
19       
20class Boat(Vehicle):
21        has_sail = models.BooleanField(default=True)
22
23        def __unicode__(self):
24                with_or_without = self.has_sail and "with" or "without"
25                return u"A boat called %(name)s %(with_or_without)s a sail" % \
26                        {'name': self.name, 'with_or_without': with_or_without }
27       
28class Amphibian(Car, Boat):
29        is_a_robot_in_disguise = models.BooleanField(default=False)
30       
31        def __unicode__(self):
32                return u"An ampibian which is 1) %(car)s and 2) %(boat)s" % \
33                        {'car': Car.__unicode__(self), 
34                        'boat': Boat.__unicode__(self)}
35
36
37#
38# The code to generate the shell results.
39#
40
41from your.path.to.models import *
42
43Vehicle.objects.all().delete()
44Boat(name="dingy", has_sail=False).save()
45dingy_vehicle = Vehicle.objects.get(name="dingy")
46dingy_vehicle.car
47dingy_vehicle.boat
48dingy_vehicle.car
49dingy_vehicle.boat
50Car(name="my rolls", wheels=4).save()
51rolls_vehicle = Vehicle.objects.get(name="my rolls")
52rolls_vehicle.car
53rolls_vehicle.boat
54rolls_vehicle.car
55rolls_vehicle.boat
56amphibian = Amphibian()
57amphibian.name = "optimus prime"
58amphibian.has_sail = True
59amphibian.wheels = 23
60amphibian.is_a_robot_in_disguise = True
61amphibian.save()
62robot_vehicle = Vehicle.objects.get(name="optimus prime")
63robot_vehicle.car
64robot_vehicle.boat
65robot_vehicle.car
66robot_vehicle.boat
67robot_vehicle.car.amphibian
68robot_vehicle.boat.amphibian
69
70#
71# Shell results before the code was changed
72#
73
74>>> Vehicle.objects.all().delete()
75>>> Boat(name="dingy", has_sail=False).save()
76>>> dingy_vehicle = Vehicle.objects.get(name="dingy")
77>>> dingy_vehicle.car
78Traceback (most recent call last):
79    ...
80DoesNotExist: Car matching query does not exist.
81>>> dingy_vehicle.boat
82<Boat: A boat called dingy without a sail>
83>>> dingy_vehicle.car # should get error
84<Boat: A boat called dingy without a sail>
85>>> dingy_vehicle.boat
86<Boat: A boat called dingy without a sail>
87>>> Car(name="my rolls", wheels=4).save()
88>>> rolls_vehicle = Vehicle.objects.get(name="my rolls")
89>>> rolls_vehicle.car
90<Car: A car called my rolls with 4 wheels>
91>>> rolls_vehicle.boat # should get error
92<Car: A car called my rolls with 4 wheels>
93>>> rolls_vehicle.car
94<Car: A car called my rolls with 4 wheels>
95>>> rolls_vehicle.boat # should get error
96<Car: A car called my rolls with 4 wheels>
97>>> amphibian = Amphibian()
98>>> amphibian.name = "optimus prime"
99>>> amphibian.has_sail = True
100>>> amphibian.wheels = 23
101>>> amphibian.is_a_robot_in_disguise = True
102>>> amphibian.save()
103>>> robot_vehicle = Vehicle.objects.get(name="optimus prime")
104>>> robot_vehicle.car
105<Car: A car called optimus prime with 23 wheels>
106>>> robot_vehicle.boat # wrong object we want to see the boat part of optimus prime
107<Car: A car called optimus prime with 23 wheels>
108>>> robot_vehicle.car
109<Car: A car called optimus prime with 23 wheels>
110>>> robot_vehicle.boat # wrong object we want to see the boat part of optimus prime
111<Car: A car called optimus prime with 23 wheels>
112>>> robot_vehicle.car.amphibian
113<Amphibian: An ampibian which is 1) A car called optimus prime with 23 wheels and 2) A boat called optimus prime with a sail>
114>>> robot_vehicle.boat.amphibian
115<Amphibian: An ampibian which is 1) A car called optimus prime with 23 wheels and 2) A boat called optimus prime with a sail>
116
117#
118# Shell results after the code was changed
119#
120
121>>> Vehicle.objects.all().delete()
122>>> Boat(name="dingy", has_sail=False).save()
123>>> dingy_vehicle = Vehicle.objects.get(name="dingy")
124>>> dingy_vehicle.car # the dingy is not a car
125Traceback (most recent call last):
126    ...
127DoesNotExist: Car matching query does not exist.
128>>> dingy_vehicle.boat
129<Boat: A boat called dingy without a sail>
130>>> dingy_vehicle.car # the dingy is still not a car
131Traceback (most recent call last):
132    ...
133DoesNotExist: Car matching query does not exist.
134>>> dingy_vehicle.boat
135<Boat: A boat called dingy without a sail>
136>>> Car(name="my rolls", wheels=4).save()
137>>> rolls_vehicle = Vehicle.objects.get(name="my rolls")
138>>> rolls_vehicle.car
139<Car: A car called my rolls with 4 wheels>
140>>> rolls_vehicle.boat
141Traceback (most recent call last):
142    ...
143DoesNotExist: Boat matching query does not exist.
144>>> rolls_vehicle.car
145<Car: A car called my rolls with 4 wheels>
146>>> rolls_vehicle.boat
147Traceback (most recent call last):
148    ...
149DoesNotExist: Boat matching query does not exist.
150>>> amphibian = Amphibian()
151>>> amphibian.name = "optimus prime"
152>>> amphibian.has_sail = True
153>>> amphibian.wheels = 23
154>>> amphibian.is_a_robot_in_disguise = True
155>>> amphibian.save()
156>>> robot_vehicle = Vehicle.objects.get(name="optimus prime")
157>>> robot_vehicle.car
158<Car: A car called optimus prime with 23 wheels>
159>>> robot_vehicle.boat
160<Boat: A boat called optimus prime with a sail>
161>>> robot_vehicle.car
162<Car: A car called optimus prime with 23 wheels>
163>>> robot_vehicle.boat
164<Boat: A boat called optimus prime with a sail>
165>>> robot_vehicle.car.amphibian
166<Amphibian: An ampibian which is 1) A car called optimus prime with 23 wheels and 2) A boat called optimus prime with a sail>
167>>> robot_vehicle.boat.amphibian
168<Amphibian: An ampibian which is 1) A car called optimus prime with 23 wheels and 2) A boat called optimus prime with a sail>