@@ -248,7 +248,7 @@ def test_is_not_unique_together(self):
248248
249249def test_is_not_unique_together_condition_based (self ):
250250"""
251- Failing unique together validation should result in non field errors when a condition-based
251+ Failing unique together validation should result in non- field errors when a condition-based
252252 unique together constraint is violated.
253253 """
254254ConditionUniquenessTogetherModel .objects .create (race_name = 'example' ,position = 1 )
@@ -275,10 +275,10 @@ def test_is_unique_together(self):
275275'position' :2
276276 }
277277
278- def test_unique_together_condition_based (self ):
278+ def test_is_unique_together_condition_based (self ):
279279"""
280- In a unique together validation,one field may be non-unique
281- so long as theset as a whole is unique .
280+ In acondition-based unique together validation,data is valid when
281+ theconstrained field differs when the condition applies` .
282282 """
283283ConditionUniquenessTogetherModel .objects .create (race_name = 'example' ,position = 1 )
284284
@@ -290,6 +290,21 @@ def test_unique_together_condition_based(self):
290290'position' :1
291291 }
292292
293+ def test_is_unique_together_when_condition_does_not_apply (self ):
294+ """
295+ In a condition-based unique together validation, data is valid when
296+ the condition does not apply, even if constrained fields match existing records.
297+ """
298+ ConditionUniquenessTogetherModel .objects .create (race_name = 'example' ,position = 1 )
299+
300+ data = {'race_name' :'example' ,'position' :2 }
301+ serializer = ConditionUniquenessTogetherSerializer (data = data )
302+ assert serializer .is_valid ()
303+ assert serializer .validated_data == {
304+ 'race_name' :'example' ,
305+ 'position' :2
306+ }
307+
293308def test_updated_instance_excluded_from_unique_together (self ):
294309"""
295310 When performing an update, the existing instance does not count
@@ -308,10 +323,10 @@ def test_updated_instance_excluded_from_unique_together_condition_based(self):
308323 When performing an update, the existing instance does not count
309324 as a match against uniqueness.
310325 """
311- ConditionUniquenessTogetherModel .objects .create (race_name = 'example' ,position = 1 )
326+ instance = ConditionUniquenessTogetherModel .objects .create (race_name = 'example' ,position = 1 )
312327
313328data = {'race_name' :'example' ,'position' :0 }
314- serializer = ConditionUniquenessTogetherSerializer (self . instance ,data = data )
329+ serializer = ConditionUniquenessTogetherSerializer (instance ,data = data )
315330assert serializer .is_valid ()
316331assert serializer .validated_data == {
317332'race_name' :'example' ,