Add tests for required fields.

stix2.1
Greg Back 2017-01-17 14:52:56 -08:00
parent ebf6513445
commit 31cebdd34a
2 changed files with 19 additions and 0 deletions

View File

@ -43,7 +43,13 @@ class Indicator:
self.created = created or now
self.modified = modified or now
if not labels:
raise ValueError("Missing required field for Indicator: 'labels'.")
self.labels = labels
if not pattern:
raise ValueError("Missing required field for Indicator: 'pattern'.")
self.pattern = pattern
self.valid_from = valid_from or now

View File

@ -81,3 +81,16 @@ def test_indicator_id_must_start_with_indicator():
indicator = stix2.Indicator(id='my-prefix--')
assert "Indicator id values must begin with 'indicator--'." in str(excinfo)
def test_indicator_required_field_labels():
with pytest.raises(ValueError) as excinfo:
indicator = stix2.Indicator()
assert "Missing required field for Indicator: 'labels'." in str(excinfo)
def test_indicator_required_field_pattern():
with pytest.raises(ValueError) as excinfo:
# Label is checked first, so make sure that is provided
indicator = stix2.Indicator(labels=['malicious-activity'])
assert "Missing required field for Indicator: 'pattern'." in str(excinfo)