Merge pull request #239 from oasis-open/238-empty-dictionaries
Remove dictionary/extension property non-empty reqmaster
commit
101eb762d1
|
@ -291,8 +291,6 @@ class DictionaryProperty(Property):
|
||||||
dictified = _get_dict(value)
|
dictified = _get_dict(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError("The dictionary property must contain a dictionary")
|
raise ValueError("The dictionary property must contain a dictionary")
|
||||||
if dictified == {}:
|
|
||||||
raise ValueError("The dictionary property must contain a non-empty dictionary")
|
|
||||||
for k in dictified.keys():
|
for k in dictified.keys():
|
||||||
if self.spec_version == '2.0':
|
if self.spec_version == '2.0':
|
||||||
if len(k) < 3:
|
if len(k) < 3:
|
||||||
|
@ -498,8 +496,6 @@ class ExtensionsProperty(DictionaryProperty):
|
||||||
dictified = copy.deepcopy(dictified)
|
dictified = copy.deepcopy(dictified)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError("The extensions property must contain a dictionary")
|
raise ValueError("The extensions property must contain a dictionary")
|
||||||
if dictified == {}:
|
|
||||||
raise ValueError("The extensions property must contain a non-empty dictionary")
|
|
||||||
|
|
||||||
v = 'v' + self.spec_version.replace('.', '')
|
v = 'v' + self.spec_version.replace('.', '')
|
||||||
|
|
||||||
|
|
|
@ -1141,12 +1141,13 @@ def test_process_example_windows_process_ext_empty():
|
||||||
|
|
||||||
|
|
||||||
def test_process_example_extensions_empty():
|
def test_process_example_extensions_empty():
|
||||||
with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo:
|
proc = stix2.v20.Process(
|
||||||
stix2.v20.Process(extensions={})
|
pid=314,
|
||||||
|
name="foobar.exe",
|
||||||
|
extensions={},
|
||||||
|
)
|
||||||
|
|
||||||
assert excinfo.value.cls == stix2.v20.Process
|
assert '{}' in str(proc)
|
||||||
assert excinfo.value.prop_name == 'extensions'
|
|
||||||
assert 'non-empty dictionary' in excinfo.value.reason
|
|
||||||
|
|
||||||
|
|
||||||
def test_process_example_with_WindowsProcessExt_Object():
|
def test_process_example_with_WindowsProcessExt_Object():
|
||||||
|
|
|
@ -360,7 +360,6 @@ def test_dictionary_property_invalid_key(d):
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"d", [
|
"d", [
|
||||||
({}, "The dictionary property must contain a non-empty dictionary"),
|
|
||||||
# TODO: This error message could be made more helpful. The error is caused
|
# TODO: This error message could be made more helpful. The error is caused
|
||||||
# because `json.loads()` doesn't like the *single* quotes around the key
|
# because `json.loads()` doesn't like the *single* quotes around the key
|
||||||
# name, even though they are valid in a Python dictionary. While technically
|
# name, even though they are valid in a Python dictionary. While technically
|
||||||
|
|
|
@ -1115,12 +1115,12 @@ def test_process_example_windows_process_ext_empty():
|
||||||
|
|
||||||
|
|
||||||
def test_process_example_extensions_empty():
|
def test_process_example_extensions_empty():
|
||||||
with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo:
|
proc = stix2.v21.Process(
|
||||||
stix2.v21.Process(extensions={})
|
pid=314,
|
||||||
|
extensions={},
|
||||||
|
)
|
||||||
|
|
||||||
assert excinfo.value.cls == stix2.v21.Process
|
assert '{}' in str(proc)
|
||||||
assert excinfo.value.prop_name == 'extensions'
|
|
||||||
assert 'non-empty dictionary' in excinfo.value.reason
|
|
||||||
|
|
||||||
|
|
||||||
def test_process_example_with_WindowsProcessExt_Object():
|
def test_process_example_with_WindowsProcessExt_Object():
|
||||||
|
|
|
@ -369,7 +369,6 @@ def test_dictionary_property_invalid_key(d):
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"d", [
|
"d", [
|
||||||
({}, "The dictionary property must contain a non-empty dictionary"),
|
|
||||||
# TODO: This error message could be made more helpful. The error is caused
|
# TODO: This error message could be made more helpful. The error is caused
|
||||||
# because `json.loads()` doesn't like the *single* quotes around the key
|
# because `json.loads()` doesn't like the *single* quotes around the key
|
||||||
# name, even though they are valid in a Python dictionary. While technically
|
# name, even though they are valid in a Python dictionary. While technically
|
||||||
|
|
Loading…
Reference in New Issue