From 02894b5be6f9ca0f774b18e875bd10d71976bc83 Mon Sep 17 00:00:00 2001 From: Liam Sennitt Date: Tue, 12 Jun 2018 17:32:46 +0100 Subject: [PATCH 1/2] add test for nested dictionary case --- stix2/test/test_custom.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/stix2/test/test_custom.py b/stix2/test/test_custom.py index 7f91d79..68a9e50 100644 --- a/stix2/test/test_custom.py +++ b/stix2/test/test_custom.py @@ -860,3 +860,30 @@ def test_register_custom_object(): def test_extension_property_location(): assert 'extensions' in stix2.v20.observables.OBJ_MAP_OBSERVABLE['x-new-observable']._properties assert 'extensions' not in stix2.v20.observables.EXT_MAP['domain-name']['x-new-ext']._properties + + +@pytest.mark.parametrize("data", [ + """{ + "type": "x-example", + "id": "x-example--336d8a9f-91f1-46c5-b142-6441bb9f8b8d", + "created": "2018-06-12T16:20:58.059Z", + "modified": "2018-06-12T16:20:58.059Z", + "dictionary": { + "key": { + "key_a": "value", + "key_b": "value" + } + } +}""", +]) +def test_custom_object_nested_dictionary(data): + @stix2.sdo.CustomObject('x-example', [ + ('dictionary', stix2.properties.DictionaryProperty()), + ]) + class Example(object): + def __init__(self, **kwargs): + pass + + example = Example(id='x-example--336d8a9f-91f1-46c5-b142-6441bb9f8b8d', created='2018-06-12T16:20:58.059Z', modified='2018-06-12T16:20:58.059Z', dictionary={'key':{'key_b':'value', 'key_a':'value'}}) + + assert data == str(example) From bdec14937d1c67cff0e70b24d15dda95c1caad55 Mon Sep 17 00:00:00 2001 From: Liam Sennitt Date: Tue, 12 Jun 2018 17:45:48 +0100 Subject: [PATCH 2/2] fix flake8 errors in new test --- stix2/test/test_custom.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stix2/test/test_custom.py b/stix2/test/test_custom.py index 68a9e50..6fb24d2 100644 --- a/stix2/test/test_custom.py +++ b/stix2/test/test_custom.py @@ -884,6 +884,9 @@ def test_custom_object_nested_dictionary(data): def __init__(self, **kwargs): pass - example = Example(id='x-example--336d8a9f-91f1-46c5-b142-6441bb9f8b8d', created='2018-06-12T16:20:58.059Z', modified='2018-06-12T16:20:58.059Z', dictionary={'key':{'key_b':'value', 'key_a':'value'}}) + example = Example(id='x-example--336d8a9f-91f1-46c5-b142-6441bb9f8b8d', + created='2018-06-12T16:20:58.059Z', + modified='2018-06-12T16:20:58.059Z', + dictionary={'key': {'key_b': 'value', 'key_a': 'value'}}) assert data == str(example)