From d08be151f713e020f502a5aea516b0859fd1679e Mon Sep 17 00:00:00 2001 From: Chris Lenk Date: Thu, 12 Apr 2018 21:26:48 -0400 Subject: [PATCH] Allow a ListProperty of DictionaryProperties --- stix2/properties.py | 2 ++ stix2/test/test_properties.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/stix2/properties.py b/stix2/properties.py index ca7f04c..41841b6 100644 --- a/stix2/properties.py +++ b/stix2/properties.py @@ -129,6 +129,8 @@ class ListProperty(Property): # constructor again result.append(valid) continue + elif type(self.contained) is DictionaryProperty: + obj_type = dict else: obj_type = self.contained diff --git a/stix2/test/test_properties.py b/stix2/test/test_properties.py index 34edc96..16ff06a 100644 --- a/stix2/test/test_properties.py +++ b/stix2/test/test_properties.py @@ -1,6 +1,6 @@ import pytest -from stix2 import EmailMIMEComponent, ExtensionsProperty, TCPExt +from stix2 import CustomObject, EmailMIMEComponent, ExtensionsProperty, TCPExt from stix2.exceptions import AtLeastOnePropertyError, DictionaryKeyError from stix2.properties import (BinaryProperty, BooleanProperty, DictionaryProperty, EmbeddedObjectProperty, @@ -266,6 +266,17 @@ def test_dictionary_property_invalid(d): assert str(excinfo.value) == d[1] +def test_property_list_of_dictionary(): + @CustomObject('x-new-obj', [ + ('property1', ListProperty(DictionaryProperty(), required=True)), + ]) + class NewObj(): + pass + + test_obj = NewObj(property1=[{'foo': 'bar'}]) + assert test_obj.property1[0]['foo'] == 'bar' + + @pytest.mark.parametrize("value", [ {"sha256": "6db12788c37247f2316052e142f42f4b259d6561751e5f401a1ae2a6df9c674b"}, [('MD5', '2dfb1bcc980200c6706feee399d41b3f'), ('RIPEMD-160', 'b3a8cd8a27c90af79b3c81754f267780f443dfef')],