@@ -408,18 +408,24 @@ class TestValidators(PostgreSQLTestCase):
408
408
def test_max (self ):
409
409
validator = RangeMaxValueValidator (5 )
410
410
validator (NumericRange (0 , 5 ))
411
+ msg = 'Ensure that this range is completely less than or equal to 5.'
411
412
with self .assertRaises (exceptions .ValidationError ) as cm :
412
413
validator (NumericRange (0 , 10 ))
413
- self .assertEqual (cm .exception .messages [0 ], 'Ensure that this range is completely less than or equal to 5.' )
414
+ self .assertEqual (cm .exception .messages [0 ], msg )
414
415
self .assertEqual (cm .exception .code , 'max_value' )
416
+ with self .assertRaisesMessage (exceptions .ValidationError , msg ):
417
+ validator (NumericRange (0 , None )) # an unbound range
415
418
416
419
def test_min (self ):
417
420
validator = RangeMinValueValidator (5 )
418
421
validator (NumericRange (10 , 15 ))
422
+ msg = 'Ensure that this range is completely greater than or equal to 5.'
419
423
with self .assertRaises (exceptions .ValidationError ) as cm :
420
424
validator (NumericRange (0 , 10 ))
421
- self .assertEqual (cm .exception .messages [0 ], 'Ensure that this range is completely greater than or equal to 5.' )
425
+ self .assertEqual (cm .exception .messages [0 ], msg )
422
426
self .assertEqual (cm .exception .code , 'min_value' )
427
+ with self .assertRaisesMessage (exceptions .ValidationError , msg ):
428
+ validator (NumericRange (None , 10 )) # an unbound range
423
429
424
430
425
431
class TestFormField (PostgreSQLTestCase ):
0 commit comments