Fix tests in 'test_properties.py'

stix2.1
Emmanuelle Vargas-Gonzalez 2018-07-10 16:10:01 -04:00
parent d24cddb547
commit 48e0442439
2 changed files with 34 additions and 34 deletions

View File

@ -1,14 +1,14 @@
import pytest import pytest
from stix2 import CustomObject, EmailMIMEComponent, ExtensionsProperty, TCPExt import stix2
from stix2.exceptions import AtLeastOnePropertyError, DictionaryKeyError from stix2.exceptions import AtLeastOnePropertyError, DictionaryKeyError
from stix2.v20.properties import (BinaryProperty, BooleanProperty, from stix2.properties import (BinaryProperty, BooleanProperty,
DictionaryProperty, EmbeddedObjectProperty, DictionaryProperty, EmbeddedObjectProperty,
EnumProperty, FloatProperty, HashesProperty, EnumProperty, ExtensionsProperty, FloatProperty,
HexProperty, IDProperty, IntegerProperty, HashesProperty, HexProperty, IDProperty,
ListProperty, Property, ReferenceProperty, IntegerProperty, ListProperty, Property,
StringProperty, TimestampProperty, ReferenceProperty, StringProperty,
TypeProperty) TimestampProperty, TypeProperty)
from .constants import FAKE_TIME from .constants import FAKE_TIME
@ -235,7 +235,7 @@ def test_dictionary_property_valid(d):
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaa: (longer than 256 characters)."], "aaaaaaaaaaaaaaaaaaaaaaa: (longer than 256 characters)."],
[{'Hey!': 'something'}, "Invalid dictionary key Hey!: (contains characters other thanlowercase a-z, " [{'Hey!': 'something'}, "Invalid dictionary key Hey!: (contains characters other than lowercase a-z, "
"uppercase A-Z, numerals 0-9, hyphen (-), or underscore (_))."], "uppercase A-Z, numerals 0-9, hyphen (-), or underscore (_))."],
]) ])
def test_dictionary_property_invalid_key(d): def test_dictionary_property_invalid_key(d):
@ -268,7 +268,7 @@ def test_dictionary_property_invalid(d):
def test_property_list_of_dictionary(): def test_property_list_of_dictionary():
@CustomObject('x-new-obj', [ @stix2.v20.CustomObject('x-new-obj', [
('property1', ListProperty(DictionaryProperty(), required=True)), ('property1', ListProperty(DictionaryProperty(), required=True)),
]) ])
class NewObj(): class NewObj():
@ -299,8 +299,8 @@ def test_hashes_property_invalid(value):
def test_embedded_property(): def test_embedded_property():
emb_prop = EmbeddedObjectProperty(type=EmailMIMEComponent) emb_prop = EmbeddedObjectProperty(type=stix2.v20.EmailMIMEComponent)
mime = EmailMIMEComponent( mime = stix2.v20.EmailMIMEComponent(
content_type="text/plain; charset=utf-8", content_type="text/plain; charset=utf-8",
content_disposition="inline", content_disposition="inline",
body="Cats are funny!" body="Cats are funny!"
@ -361,4 +361,4 @@ def test_extension_property_invalid_type():
def test_extension_at_least_one_property_constraint(): def test_extension_at_least_one_property_constraint():
with pytest.raises(AtLeastOnePropertyError): with pytest.raises(AtLeastOnePropertyError):
TCPExt() stix2.v20.TCPExt()

View File

@ -1,14 +1,14 @@
import pytest import pytest
from stix2 import CustomObject, EmailMIMEComponent, ExtensionsProperty, TCPExt import stix2
from stix2.exceptions import AtLeastOnePropertyError, DictionaryKeyError from stix2.exceptions import AtLeastOnePropertyError, DictionaryKeyError
from stix2.v21.properties import (BinaryProperty, BooleanProperty, from stix2.properties import (BinaryProperty, BooleanProperty,
DictionaryProperty, EmbeddedObjectProperty, DictionaryProperty, EmbeddedObjectProperty,
EnumProperty, FloatProperty, HashesProperty, EnumProperty, ExtensionsProperty, FloatProperty,
HexProperty, IDProperty, IntegerProperty, HashesProperty, HexProperty, IDProperty,
ListProperty, Property, ReferenceProperty, IntegerProperty, ListProperty, Property,
StringProperty, TimestampProperty, ReferenceProperty, StringProperty,
TypeProperty) TimestampProperty, TypeProperty)
from .constants import FAKE_TIME from .constants import FAKE_TIME
@ -224,7 +224,7 @@ def test_hex_property():
[('abc', 1), ('bcd', 2), ('cde', 3)], [('abc', 1), ('bcd', 2), ('cde', 3)],
]) ])
def test_dictionary_property_valid(d): def test_dictionary_property_valid(d):
dict_prop = DictionaryProperty() dict_prop = DictionaryProperty(spec_version='2.1')
assert dict_prop.clean(d) assert dict_prop.clean(d)
@ -232,7 +232,7 @@ def test_dictionary_property_valid(d):
[{'a': 'something'}, "Invalid dictionary key a: (shorter than 3 characters)."], [{'a': 'something'}, "Invalid dictionary key a: (shorter than 3 characters)."],
]) ])
def test_dictionary_no_longer_raises(d): def test_dictionary_no_longer_raises(d):
dict_prop = DictionaryProperty() dict_prop = DictionaryProperty(spec_version='2.1')
try: try:
dict_prop.clean(d[0]) dict_prop.clean(d[0])
@ -246,11 +246,11 @@ def test_dictionary_no_longer_raises(d):
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaa: (longer than 250 characters)."], "aaaaaaaaaaaaaaaaaaaaaaa: (longer than 250 characters)."],
[{'Hey!': 'something'}, "Invalid dictionary key Hey!: (contains characters other thanlowercase a-z, " [{'Hey!': 'something'}, "Invalid dictionary key Hey!: (contains characters other than lowercase a-z, "
"uppercase A-Z, numerals 0-9, hyphen (-), or underscore (_))."], "uppercase A-Z, numerals 0-9, hyphen (-), or underscore (_))."],
]) ])
def test_dictionary_property_invalid_key(d): def test_dictionary_property_invalid_key(d):
dict_prop = DictionaryProperty() dict_prop = DictionaryProperty(spec_version='2.1')
with pytest.raises(DictionaryKeyError) as excinfo: with pytest.raises(DictionaryKeyError) as excinfo:
dict_prop.clean(d[0]) dict_prop.clean(d[0])
@ -271,7 +271,7 @@ def test_dictionary_property_invalid_key(d):
("{'description': 'something'}", "The dictionary property must contain a dictionary"), ("{'description': 'something'}", "The dictionary property must contain a dictionary"),
]) ])
def test_dictionary_property_invalid(d): def test_dictionary_property_invalid(d):
dict_prop = DictionaryProperty() dict_prop = DictionaryProperty(spec_version='2.1')
with pytest.raises(ValueError) as excinfo: with pytest.raises(ValueError) as excinfo:
dict_prop.clean(d[0]) dict_prop.clean(d[0])
@ -279,8 +279,8 @@ def test_dictionary_property_invalid(d):
def test_property_list_of_dictionary(): def test_property_list_of_dictionary():
@CustomObject('x-new-obj', [ @stix2.v21.CustomObject('x-new-obj', [
('property1', ListProperty(DictionaryProperty(), required=True)), ('property1', ListProperty(DictionaryProperty(spec_version='2.1'), required=True)),
]) ])
class NewObj(): class NewObj():
pass pass
@ -310,8 +310,8 @@ def test_hashes_property_invalid(value):
def test_embedded_property(): def test_embedded_property():
emb_prop = EmbeddedObjectProperty(type=EmailMIMEComponent) emb_prop = EmbeddedObjectProperty(type=stix2.v21.EmailMIMEComponent)
mime = EmailMIMEComponent( mime = stix2.v21.EmailMIMEComponent(
content_type="text/plain; charset=utf-8", content_type="text/plain; charset=utf-8",
content_disposition="inline", content_disposition="inline",
body="Cats are funny!" body="Cats are funny!"
@ -339,7 +339,7 @@ def test_enum_property_invalid():
def test_extension_property_valid(): def test_extension_property_valid():
ext_prop = ExtensionsProperty(enclosing_type='file') ext_prop = ExtensionsProperty(spec_version='2.1', enclosing_type='file')
assert ext_prop({ assert ext_prop({
'windows-pebinary-ext': { 'windows-pebinary-ext': {
'pe_type': 'exe' 'pe_type': 'exe'
@ -354,13 +354,13 @@ def test_extension_property_valid():
}}, }},
]) ])
def test_extension_property_invalid(data): def test_extension_property_invalid(data):
ext_prop = ExtensionsProperty(enclosing_type='file') ext_prop = ExtensionsProperty(spec_version='2.1', enclosing_type='file')
with pytest.raises(ValueError): with pytest.raises(ValueError):
ext_prop.clean(data) ext_prop.clean(data)
def test_extension_property_invalid_type(): def test_extension_property_invalid_type():
ext_prop = ExtensionsProperty(enclosing_type='indicator') ext_prop = ExtensionsProperty(spec_version='2.1', enclosing_type='indicator')
with pytest.raises(ValueError) as excinfo: with pytest.raises(ValueError) as excinfo:
ext_prop.clean({ ext_prop.clean({
'windows-pebinary-ext': { 'windows-pebinary-ext': {
@ -372,4 +372,4 @@ def test_extension_property_invalid_type():
def test_extension_at_least_one_property_constraint(): def test_extension_at_least_one_property_constraint():
with pytest.raises(AtLeastOnePropertyError): with pytest.raises(AtLeastOnePropertyError):
TCPExt() stix2.v21.TCPExt()