From 55528addf97c1d3ee24bb3332fb6dcb5496de158 Mon Sep 17 00:00:00 2001 From: Mark Hughes Date: Wed, 3 Dec 2014 12:30:15 +0000 Subject: [PATCH] Added test to show potential issue with UniqueValidator being added to the underlying Django model. --- tests/test_validators.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_validators.py b/tests/test_validators.py index 1df0641c5..9226cc7a5 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -20,6 +20,15 @@ class UniquenessSerializer(serializers.ModelSerializer): model = UniquenessModel +class AnotherUniquenessModel(models.Model): + code = models.IntegerField(unique=True) + + +class AnotherUniquenessSerializer(serializers.ModelSerializer): + class Meta: + model = AnotherUniquenessModel + + class TestUniquenessValidation(TestCase): def setUp(self): self.instance = UniquenessModel.objects.create(username='existing') @@ -51,6 +60,17 @@ class TestUniquenessValidation(TestCase): assert serializer.is_valid() assert serializer.validated_data == {'username': 'existing'} + def test_doesnt_pollute_model(self): + instance = AnotherUniquenessModel.objects.create(code='100') + serializer = AnotherUniquenessSerializer(instance) + self.assertEqual( + AnotherUniquenessModel._meta.get_field('code').validators, []) + + # Accessing data shouldn't effect validators on the model + serializer.data + self.assertEqual( + AnotherUniquenessModel._meta.get_field('code').validators, []) + # Tests for `UniqueTogetherValidator` # -----------------------------------