From 82e020f5a1ca4ec0a07f017098df7a7962335b8f Mon Sep 17 00:00:00 2001 From: Aristotelis Mikropoulos Date: Thu, 15 Oct 2020 22:17:21 +0300 Subject: [PATCH] Test PrimaryKeyRelatedField bool lookup rejection --- tests/test_relations.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_relations.py b/tests/test_relations.py index 92aeecf6c..92fa4ce6d 100644 --- a/tests/test_relations.py +++ b/tests/test_relations.py @@ -107,6 +107,12 @@ class TestPrimaryKeyRelatedField(APISimpleTestCase): msg = excinfo.value.detail[0] assert msg == 'Incorrect type. Expected pk value, received BadType.' + def test_pk_related_lookup_bool(self): + with pytest.raises(serializers.ValidationError) as excinfo: + self.field.to_internal_value(True) + msg = excinfo.value.detail[0] + assert msg == 'Incorrect type. Expected pk value, received bool.' + def test_pk_representation(self): representation = self.field.to_representation(self.instance) assert representation == self.instance.pk