Add a unit test for deterministic ID, with unicode

master
Michael Chisholm 2019-10-11 18:15:47 -04:00
parent 216b43d49e
commit edf465bd80
1 changed files with 13 additions and 0 deletions

View File

@ -1,9 +1,11 @@
import datetime as dt import datetime as dt
import json import json
import uuid
import pytest import pytest
import pytz import pytz
import stix2
from stix2.base import STIXJSONEncoder from stix2.base import STIXJSONEncoder
@ -23,3 +25,14 @@ def test_encode_json_object():
json.dumps(test_dict, cls=STIXJSONEncoder) json.dumps(test_dict, cls=STIXJSONEncoder)
assert " is not JSON serializable" in str(excinfo.value) assert " is not JSON serializable" in str(excinfo.value)
def test_deterministic_id_unicode():
mutex = {'name': u'D*Fl#Ed*\u00a3\u00a8', 'type': 'mutex'}
obs = stix2.parse_observable(mutex, version="2.1")
dd_idx = obs.id.index("--")
id_uuid = uuid.UUID(obs.id[dd_idx+2:])
assert id_uuid.variant == uuid.RFC_4122
assert id_uuid.version == 5