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/contenttypes_tests | |
| parent | aa14528910df0d35ad43a6f8191e3bd2d0f1746e (diff) | |
Refs #27745 -- Improved test coverage of contrib.contenttypes.
Diffstat (limited to 'tests/contenttypes_tests')
| -rw-r--r-- | tests/contenttypes_tests/test_fields.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/contenttypes_tests/test_fields.py b/tests/contenttypes_tests/test_fields.py index 88de0ec7f2..ce5e244df5 100644 --- a/tests/contenttypes_tests/test_fields.py +++ b/tests/contenttypes_tests/test_fields.py @@ -1,8 +1,12 @@ +import json + from django.contrib.contenttypes.fields import GenericForeignKey from django.db import models -from django.test import SimpleTestCase +from django.test import SimpleTestCase, TestCase from django.test.utils import isolate_apps +from .models import Answer, Question + @isolate_apps('contenttypes_tests') class GenericForeignKeyTests(SimpleTestCase): @@ -11,3 +15,21 @@ class GenericForeignKeyTests(SimpleTestCase): class Model(models.Model): field = GenericForeignKey() self.assertEqual(str(Model.field), 'contenttypes_tests.Model.field') + + def test_get_content_type_no_arguments(self): + with self.assertRaisesMessage(Exception, 'Impossible arguments to GFK.get_content_type!'): + Answer.question.get_content_type() + + def test_incorrect_get_prefetch_queryset_arguments(self): + with self.assertRaisesMessage(ValueError, "Custom queryset can't be used for this lookup."): + Answer.question.get_prefetch_queryset(Answer.objects.all(), Answer.objects.all()) + + +class GenericRelationTests(TestCase): + + def test_value_to_string(self): + question = Question.objects.create(text='test') + answer1 = Answer.objects.create(question=question) + answer2 = Answer.objects.create(question=question) + result = json.loads(Question.answer_set.field.value_to_string(question)) + self.assertCountEqual(result, [answer1.pk, answer2.pk]) |
