cti-python-stix2/stix2/test/test_identity.py

54 lines
1.3 KiB
Python
Raw Normal View History

import datetime as dt
2017-04-19 15:22:08 +02:00
import pytest
import pytz
2017-02-24 18:56:55 +01:00
import stix2
2017-04-19 15:22:08 +02:00
from .constants import IDENTITY_ID
2017-02-24 18:56:55 +01:00
EXPECTED = """{
2017-04-11 18:10:55 +02:00
"created": "2015-12-21T19:59:11Z",
2017-02-24 18:56:55 +01:00
"id": "identity--311b2d2d-f010-5473-83ec-1edf84858f4c",
"identity_class": "individual",
2017-04-11 18:10:55 +02:00
"modified": "2015-12-21T19:59:11Z",
2017-02-24 18:56:55 +01:00
"name": "John Smith",
"type": "identity"
}"""
def test_identity_example():
report = stix2.Identity(
id="identity--311b2d2d-f010-5473-83ec-1edf84858f4c",
2017-04-11 18:10:55 +02:00
created="2015-12-21T19:59:11Z",
modified="2015-12-21T19:59:11Z",
2017-02-24 18:56:55 +01:00
name="John Smith",
identity_class="individual",
)
assert str(report) == EXPECTED
2017-04-19 15:22:08 +02:00
@pytest.mark.parametrize("data", [
EXPECTED,
{
"created": "2015-12-21T19:59:11Z",
"id": "identity--311b2d2d-f010-5473-83ec-1edf84858f4c",
"identity_class": "individual",
"modified": "2015-12-21T19:59:11Z",
"name": "John Smith",
"type": "identity"
},
])
def test_parse_identity(data):
identity = stix2.parse(data)
assert identity.type == 'identity'
assert identity.id == IDENTITY_ID
assert identity.created == dt.datetime(2015, 12, 21, 19, 59, 11, tzinfo=pytz.utc)
assert identity.modified == dt.datetime(2015, 12, 21, 19, 59, 11, tzinfo=pytz.utc)
assert identity.name == "John Smith"
2017-02-24 18:56:55 +01:00
# TODO: Add other examples