Merge pull request #760 from JakubOnderka/get-taxonomy-namespace

chg: `get_taxonomy` supports namespace
pull/770/head
Raphaël Vinot 2021-06-22 11:24:15 -07:00 committed by GitHub
commit 4c003ca810
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -1092,7 +1092,7 @@ class PyMISP:
return to_return return to_return
def get_taxonomy(self, taxonomy: Union[MISPTaxonomy, int, str, UUID], pythonify: bool = False) -> Union[Dict, MISPTaxonomy]: def get_taxonomy(self, taxonomy: Union[MISPTaxonomy, int, str, UUID], pythonify: bool = False) -> Union[Dict, MISPTaxonomy]:
"""Get a taxonomy by id from a MISP instance """Get a taxonomy by id or namespace from a MISP instance
:param taxonomy: taxonomy to get :param taxonomy: taxonomy to get
:param pythonify: Returns a PyMISP Object instead of the plain json output :param pythonify: Returns a PyMISP Object instead of the plain json output

View File

@ -1576,6 +1576,8 @@ class TestComprehensive(unittest.TestCase):
# Get list # Get list
taxonomies = self.admin_misp_connector.taxonomies(pythonify=True) taxonomies = self.admin_misp_connector.taxonomies(pythonify=True)
self.assertTrue(isinstance(taxonomies, list)) self.assertTrue(isinstance(taxonomies, list))
# Test fetching taxonomy by ID
list_name_test = 'tlp' list_name_test = 'tlp'
for tax in taxonomies: for tax in taxonomies:
if tax.namespace == list_name_test: if tax.namespace == list_name_test:
@ -1583,10 +1585,17 @@ class TestComprehensive(unittest.TestCase):
r = self.admin_misp_connector.get_taxonomy(tax, pythonify=True) r = self.admin_misp_connector.get_taxonomy(tax, pythonify=True)
self.assertEqual(r.namespace, list_name_test) self.assertEqual(r.namespace, list_name_test)
self.assertTrue('enabled' in r) self.assertTrue('enabled' in r)
# Test fetching taxonomy by namespace
r = self.admin_misp_connector.get_taxonomy("tlp", pythonify=True)
self.assertEqual(r.namespace, "tlp")
r = self.admin_misp_connector.enable_taxonomy(tax) r = self.admin_misp_connector.enable_taxonomy(tax)
self.assertEqual(r['message'], 'Taxonomy enabled') self.assertEqual(r['message'], 'Taxonomy enabled')
r = self.admin_misp_connector.enable_taxonomy_tags(tax) r = self.admin_misp_connector.enable_taxonomy_tags(tax)
self.assertEqual(r['name'], 'The tag(s) has been saved.') self.assertEqual(r['name'], 'The tag(s) has been saved.')
r = self.admin_misp_connector.disable_taxonomy(tax) r = self.admin_misp_connector.disable_taxonomy(tax)
self.assertEqual(r['message'], 'Taxonomy disabled') self.assertEqual(r['message'], 'Taxonomy disabled')