2017-03-22 14:26:13 +01:00
|
|
|
import datetime as dt
|
|
|
|
import json
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import pytz
|
|
|
|
|
|
|
|
from stix2.base import STIXJSONEncoder
|
|
|
|
|
|
|
|
|
|
|
|
def test_encode_json_datetime():
|
|
|
|
now = dt.datetime(2017, 3, 22, 0, 0, 0, tzinfo=pytz.UTC)
|
|
|
|
test_dict = {'now': now}
|
|
|
|
|
|
|
|
expected = '{"now": "2017-03-22T00:00:00Z"}'
|
|
|
|
assert json.dumps(test_dict, cls=STIXJSONEncoder) == expected
|
|
|
|
|
|
|
|
|
|
|
|
def test_encode_json_object():
|
|
|
|
obj = object()
|
|
|
|
test_dict = {'obj': obj}
|
|
|
|
|
|
|
|
with pytest.raises(TypeError) as excinfo:
|
|
|
|
json.dumps(test_dict, cls=STIXJSONEncoder)
|
|
|
|
|
2017-03-22 14:33:42 +01:00
|
|
|
assert " is not JSON serializable" in str(excinfo.value)
|