Fix revert_machinetag, add test

pull/3/head
Raphaël Vinot 2017-07-26 15:52:39 +02:00
parent 80ab84f86f
commit 1d1bf4f0ec
2 changed files with 4 additions and 1 deletions

View File

@ -261,7 +261,7 @@ class Clusters(collections.Mapping):
def revert_machinetag(self, machinetag):
_, cluster_type, cluster_value = re.findall('^([^:]*):([^=]*)="([^"]*)"$', machinetag)[0]
cluster = self.clusters[cluster_type]
for v in cluster.values:
for v in cluster.values.values():
if v.value == cluster_value:
return cluster, v
raise UnableToRevertMachinetag('The machinetag {} could not be found.'.format(machinetag))

View File

@ -56,3 +56,6 @@ class TestPyMISPGalaxies(unittest.TestCase):
def test_search(self):
self.assertIsNot(len(self.clusters.search('apt')), 0)
def test_revert_machinetag(self):
self.assertEqual(len(self.clusters.revert_machinetag('misp-galaxy:tool="Babar"')), 2)