From c592bfcca976cdce1557c6491b06914c8a813c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Mon, 11 Mar 2019 10:15:39 +0100 Subject: [PATCH] fix: get_object_template_id was broken. Add test case. Fix #361 --- pymisp/api.py | 15 +++++++++++++-- tests/testlive_comprehensive.py | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pymisp/api.py b/pymisp/api.py index 2ae60fa..5a1285f 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -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') diff --git a/tests/testlive_comprehensive.py b/tests/testlive_comprehensive.py index fe69b59..cec8b52 100644 --- a/tests/testlive_comprehensive.py +++ b/tests/testlive_comprehensive.py @@ -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()