Skip to content

Commit dfd7b70

Browse files
committed
fix: [tests, doc] Fixed automated doc generation from tests by allowing multiple stix object types to be documented as result of a conversion
1 parent d47d68f commit dfd7b70

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

tests/_test_stix_export.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -832,13 +832,13 @@ def _populate_attributes_documentation(self, attribute, **kwargs):
832832
feature = attribute['type']
833833
if 'MISP' not in self._attributes_v21[feature]:
834834
self._attributes_v21[feature]['MISP'] = self._sanitize_documentation(attribute)
835-
if 'observed_data' in kwargs:
836-
documented = [json.loads(observable.serialize()) for observable in kwargs['observed_data']]
837-
self._attributes_v21[feature]['STIX']['Observed Data'] = documented
838-
else:
839-
for object_type, stix_object in kwargs.items():
840-
documented = json.loads(stix_object.serialize())
841-
self._attributes_v21[feature]['STIX'][object_type.capitalize()] = documented
835+
for object_type, stix_object in kwargs.items():
836+
if object_type == 'observed_data':
837+
documented = [json.loads(observable.serialize()) for observable in kwargs['observed_data']]
838+
self._attributes_v21[feature]['STIX']['Observed Data'] = documented
839+
continue
840+
documented = json.loads(stix_object.serialize())
841+
self._attributes_v21[feature]['STIX'][object_type.capitalize()] = documented
842842

843843
def _populate_galaxies_documentation(self, galaxy, name=None, summary=None, **kwargs):
844844
if name is None:

tests/update_documentation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ def _replace_data(self, attribute, name, stix_mapping):
203203

204204
@staticmethod
205205
def _replace_export_file_data(mapping, data, short_data):
206-
mapping['Indicator']['pattern'] = mapping['Indicator']['pattern'].replace(data, short_data)
206+
if mapping.get('Indicator', {}).get('pattern') is not None:
207+
mapping['Indicator']['pattern'] = mapping['Indicator']['pattern'].replace(data, short_data)
207208
if isinstance(mapping['Observed Data'], list):
208209
for observable in mapping['Observed Data'][1:]:
209210
if observable['type'] == 'artifact':

0 commit comments

Comments
 (0)