Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion tests/validators/any_of_validator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ def test_with_specified_allowed_type(allowed_types, expected_type_dict, valid_in
**expected_type_dict,
}

@staticmethod
def test_empty_allowed_values_with_allowed_types():
""" Test AnyOfValidator with an empty list of allowed values (requires explicit allowed_types). """
validator = AnyOfValidator([], allowed_types=[str])

# There can't be any valid input for this validator (in that way it acts like a RejectValidator with a different error)
with pytest.raises(ValueNotAllowedError) as exception_info:
validator.validate('banana')
assert exception_info.value.to_dict() == {
'code': 'value_not_allowed',
'allowed_values': [],
}

# Test AnyOfValidator with case-insensitive option

@staticmethod
Expand Down Expand Up @@ -248,9 +261,16 @@ def test_value_not_allowed_error_with_too_many_allowed_values():

# Invalid validator parameters

@staticmethod
def test_empty_allowed_values_requires_allowed_types():
""" Test that AnyOfValidator raises exception when allowed_values is empty and no allowed_types are specified. """
with pytest.raises(InvalidValidatorOptionException) as exception_info:
AnyOfValidator([])
assert str(exception_info.value) == 'Parameter "allowed_types" is an empty list (or types could not be autodetermined).'

@staticmethod
def test_empty_allowed_types():
""" Check that AnyOfValidator raises exception when allowed_types is empty. """
""" Test that AnyOfValidator raises exception when allowed_types is empty. """
with pytest.raises(InvalidValidatorOptionException) as exception_info:
AnyOfValidator([1, 2, 3], allowed_types=[])
assert str(exception_info.value) == 'Parameter "allowed_types" is an empty list (or types could not be autodetermined).'