def test_custom_code(self): validator = TransportsValidator(code='smeghead') with self.assertRaisesMessage(ValidationError, 'Select a valid choice.') as catcher: validator('rimmer') self.assertEqual(catcher.exception.code, 'smeghead')
def test_invalid(self): validator = TransportsValidator() for value, invalid_chunk in self.invalid_values: with self.assertRaisesMessage(ValidationError, 'Select a valid choice.') as catcher: validator(value) self.assertEqual(catcher.exception.code, 'invalid_choice') self.assertEqual(catcher.exception.params, {'value': invalid_chunk})
def test_custom_message(self): validator = TransportsValidator(message="You're a smeghead.") self.assertRaisesMessage(ValidationError, "You're a smeghead.", validator, 'rimmer')
def test_custom_choices(self): validator = TransportsValidator(choices=['foo', 'bar']) validator('foo,bar') self.assertRaisesMessage(ValidationError, 'Select a valid choice.', validator, 'usb')
def test_valid(self): validator = TransportsValidator() for value in self.valid_values: validator(value)