Update tests.

stix2.1
Emmanuelle Vargas-Gonzalez 2018-06-26 12:29:20 -04:00
parent 9baaad6e08
commit 59fdd3082e
5 changed files with 21 additions and 20 deletions

View File

@ -2,6 +2,7 @@ import importlib
import pkgutil
import stix2
from .exceptions import ParseError
from .utils import _get_dict

View File

@ -3,8 +3,8 @@ import json
import pytest
import stix2
import stix2.v20.sdo
import stix2.v21.bundle
import stix2.v21.sdo
EXPECTED_BUNDLE = """{
"type": "bundle",
@ -179,8 +179,7 @@ def test_parse_bundle(version):
assert bundle.type == "bundle"
assert bundle.id.startswith("bundle--")
# TODO: update this to a STIX 2.1 indicator
assert type(bundle.objects[0]) is stix2.v20.sdo.Indicator
assert type(bundle.objects[0]) is stix2.v21.sdo.Indicator
assert bundle.objects[0].type == 'indicator'
assert bundle.objects[1].type == 'malware'
assert bundle.objects[2].type == 'relationship'

View File

@ -2,7 +2,7 @@ import pytest
import stix2
import stix2.base
import stix2.v20.sdo
import stix2.v21.sdo
from .constants import FAKE_TIME, MARKING_DEFINITION_ID
@ -95,8 +95,7 @@ def test_identity_custom_property_allowed():
def test_parse_identity_custom_property(data):
with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo:
identity = stix2.parse(data)
# TODO: update to create and check a STIX 2.1 Identity object
assert excinfo.value.cls == stix2.v20.sdo.Identity
assert excinfo.value.cls == stix2.v21.sdo.Identity
assert excinfo.value.properties == ['foo']
assert "Unexpected properties for" in str(excinfo.value)

View File

@ -2,7 +2,6 @@
import datetime as dt
import pytest
import pytz
import stix2
@ -21,7 +20,7 @@ TEST_CAMPAIGN = """{
"description": "More information about bank attack"
}"""
TEST_LANGUAGE_CONTENT = """{
TEST_LANGUAGE_CONTENT = u"""{
"type": "language-content",
"id": "language-content--b86bd89f-98bb-4fa9-8cb2-9ad421da981d",
"created": "2017-02-08T21:31:22.007Z",
@ -30,18 +29,17 @@ TEST_LANGUAGE_CONTENT = """{
"object_modified": "2017-02-08T21:31:22.007Z",
"contents": {
"de": {
"name": "Bank Angriff 1",
"description": "Weitere Informationen über Banküberfall"
"description": "Weitere Informationen über Banküberfall",
"name": "Bank Angriff 1"
},
"fr": {
"name": "Attaque Bank 1",
"description": "Plus d'informations sur la crise bancaire"
"description": "Plus d'informations sur la crise bancaire",
"name": "Attaque Bank 1"
}
}
}"""
@pytest.mark.xfail(reason="Dictionary keys are too short")
def test_language_content_campaign():
now = dt.datetime(2017, 2, 8, 21, 31, 22, microsecond=7000, tzinfo=pytz.utc)
@ -66,5 +64,8 @@ def test_language_content_campaign():
camp = stix2.parse(TEST_CAMPAIGN)
assert str(lc) in TEST_LANGUAGE_CONTENT
# In order to provide the same representation, we need to disable escaping
# in json.dumps(). https://docs.python.org/3/library/json.html#json.dumps
# or https://docs.python.org/2/library/json.html#json.dumps
assert lc.serialize(pretty=True, ensure_ascii=False) == TEST_LANGUAGE_CONTENT
assert lc.modified == camp.modified

View File

@ -2,12 +2,13 @@ import pytest
from stix2 import CustomObject, EmailMIMEComponent, ExtensionsProperty, TCPExt
from stix2.exceptions import AtLeastOnePropertyError, DictionaryKeyError
from stix2.properties import (BinaryProperty, BooleanProperty,
DictionaryProperty, EmbeddedObjectProperty,
EnumProperty, FloatProperty, HashesProperty,
HexProperty, IDProperty, IntegerProperty,
ListProperty, Property, ReferenceProperty,
StringProperty, TimestampProperty, TypeProperty)
from stix2.v20.properties import (BinaryProperty, BooleanProperty,
DictionaryProperty, EmbeddedObjectProperty,
EnumProperty, FloatProperty, HashesProperty,
HexProperty, IDProperty, IntegerProperty,
ListProperty, Property, ReferenceProperty,
StringProperty, TimestampProperty,
TypeProperty)
from .constants import FAKE_TIME