Add a check in ReferenceProperty constructor for an impossible

to satisfy type constraint: empty whitelist.  It would be silly
for anyone to do that, but I should check just in case I guess.
pull/1/head
Michael Chisholm 2020-06-22 16:58:28 -04:00
parent c7dd58ed89
commit 03c265c3a3
3 changed files with 13 additions and 0 deletions

View File

@ -511,6 +511,9 @@ class ReferenceProperty(Property):
elif invalid_types and not isinstance(invalid_types, list):
invalid_types = [invalid_types]
if valid_types is not None and len(valid_types) == 0:
raise ValueError("Impossible type constraint: empty whitelist")
self.types = set(valid_types or invalid_types)
self.auth_type = self._WHITELIST if valid_types else self._BLACKLIST

View File

@ -229,6 +229,11 @@ def test_reference_property_hybrid_constraint_type():
ReferenceProperty(invalid_types=["a", "SCO"], spec_version="2.0")
def test_reference_property_impossible_constraint():
with pytest.raises(ValueError):
ReferenceProperty(valid_types=[], spec_version="2.0")
@pytest.mark.parametrize(
"d", [
{'description': 'something'},

View File

@ -250,6 +250,11 @@ def test_reference_property_hybrid_constraint_type():
ReferenceProperty(invalid_types=["a", "SCO"], spec_version="2.1")
def test_reference_property_impossible_constraint():
with pytest.raises(ValueError):
ReferenceProperty(valid_types=[], spec_version="2.1")
@pytest.mark.parametrize(
"d", [
{'description': 'something'},