@@ -19,65 +19,3 @@ def __unicode__(self):
19
19
class ManualPrimaryKeyTest (models .Model ):
20
20
id = models .IntegerField (primary_key = True )
21
21
data = models .CharField (max_length = 100 )
22
-
23
- __test__ = {'API_TESTS' :"""
24
- # Acting as a divine being, create an Person.
25
- >>> from datetime import date
26
- >>> p = Person(first_name='John', last_name='Lennon', birthday=date(1940, 10, 9))
27
- >>> p.save()
28
-
29
- # Only one Person is in the database at this point.
30
- >>> Person.objects.count()
31
- 1
32
-
33
- # get_or_create() a person with similar first names.
34
- >>> p, created = Person.objects.get_or_create(first_name='John', last_name='Lennon', defaults={'birthday': date(1940, 10, 9)})
35
-
36
- # get_or_create() didn't have to create an object.
37
- >>> created
38
- False
39
-
40
- # There's still only one Person in the database.
41
- >>> Person.objects.count()
42
- 1
43
-
44
- # get_or_create() a Person with a different name.
45
- >>> p, created = Person.objects.get_or_create(first_name='George', last_name='Harrison', defaults={'birthday': date(1943, 2, 25)})
46
- >>> created
47
- True
48
- >>> Person.objects.count()
49
- 2
50
-
51
- # If we execute the exact same statement, it won't create a Person.
52
- >>> p, created = Person.objects.get_or_create(first_name='George', last_name='Harrison', defaults={'birthday': date(1943, 2, 25)})
53
- >>> created
54
- False
55
- >>> Person.objects.count()
56
- 2
57
-
58
- # If you don't specify a value or default value for all required fields, you
59
- # will get an error.
60
- >>> try:
61
- ... p, created = Person.objects.get_or_create(first_name='Tom', last_name='Smith')
62
- ... except Exception, e:
63
- ... if isinstance(e, IntegrityError):
64
- ... print "Pass"
65
- ... else:
66
- ... print "Fail with %s" % type(e)
67
- Pass
68
-
69
- # If you specify an existing primary key, but different other fields, then you
70
- # will get an error and data will not be updated.
71
- >>> m = ManualPrimaryKeyTest(id=1, data='Original')
72
- >>> m.save()
73
- >>> try:
74
- ... m, created = ManualPrimaryKeyTest.objects.get_or_create(id=1, data='Different')
75
- ... except Exception, e:
76
- ... if isinstance(e, IntegrityError):
77
- ... print "Pass"
78
- ... else:
79
- ... print "Fail with %s" % type(e)
80
- Pass
81
- >>> ManualPrimaryKeyTest.objects.get(id=1).data == 'Original'
82
- True
83
- """ }
0 commit comments