diff --git a/tests/modeltests/get_or_create/models.py b/tests/modeltests/get_or_create/models.py
index db5719b..efc50f9 100644
a
|
b
|
given parameters. If an object isn't found, it creates one with the given
|
6 | 6 | parameters. |
7 | 7 | """ |
8 | 8 | |
9 | | from django.db import models, IntegrityError |
| 9 | from django.db import models |
10 | 10 | |
11 | 11 | class Person(models.Model): |
12 | 12 | first_name = models.CharField(max_length=100) |
… |
… |
class Person(models.Model):
|
19 | 19 | class ManualPrimaryKeyTest(models.Model): |
20 | 20 | id = models.IntegerField(primary_key=True) |
21 | 21 | data = models.CharField(max_length=100) |
| 22 | |
| 23 | |
| 24 | class IntegrityErrorTest(models.Model): |
| 25 | country = models.ForeignKey(Person, primary_key=True) |
| 26 | info = models.TextField(blank=True, default='') |
| 27 | |
diff --git a/tests/modeltests/get_or_create/tests.py b/tests/modeltests/get_or_create/tests.py
index 3323c88..5b65537 100644
a
|
b
|
from datetime import date
|
3 | 3 | from django.db import IntegrityError |
4 | 4 | from django.test import TestCase |
5 | 5 | |
6 | | from models import Person, ManualPrimaryKeyTest |
| 6 | from models import Person, ManualPrimaryKeyTest, IntegrityErrorTest |
7 | 7 | |
8 | 8 | |
9 | 9 | class GetOrCreateTests(TestCase): |
… |
… |
class GetOrCreateTests(TestCase):
|
50 | 50 | ManualPrimaryKeyTest.objects.get_or_create, id=1, data="Different" |
51 | 51 | ) |
52 | 52 | self.assertEqual(ManualPrimaryKeyTest.objects.get(id=1).data, "Original") |
| 53 | |
| 54 | |
| 55 | def test_get_or_create_integrityerror(self): |
| 56 | |
| 57 | self.assertRaises(IntegrityError, |
| 58 | IntegrityErrorTest.objects.get_or_create, pk=1) |
| 59 | |
| 60 | p = Person() |
| 61 | p.id = 1 |
| 62 | |
| 63 | self.assertRaises(IntegrityError, |
| 64 | IntegrityErrorTest.objects.get_or_create, p=p) |
| 65 | |