Ticket #1946: test-patch

File test-patch, 2.2 KB (added by hanne.moa@…, 7 years ago)

Tests for patch (or a good start anyway)

Line 
1diff -rduP -x .svn -x '*.pyc' django-trunk/tests/modeltests/custom_sequence/models.py django-new/tests/modeltests/custom_sequence/models.py
2--- django-trunk/tests/modeltests/custom_sequence/models.py     1970-01-01 01:00:00.000000000 +0100
3+++ django-new/tests/modeltests/custom_sequence/models.py       2008-02-26 15:01:12.000000000 +0100
4@@ -0,0 +1,82 @@
5+# -*- coding: utf-8 -*-
6+"""
7+XX. Using a custom incrementor sequence for an AutoField
8+
9+By default, Django generates the name of the incrementor sequence
10+automatically. But you can override this behavior by explicitly adding
11+``sec_name`` to the AutoField.
12+"""
13+
14+from django.db import models
15+
16+class Human(models.Model):
17+    id = models.AutoField(seq_name='global_id_seq')
18+    name = models.CharField(max_length=64)
19+
20+    def __unicode__(self):
21+        return self.name
22+
23+class Animal(models.Model):
24+    id = models.AutoField(seq_name='global_id_seq')
25+    name = models.CharField(max_length=64)
26+
27+    def __unicode__(self):
28+        return self.name
29+
30+class Voter(Human):
31+    name = models.CharField(max_length=64)
32+
33+    def __unicode__(self):
34+        return self.name
35+
36+__test__ = {'API_TESTS':"""
37+>>> jane = Human(name="Jane Doe")
38+>>> jane.save()
39+>>> Human.objects.all()
40+[<Human: Jane Doe>]
41+
42+>>> jane.id
43+1
44+
45+>>> bowser = Animal(name="Ridgemont von Fjausterhofen III aka. Bowser")
46+>>> bowser.save()
47+>>> Animal.objects.all()
48+[<Animal: Ridgemont von Fjausterhofen III aka. Bowser>]
49+
50+>>> bowser.id
51+2
52+
53+>>> mary = Voter(name="Mary Sue Heinlein")
54+>>> mary.save()
55+>>> Voter.objects.all()
56+[<Voter: Mary Sue Heinlein>]
57+
58+>>> mary.id
59+3
60+
61+# This belongs in an inheritance test
62+#>>> Human.objects.all()
63+#[<Human: Jane Doe>, <Voter: Mary Sue Heinlein>]
64+
65+>>> Human.objects.get(pk=1)
66+<Human: Jane Doe>
67+>>> Human.objects.get(pk=2)
68+Traceback (most recent call last):
69+    ...
70+DoesNotExist: Human matching query does not exist.
71+
72+# Jane Doe was identified and got a real name
73+>>> ana = Human.objects.get(pk=1)
74+>>> ana.name = 'Anastasia Romanova'
75+>>> ana.save()
76+>>> ana.id
77+1
78+
79+# Mary got a friend
80+>>> kim = Voter(name="Kim Possible")
81+>>> kim.save()
82+>>> Voter.objects.all()
83+[<Voter: Mary Sue Heinlein>, <Voter: Kim Possible>]
84+>>> kim.id
85+4
86+"""}
Back to Top