diff options
| author | Anton Samarchyan <anton.samarchyan@savoirfairelinux.com> | 2017-01-27 13:29:56 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-02-03 14:17:00 -0500 |
| commit | 4d6584000a85bd76e0716e2f184335698e9cf686 (patch) | |
| tree | db3d1532fd585bf09c8ce9ff13fbdac0c9ef75be /tests/generic_relations | |
| parent | aa14528910df0d35ad43a6f8191e3bd2d0f1746e (diff) | |
Refs #27745 -- Improved test coverage of contrib.contenttypes.
Diffstat (limited to 'tests/generic_relations')
| -rw-r--r-- | tests/generic_relations/tests.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py index 08651adb0e..91bb616420 100644 --- a/tests/generic_relations/tests.py +++ b/tests/generic_relations/tests.py @@ -2,9 +2,10 @@ from django import forms from django.contrib.contenttypes.forms import generic_inlineformset_factory from django.contrib.contenttypes.models import ContentType from django.core.exceptions import FieldError -from django.db import IntegrityError +from django.db import IntegrityError, models from django.db.models import Q from django.test import SimpleTestCase, TestCase +from django.test.utils import isolate_apps from .models import ( AllowsNullGFK, Animal, Carrot, Comparison, ConcreteRelatedModel, @@ -272,6 +273,11 @@ class GenericRelationsTests(TestCase): with self.assertRaisesMessage(ValueError, msg): self.bacon.tags.add(t1) + def test_add_rejects_wrong_instances(self): + msg = "'TaggedItem' instance expected, got <Animal: Lion>" + with self.assertRaisesMessage(TypeError, msg): + self.bacon.tags.add(self.lion) + def test_set(self): bacon = Vegetable.objects.create(name="Bacon", is_yucky=False) fatty = bacon.tags.create(tag="fatty") @@ -596,6 +602,15 @@ class GenericInlineFormsetTest(TestCase): form = Formset().forms[0] self.assertIsInstance(form['tag'].field.widget, CustomWidget) + @isolate_apps('generic_relations') + def test_incorrect_content_type(self): + class BadModel(models.Model): + content_type = models.PositiveIntegerField() + + msg = "fk_name 'generic_relations.BadModel.content_type' is not a ForeignKey to ContentType" + with self.assertRaisesMessage(Exception, msg): + generic_inlineformset_factory(BadModel, TaggedItemForm) + def test_save_new_uses_form_save(self): """ Regression for #16260: save_new should call form.save() |
