# HG changeset patch # User BenoƮt Allard # Date 1414409396 -3600 # Node ID 1ea1a3c3c7907fa04af8b819a20c689c2d1f6caa # Parent b15022ae484a1dc6ab44d1364c1591892656e3a6 Add method to change a Group ID diff -r b15022ae484a -r 1ea1a3c3c790 farolluz/document.py --- a/farolluz/document.py Mon Oct 27 12:29:37 2014 +0100 +++ b/farolluz/document.py Mon Oct 27 12:29:56 2014 +0100 @@ -306,13 +306,22 @@ item._productids.remove(old) item._productids.append(new) + def mentionsGroupId(self, groupid): + for vulnerability in self._vulnerabilities: + for item in vulnerability.mentionsGroupId(groupid): + yield item + def isGroupOrphan(self, groupid): """ Returns if a group can be safely deleted """ - for vulnerability in self._vulnerabilities: - if vulnerability.isMentioningGroupId(groupid): - return False + for _ in self.mentionsGroupId(groupid): + return False return True + def changeGroupID(self, old, new): + for item in self.mentionsGroupId(old): + item._groupids.remove(old) + item._groupids.append(new) + def isProductTreeOrphan(self): """ Difference with the previous method is that we don;t care about inter-producttree references """ diff -r b15022ae484a -r 1ea1a3c3c790 tests/testGroupIdRename.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/testGroupIdRename.py Mon Oct 27 12:29:56 2014 +0100 @@ -0,0 +1,27 @@ +from datetime import datetime + +from tests.utils import TestCase +from farolluz.cvrf import CVRFFullProductName, CVRFGroup, CVRFVulnerability, CVRFThreat + +class TestGroupIdRename(TestCase): + + def testChangeGroupId(self): + ptree = self.doc.createProductTree() + prod1 = CVRFFullProductName('1', 'a', ptree) + ptree.addProduct(prod1) + prod2 = CVRFFullProductName('2', 'b', ptree) + ptree.addProduct(prod2) + grp = CVRFGroup('GRP-1') + grp.addProductID('1') + grp.addProductID('2') + ptree.addGroup(grp) + vuln = CVRFVulnerability(1) + th = CVRFThreat('Impact', 'bad !') + th.addGroupID('GRP-1') + vuln.addThreat(th) + self.doc.addVulnerability(vuln) + self._validate() + grp._productid = 'GRP-2' + self.doc.changeProductID('GRP-1', 'GRP-2') + self._validate() +