diff --git a/pymisp/api.py b/pymisp/api.py index e69bb72..a2c29c0 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -122,9 +122,7 @@ class PyMISP(object): try: self.describe_types = self.get_live_describe_types() except Exception: - with open(os.path.join(self.resources_path, 'describeTypes.json'), 'r') as f: - describe_types = json.load(f) - self.describe_types = describe_types['result'] + self.describe_types = self.get_local_describe_types() self.categories = self.describe_types['categories'] self.types = self.describe_types['types'] @@ -136,6 +134,11 @@ class PyMISP(object): response = self.__prepare_request('GET', urljoin(self.root_url, 'events/queryACL.json')) return self._check_response(response) + def get_local_describe_types(self): + with open(os.path.join(self.resources_path, 'describeTypes.json'), 'r') as f: + describe_types = json.load(f) + return describe_types['result'] + def get_live_describe_types(self): response = self.__prepare_request('GET', urljoin(self.root_url, 'attributes/describeTypes.json')) describe_types = self._check_response(response) diff --git a/tests/test.py b/tests/test.py index a678191..acd5a77 100755 --- a/tests/test.py +++ b/tests/test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from pymisp import PyMISP +from pymisp import PyMISP, __version__ from keys import url, key import time @@ -282,10 +282,19 @@ class TestBasic(unittest.TestCase): self.assertTrue(sd['to_ids'] in [0, 1]) self.assertTrue(sd['default_category'] in categories) + def test_describeTypes_uptodate(self): + self.assertEqual(self.live_describe_types, self.misp.get_local_describe_types()) + def test_live_acl(self): query_acl = self.misp.get_live_query_acl() self.assertEqual(query_acl['response'], []) + def test_recommended_pymisp_version(self): + response = self.misp.get_recommended_api_version() + recommended_version_tup = tuple(int(x) for x in response['version'].split('.')) + pymisp_version_tup = tuple(int(x) for x in __version__.split('.'))[:3] + self.assertEqual(recommended_version_tup, pymisp_version_tup) + if __name__ == '__main__': unittest.main()