fix: get_object_template_id was broken. Add test case.

Fix #361
pull/366/head
Raphaël Vinot 2019-03-11 10:15:39 +01:00
parent 35b4f3f852
commit c592bfcca9
2 changed files with 17 additions and 2 deletions

View File

@ -2320,11 +2320,22 @@ class PyMISP(object):
response = self._prepare_request('GET', url)
return self._check_response(response)
def get_object_template_id(self, object_uuid):
"""Gets the template ID corresponting the UUID passed as parameter"""
def get_object_template(self, object_uuid):
"""Gets the full object template corresponting the UUID passed as parameter"""
url = urljoin(self.root_url, 'objectTemplates/view/{}'.format(object_uuid))
response = self._prepare_request('GET', url)
return self._check_response(response)
if 'ObjectTemplate' in response:
return response['ObjectTemplate']['id']
return response
def get_object_template_id(self, object_uuid):
"""Gets the template ID corresponting the UUID passed as parameter"""
template = self.get_object_template(object_uuid)
if 'ObjectTemplate' in template:
return template['ObjectTemplate']['id']
# Contains the error message.
return template
def update_object_templates(self):
url = urljoin(self.root_url, 'objectTemplates/update')

View File

@ -908,6 +908,10 @@ class TestComprehensive(unittest.TestCase):
# Delete event
self.admin_misp_connector.delete_event(first.id)
def test_object_template(self):
template = self.admin_misp_connector.get_object_template('688c46fb-5edb-40a3-8273-1af7923e2215')
self.assertEqual(template['ObjectTemplate']['uuid'], '688c46fb-5edb-40a3-8273-1af7923e2215')
def test_update_modules(self):
# object templates
self.admin_misp_connector.update_object_templates()