Add test for UnableToRevertMachinetag

pull/3/head
Raphaël Vinot 2017-07-26 17:06:44 +02:00
parent d146ebba88
commit b4ba8dcf84
3 changed files with 5 additions and 3 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .api import Galaxies, Clusters, EncodeGalaxies
from .api import Galaxies, Clusters, EncodeGalaxies, UnableToRevertMachinetag

View File

@ -244,8 +244,8 @@ class Clusters(collections.Mapping):
return [cluster.machinetags() for cluster in self.values()]
def revert_machinetag(self, machinetag):
_, cluster_type, cluster_value = re.findall('^([^:]*):([^=]*)="([^"]*)"$', machinetag)[0]
try:
_, cluster_type, cluster_value = re.findall('^([^:]*):([^=]*)="([^"]*)"$', machinetag)[0]
cluster = self.get(cluster_type)
value = cluster[cluster_value]
return cluster, value

View File

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
import unittest
from pymispgalaxies import Galaxies, Clusters
from pymispgalaxies import Galaxies, Clusters, UnableToRevertMachinetag
from glob import glob
import os
import json
@ -59,6 +59,8 @@ class TestPyMISPGalaxies(unittest.TestCase):
def test_revert_machinetag(self):
self.assertEqual(len(self.clusters.revert_machinetag('misp-galaxy:tool="Babar"')), 2)
with self.assertRaises(UnableToRevertMachinetag):
self.clusters.revert_machinetag('blah')
def test_len(self):
self.assertIsNot(len(self.clusters), 0)