mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
Merge branch 'validator-pollution' of git://github.com/mhsparks/django-rest-framework into mhsparks-validator-pollution
This commit is contained in:
commit
8933bc4b14
|
@ -20,6 +20,15 @@ class UniquenessSerializer(serializers.ModelSerializer):
|
||||||
model = UniquenessModel
|
model = UniquenessModel
|
||||||
|
|
||||||
|
|
||||||
|
class AnotherUniquenessModel(models.Model):
|
||||||
|
code = models.IntegerField(unique=True)
|
||||||
|
|
||||||
|
|
||||||
|
class AnotherUniquenessSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = AnotherUniquenessModel
|
||||||
|
|
||||||
|
|
||||||
class TestUniquenessValidation(TestCase):
|
class TestUniquenessValidation(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.instance = UniquenessModel.objects.create(username='existing')
|
self.instance = UniquenessModel.objects.create(username='existing')
|
||||||
|
@ -51,6 +60,17 @@ class TestUniquenessValidation(TestCase):
|
||||||
assert serializer.is_valid()
|
assert serializer.is_valid()
|
||||||
assert serializer.validated_data == {'username': 'existing'}
|
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`
|
# Tests for `UniqueTogetherValidator`
|
||||||
# -----------------------------------
|
# -----------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user