Add IntegerProperty
parent
635a3ec389
commit
a14d507f48
|
@ -151,6 +151,15 @@ class IDProperty(Property):
|
|||
return self.required_prefix + str(uuid.uuid4())
|
||||
|
||||
|
||||
class IntegerProperty(Property):
|
||||
|
||||
def clean(self, value):
|
||||
try:
|
||||
return int(value)
|
||||
except Exception:
|
||||
raise ValueError("must be an integer.")
|
||||
|
||||
|
||||
class BooleanProperty(Property):
|
||||
|
||||
def clean(self, value):
|
||||
|
|
|
@ -2,7 +2,8 @@ import pytest
|
|||
|
||||
from stix2.properties import (Property, BooleanProperty, ListProperty,
|
||||
StringProperty, TypeProperty, IDProperty,
|
||||
ReferenceProperty, TimestampProperty)
|
||||
IntegerProperty, ReferenceProperty,
|
||||
TimestampProperty)
|
||||
from .constants import FAKE_TIME
|
||||
|
||||
|
||||
|
@ -91,6 +92,27 @@ def test_id_property():
|
|||
assert idprop.clean(idprop.default())
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [
|
||||
2,
|
||||
-1,
|
||||
3.14,
|
||||
False,
|
||||
])
|
||||
def test_integer_property_valid(value):
|
||||
int_prop = IntegerProperty()
|
||||
assert int_prop.clean(value) is not None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [
|
||||
"something",
|
||||
StringProperty(),
|
||||
])
|
||||
def test_integer_property_invalid(value):
|
||||
int_prop = IntegerProperty()
|
||||
with pytest.raises(ValueError):
|
||||
int_prop.clean(value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [
|
||||
True,
|
||||
False,
|
||||
|
|
Loading…
Reference in New Issue