Пример #1
0
 def test_must_raise_validation_exception_only_when_all_entries_are_invalid_when_all_is_false(
         self):
     input = [-1, 2, 8]
     try:
         is_list(validator=is_int(min=1), all=False)(input)
     except ValidationException:
         raise AssertionError("should not throw")
Пример #2
0
 def test_must_return_only_valid_inputs_when_all_is_false(self):
     input = [1, -8, 3]
     assert is_list(validator=is_int(min=1), all=False)(input) == [1, 3]
Пример #3
0
 def test_must_return_newly_validated_input(self, validator, input,
                                            return_val):
     assert is_list(validator=validator)(input) == return_val
Пример #4
0
 def test_must_raise_validation_when_at_least_one_entry_is_invalid_by_default(
         self, validator, input, errors):
     with pytest.raises(ValidationException) as exc:
         is_list(validator=validator)(input)
     assert exc.value.errors == errors
Пример #5
0
 def test_must_validate_all_input_against_validator(self):
     validator = Mock()
     is_list(validator=validator)([-1, 8])
     validator.assert_has_calls([call(-1), call(8)])
Пример #6
0
 def test_must_raise_validation_exception_for_non_list_input(self, input):
     with pytest.raises(ValidationException) as exc:
         is_list(validator=Mock())(input)
     assert exc.value.errors == "expected a list but got {}".format(
         type(input))
Пример #7
0
 def test_must_return_default_value_when_input_is_none(self):
     default = [1, 2]
     assert default == is_list(required=False,
                               default=[1, 2],
                               validator=is_int())(None)
Пример #8
0
 def test_must_raise_validation_error_when_input_is_none_but_required_is_true(
         self):
     with pytest.raises(ValidationException) as exc_info:
         is_list(required=True, validator=is_int())(None)
     assert exc_info.value.errors == "required but was missing"