Example #1
0
 def test_validation_passes(self, rules):
     """Test that validation passes when the rules pass."""
     instance = Mock()
     serializer = Mock(instance=instance,
                       error_messages={'error': 'test error'})
     validator = RulesBasedValidator(*rules)
     validator.set_context(serializer)
     assert validator({}) is None
Example #2
0
 def test_validation_fails(self, rules, errors):
     """Test that validation fails when any rule fails."""
     instance = Mock()
     serializer = Mock(
         instance=instance,
         error_messages={
             'error': 'test error',
             'error2': 'test error 2',
         },
     )
     validator = RulesBasedValidator(*rules)
     validator.set_context(serializer)
     with pytest.raises(ValidationError) as excinfo:
         validator({})
     assert excinfo.value.detail == errors