Added test to show potential issue with UniqueValidator being added to the underlying Django model.

This commit is contained in:
Mark Hughes 2014-12-03 12:30:15 +00:00
parent c5a2d501e5
commit 55528addf9

View File

@ -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`
# -----------------------------------