@@ -11,54 +11,3 @@ class Counter(models.Model):
11
11
class WithCustomPK (models .Model ):
12
12
name = models .IntegerField (primary_key = True )
13
13
value = models .IntegerField ()
14
-
15
- __test__ = {"API_TESTS" : """
16
- >>> c = Counter.objects.create(name="one", value=1)
17
-
18
- # The normal case
19
- >>> c.value = 2
20
- >>> c.save()
21
-
22
- # Same thing, via an update
23
- >>> c.value = 3
24
- >>> c.save(force_update=True)
25
-
26
- # Won't work because force_update and force_insert are mutually exclusive
27
- >>> c.value = 4
28
- >>> c.save(force_insert=True, force_update=True)
29
- Traceback (most recent call last):
30
- ...
31
- ValueError: Cannot force both insert and updating in model saving.
32
-
33
- # Try to update something that doesn't have a primary key in the first place.
34
- >>> c1 = Counter(name="two", value=2)
35
- >>> c1.save(force_update=True)
36
- Traceback (most recent call last):
37
- ...
38
- ValueError: Cannot force an update in save() with no primary key.
39
-
40
- >>> c1.save(force_insert=True)
41
-
42
- # Won't work because we can't insert a pk of the same value.
43
- >>> sid = transaction.savepoint()
44
- >>> c.value = 5
45
- >>> try:
46
- ... c.save(force_insert=True)
47
- ... except Exception, e:
48
- ... if isinstance(e, IntegrityError):
49
- ... print "Pass"
50
- ... else:
51
- ... print "Fail with %s" % type(e)
52
- Pass
53
- >>> transaction.savepoint_rollback(sid)
54
-
55
- # Trying to update should still fail, even with manual primary keys, if the
56
- # data isn't in the database already.
57
- >>> obj = WithCustomPK(name=1, value=1)
58
- >>> obj.save(force_update=True)
59
- Traceback (most recent call last):
60
- ...
61
- DatabaseError: ...
62
-
63
- """
64
- }
0 commit comments