chg: [tests] Few improvements

pull/430/head
Raphaël Vinot 2019-08-01 15:10:48 +02:00
parent 1b85f73d89
commit b1c79f939b
2 changed files with 26 additions and 22 deletions

View File

@ -604,11 +604,6 @@ class ExpandedPyMISP(PyMISP):
# ## BEGIN Taxonomies ### # ## BEGIN Taxonomies ###
def update_taxonomies(self):
"""Update all the taxonomies."""
response = self._prepare_request('POST', 'taxonomies/update')
return self._check_response(response, expect_json=True)
def taxonomies(self, pythonify: bool=False): def taxonomies(self, pythonify: bool=False):
"""Get all the taxonomies.""" """Get all the taxonomies."""
taxonomies = self._prepare_request('GET', 'taxonomies') taxonomies = self._prepare_request('GET', 'taxonomies')
@ -663,6 +658,11 @@ class ExpandedPyMISP(PyMISP):
response = self._prepare_request('POST', url) response = self._prepare_request('POST', url)
return self._check_response(response, expect_json=True) return self._check_response(response, expect_json=True)
def update_taxonomies(self):
"""Update all the taxonomies."""
response = self._prepare_request('POST', 'taxonomies/update')
return self._check_response(response, expect_json=True)
# ## END Taxonomies ### # ## END Taxonomies ###
# ## BEGIN Warninglists ### # ## BEGIN Warninglists ###
@ -713,11 +713,6 @@ class ExpandedPyMISP(PyMISP):
response = self._prepare_request('POST', 'warninglists/toggleEnable', data=json.dumps(query)) response = self._prepare_request('POST', 'warninglists/toggleEnable', data=json.dumps(query))
return self._check_response(response, expect_json=True) return self._check_response(response, expect_json=True)
def update_warninglists(self):
"""Update all the warninglists."""
response = self._prepare_request('POST', 'warninglists/update')
return self._check_response(response, expect_json=True)
def enable_warninglist(self, warninglist: Union[MISPWarninglist, int, str, UUID]): def enable_warninglist(self, warninglist: Union[MISPWarninglist, int, str, UUID]):
"""Enable a warninglist.""" """Enable a warninglist."""
warninglist_id = self.__get_uuid_or_id_from_abstract_misp(warninglist) warninglist_id = self.__get_uuid_or_id_from_abstract_misp(warninglist)
@ -733,6 +728,11 @@ class ExpandedPyMISP(PyMISP):
response = self._prepare_request('POST', 'warninglists/checkValue', data=json.dumps(value)) response = self._prepare_request('POST', 'warninglists/checkValue', data=json.dumps(value))
return self._check_response(response, expect_json=True) return self._check_response(response, expect_json=True)
def update_warninglists(self):
"""Update all the warninglists."""
response = self._prepare_request('POST', 'warninglists/update')
return self._check_response(response, expect_json=True)
# ## END Warninglists ### # ## END Warninglists ###
# ## BEGIN Noticelist ### # ## BEGIN Noticelist ###
@ -1693,11 +1693,10 @@ class ExpandedPyMISP(PyMISP):
def users_statistics(self, context: str='data'): def users_statistics(self, context: str='data'):
"""Get users statistics from the MISP instance""" """Get users statistics from the MISP instance"""
# FIXME: https://github.com/MISP/MISP/issues/4874
availables_contexts = ['data', 'orgs', 'users', 'tags', 'attributehistogram', 'sightings', 'galaxyMatrix'] availables_contexts = ['data', 'orgs', 'users', 'tags', 'attributehistogram', 'sightings', 'galaxyMatrix']
if context not in availables_contexts: if context not in availables_contexts:
raise PyMISPError("context can only be {','.join(availables_contexts)}") raise PyMISPError("context can only be {','.join(availables_contexts)}")
response = self._prepare_request('GET', f'users/statistics/{context}.json') response = self._prepare_request('GET', f'users/statistics/{context}')
return self._check_response(response) return self._check_response(response)
# ## END Statistics ### # ## END Statistics ###

View File

@ -1551,10 +1551,9 @@ class TestComprehensive(unittest.TestCase):
self.assertEqual(r['name'], 'Organisation added to the sharing group.') self.assertEqual(r['name'], 'Organisation added to the sharing group.')
# delete org # delete org
# FIXME: https://github.com/MISP/MISP/issues/4884 r = self.admin_misp_connector.remove_org_from_sharing_group(sharing_group.id,
# r = self.admin_misp_connector.remove_org_from_sharing_group(sharing_group.id, self.test_org.id)
# self.test_org.id) self.assertEqual(r['name'], 'Organisation removed from the sharing group.', r)
# self.assertEqual(r['name'], 'Organisation deleted from the sharing group.', r)
# Get list # Get list
sharing_groups = self.admin_misp_connector.sharing_groups(pythonify=True) sharing_groups = self.admin_misp_connector.sharing_groups(pythonify=True)
self.assertTrue(isinstance(sharing_groups, list)) self.assertTrue(isinstance(sharing_groups, list))
@ -1563,20 +1562,26 @@ class TestComprehensive(unittest.TestCase):
# Use the SG # Use the SG
first = self.create_simple_event() first = self.create_simple_event()
o = first.add_object(name='file')
o.add_attribute('filename', value='foo2.exe')
try: try:
first = self.user_misp_connector.add_event(first) first = self.user_misp_connector.add_event(first)
first = self.admin_misp_connector.change_sharing_group_on_entity(first, sharing_group.id, pythonify=True) first = self.admin_misp_connector.change_sharing_group_on_entity(first, sharing_group.id, pythonify=True)
self.assertEqual(first.SharingGroup['name'], 'Testcases SG') self.assertEqual(first.SharingGroup['name'], 'Testcases SG')
first_object = self.admin_misp_connector.change_sharing_group_on_entity(first.objects[0], sharing_group.id, pythonify=True)
self.assertEqual(first_object.sharing_group_id, sharing_group.id)
# FIXME https://github.com/MISP/MISP/issues/4891 # FIXME https://github.com/MISP/MISP/issues/4891
# first_attribute = self.admin_misp_connector.change_sharing_group_on_entity(first.attributes[0], sharing_group.id) # NOTE: Fails with pythonify because the sharing group id isn't in the response
# self.assertEqual(first_attribute.SharingGroup['name'], 'Testcases SG') # first_attribute = self.admin_misp_connector.change_sharing_group_on_entity(first.attributes[0], sharing_group.id, pythonify=True)
# self.assertEqual(first_attribute.distribution, 4)
# self.assertEqual(first_attribute.sharing_group_id, sharing_group.id)
finally: finally:
# Delete event # Delete event
self.admin_misp_connector.delete_event(first.id) self.admin_misp_connector.delete_event(first.id)
# Delete sharing group
# delete r = self.admin_misp_connector.delete_sharing_group(sharing_group.id)
r = self.admin_misp_connector.delete_sharing_group(sharing_group.id) self.assertEqual(r['message'], 'SharingGroup deleted')
self.assertEqual(r['message'], 'SharingGroup deleted')
def test_feeds(self): def test_feeds(self):
# Add # Add