示例#1
0
    def __ne__(self, other):
        """Compare NessusReportItem with != operator
           :return: Return true if NessusReportItem has changed
           :rtype: Boolean
           :raises: TypeError
        """
        try:
            self.iscomparable(other)
        except TypeError as etyperr:
            raise etyperr

        diff = DictDiffer(self.get_vuln_info, other.get_vuln_info)
        return (len(diff.unchanged()) != len(self.get_vuln_info))
示例#2
0
 def __eq__(self, other):
     """Compare NessusReportItem with == operator
        :return: Return true if NessusReportItem has not changed
        :rtype: Boolean
        :raises: TypeError
     """
     try:
         self.iscomparable(other)
     except TypeError as etyperr:
         raise etyperr
     diff = DictDiffer(self.get_vuln_info, other.get_vuln_info)
     return (len(diff.added()) == 0 and len(diff.removed()) == 0
             and len(diff.changed()) == 0)
示例#3
0
 def diff(self, other):
     '''
     Description: diff object and provide the differences
     :param other: obj to compare to
     :type other: NessusReport
     :return: a dict of all the differences
     :rtype: dict
     '''
     diff = DictDiffer(self.__get_dict(), other.__get_dict())
     rdict = {}
     rdict["removed"] = diff.removed()
     rdict["changed"] = diff.changed()
     rdict["added"] = diff.added()
     rdict["unchanged"] = diff.unchanged()
     return rdict
    def __ne__(self, other):
        """Compare NessusReportItem with != operator
           :return: Return true if NessusReportItem has changed
           :rtype: Boolean
           :raises: TypeError
        """
        try:
            self.iscomparable(other)
        except TypeError as etyperr:
            raise etyperr

        diff = DictDiffer(self.get_vuln_info, other.get_vuln_info)
        return (
            len(diff.unchanged()) != len(self.get_vuln_info)
            )
 def __eq__(self, other):
     """Compare NessusReportItem with == operator
        :return: Return true if NessusReportItem has not changed
        :rtype: Boolean
        :raises: TypeError
     """
     try:
         self.iscomparable(other)
     except TypeError as etyperr:
         raise etyperr
     diff = DictDiffer(self.get_vuln_info, other.get_vuln_info)
     return (
         len(diff.added()) == 0
         and len(diff.removed()) == 0
         and len(diff.changed()) == 0
         )
class TestDictDiffer(TestCase):
    def setUp(self):
        a = {'a': 1, 'b': 1, 'c': 0}
        b = {'a': 1, 'b': 2, 'd': 0}
        self.d = DictDiffer(b, a)

    def test_added(self):
        self.assertEqual(self.d.added(), set(['d']))

    def test_removed(self):
        self.assertEqual(self.d.removed(), set(['c']))

    def test_changed(self):
        self.assertEqual(self.d.changed(), set(['b']))

    def test_unchanged(self):
        self.assertEqual(self.d.unchanged(), set(['a']))
示例#7
0
class TestDictDiffer(TestCase):
    def setUp(self):
        a = {'a': 1, 'b': 1, 'c': 0}
        b = {'a': 1, 'b': 2, 'd': 0}
        self.d = DictDiffer(b, a)

    def test_added(self):
        self.assertEqual(self.d.added(), set(['d']))

    def test_removed(self):
        self.assertEqual(self.d.removed(), set(['c']))

    def test_changed(self):
        self.assertEqual(self.d.changed(), set(['b']))

    def test_unchanged(self):
        self.assertEqual(self.d.unchanged(), set(['a']))
 def diff(self, other):
     '''
     Description: Compare two NessusReportItem
     :param other: NessusReportItem
     :type other: NessusReportItem
     :return: a dict of set containing 4 keys unchanged, added,
     removed, changed. these set are the list of the keys in the
     get_vuln_info property that have changed
     :rtype: dict
     :raises: TypeError
     '''
     try:
         self.iscomparable(other)
     except TypeError as etyperr:
         raise etyperr
     diff = DictDiffer(self.get_vuln_info, other.get_vuln_info)
     rdict = {}
     rdict["removed"] = diff.removed()
     rdict["changed"] = diff.changed()
     rdict["added"] = diff.added()
     rdict["unchanged"] = diff.unchanged()
     return rdict
示例#9
0
 def diff(self, other):
     '''
     Description: diff object and provide the differences
     :param other: obj to compare to
     :type other: NessusReport
     :return: a dict of all the differences
     :rtype: dict
     '''
     diff = DictDiffer(self.__get_dict(), other.__get_dict())
     rdict = {}
     rdict["removed"] = diff.removed()
     rdict["changed"] = diff.changed()
     rdict["added"] = diff.added()
     rdict["unchanged"] = diff.unchanged()
     return rdict
示例#10
0
 def diff(self, other):
     '''
     Description: compute a diff dict obj
     :param other: the object to compare
     :type other: NessusReportHost
     :return:
     :rtype: dict
     '''
     diff = DictDiffer(self.__get_dict(), other.__get_dict())
     rdict = {}
     rdict["removed"] = diff.removed()
     rdict["changed"] = diff.changed()
     rdict["added"] = diff.added()
     rdict["unchanged"] = diff.unchanged()
     return rdict
示例#11
0
 def diff(self, other):
     """
     Description: Compare two NessusReportItem
     :param other: NessusReportItem
     :type other: NessusReportItem
     :return: a dict of set containing 4 keys unchanged, added,
     removed, changed. these set are the list of the keys in the
     get_vuln_info property that have changed
     :rtype: dict
     :raises: TypeError
     """
     try:
         self.iscomparable(other)
     except TypeError as etyperr:
         raise etyperr
     diff = DictDiffer(self.get_vuln_info, other.get_vuln_info)
     rdict = {}
     rdict["removed"] = diff.removed()
     rdict["changed"] = diff.changed()
     rdict["added"] = diff.added()
     rdict["unchanged"] = diff.unchanged()
     return rdict
 def setUp(self):
     a = {'a': 1, 'b': 1, 'c': 0}
     b = {'a': 1, 'b': 2, 'd': 0}
     self.d = DictDiffer(b, a)
示例#13
0
 def setUp(self):
     a = {'a': 1, 'b': 1, 'c': 0}
     b = {'a': 1, 'b': 2, 'd': 0}
     self.d = DictDiffer(b, a)