mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Merge 2ce30ddc7a
into d2994e0596
This commit is contained in:
commit
f08f27a46f
|
@ -341,6 +341,28 @@ class TestUniquenessTogetherValidation(TestCase):
|
||||||
validator.filter_queryset(attrs=data, queryset=queryset)
|
validator.filter_queryset(attrs=data, queryset=queryset)
|
||||||
assert queryset.called_with == {'race_name': 'bar', 'position': 1}
|
assert queryset.called_with == {'race_name': 'bar', 'position': 1}
|
||||||
|
|
||||||
|
def test_validator_instances_with_context_are_not_used_twice(self):
|
||||||
|
"""
|
||||||
|
Every instance of a serializer should use unique instances of validators
|
||||||
|
when calling `set_context`.
|
||||||
|
"""
|
||||||
|
def data():
|
||||||
|
return {'race_name': 'example', 'position': 3}
|
||||||
|
|
||||||
|
def check_validators(serializer):
|
||||||
|
for validator in serializer.validators:
|
||||||
|
assert not hasattr(validator, 'instance')
|
||||||
|
|
||||||
|
serializer = UniquenessTogetherSerializer(self.instance, data=data())
|
||||||
|
check_validators(serializer)
|
||||||
|
serializer.run_validators({})
|
||||||
|
check_validators(serializer)
|
||||||
|
|
||||||
|
another_serializer = UniquenessTogetherSerializer(data=data())
|
||||||
|
check_validators(another_serializer)
|
||||||
|
another_serializer.run_validators(data())
|
||||||
|
check_validators(another_serializer)
|
||||||
|
|
||||||
|
|
||||||
# Tests for `UniqueForDateValidator`
|
# Tests for `UniqueForDateValidator`
|
||||||
# ----------------------------------
|
# ----------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user