Add two tests to ensure millisecond precision is used in timestamps irrespective of user-provided precision

master
Desai, Kartikey H 2019-01-22 10:05:22 -05:00
parent 5658cebf57
commit dda8a7f724
1 changed files with 34 additions and 3 deletions

View File

@ -5,8 +5,6 @@ import pytz
import stix2
from .constants import ATTACK_PATTERN_ID
EXPECTED = """{
"type": "attack-pattern",
"spec_version": "2.1",
@ -65,7 +63,7 @@ def test_parse_attack_pattern(data):
assert ap.type == 'attack-pattern'
assert ap.spec_version == '2.1'
assert ap.id == ATTACK_PATTERN_ID
assert ap.id == "attack-pattern--0c7b5b88-8ff7-4a4d-aa9d-feb398cd0061"
assert ap.created == dt.datetime(2016, 5, 12, 8, 17, 27, tzinfo=pytz.utc)
assert ap.modified == dt.datetime(2016, 5, 12, 8, 17, 27, tzinfo=pytz.utc)
assert ap.description == "..."
@ -84,4 +82,37 @@ def test_attack_pattern_invalid_labels():
labels=1,
)
def test_overly_precise_timestamps():
ap = stix2.v21.AttackPattern(
id="attack-pattern--0c7b5b88-8ff7-4a4d-aa9d-feb398cd0061",
created="2016-05-12T08:17:27.0000342Z",
modified="2016-05-12T08:17:27.000287Z",
name="Spear Phishing",
external_references=[{
"source_name": "capec",
"external_id": "CAPEC-163",
}],
description="...",
)
assert str(ap) == EXPECTED
def test_less_precise_timestamps():
ap = stix2.v21.AttackPattern(
id="attack-pattern--0c7b5b88-8ff7-4a4d-aa9d-feb398cd0061",
created="2016-05-12T08:17:27.00Z",
modified="2016-05-12T08:17:27.0Z",
name="Spear Phishing",
external_references=[{
"source_name": "capec",
"external_id": "CAPEC-163",
}],
description="...",
)
assert str(ap) == EXPECTED
# TODO: Add other examples