| 1 | from django.db import models, IntegrityError |
| 2 | |
| 3 | class ManualPrimaryKeyTest(models.Model): |
| 4 | id = models.IntegerField(primary_key=True) |
| 5 | data = models.CharField(max_length=100) |
| 6 | |
| 7 | __test__ = {'API_TESTS':""" |
| 8 | # If you force_update specifying a non-existent object, then you will get an |
| 9 | # error. |
| 10 | >>> m = ManualPrimaryKeyTest(id=1, data='Original') |
| 11 | >>> m.save(force_insert=True) |
| 12 | >>> try: |
| 13 | ... m = ManualPrimaryKeyTest(id=2, data='Different') |
| 14 | ... m.save(force_update=True) |
| 15 | ... except Exception, e: |
| 16 | ... if isinstance(e, IntegrityError): |
| 17 | ... print "Pass" |
| 18 | ... else: |
| 19 | ... print "Fail with %s" % type(e) |
| 20 | Pass |
| 21 | >>> len(ManualPrimaryKeyTest.objects.filter(id=2)) == 0 |
| 22 | True |
| 23 | """} |