File tree 1 file changed +22
-0
lines changed 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -341,6 +341,28 @@ def filter(self, **kwargs):
341
341
validator .filter_queryset (attrs = data , queryset = queryset )
342
342
assert queryset .called_with == {'race_name' : 'bar' , 'position' : 1 }
343
343
344
+ def test_validator_instances_with_context_are_not_used_twice (self ):
345
+ """
346
+ Every instance of a serializer should use unique instances of validators
347
+ when calling `set_context`.
348
+ """
349
+ def data ():
350
+ return {'race_name' : 'example' , 'position' : 3 }
351
+
352
+ def check_validators (serializer ):
353
+ for validator in serializer .validators :
354
+ assert not hasattr (validator , 'instance' )
355
+
356
+ serializer = UniquenessTogetherSerializer (self .instance , data = data ())
357
+ check_validators (serializer )
358
+ serializer .run_validators ({})
359
+ check_validators (serializer )
360
+
361
+ another_serializer = UniquenessTogetherSerializer (data = data ())
362
+ check_validators (another_serializer )
363
+ another_serializer .run_validators (data ())
364
+ check_validators (another_serializer )
365
+
344
366
345
367
# Tests for `UniqueForDateValidator`
346
368
# ----------------------------------
You can’t perform that action at this time.
0 commit comments