48 lines
1.4 KiB
Python
Executable File
48 lines
1.4 KiB
Python
Executable File
import unittest
|
|
import config
|
|
|
|
class TestAlertWithDependencies(unittest.TestCase) :
|
|
def test_base(self) :
|
|
self.alertToAlertWithDependencies = {}
|
|
self.alert_list = []
|
|
self.make_alert("A", ["C"])
|
|
self.make_alert("B", ["C"])
|
|
self.make_alert("C", ["D"])
|
|
self.make_alert("D", None)
|
|
self.validate()
|
|
self.checkDepLen("A", 2)
|
|
self.checkDepLen("B", 2)
|
|
self.checkDepLen("C", 1)
|
|
self.checkDepLen("D", 0)
|
|
|
|
def make_alert(self, id, depends) :
|
|
alert = {
|
|
'id': id,
|
|
'dependencies': depends
|
|
}
|
|
alertWithDependencies = config.AlertWithDependencies(alert['id'], alert[config.DEPENDENCIES_KEY] if config.DEPENDENCIES_KEY in alert else None)
|
|
self.alertToAlertWithDependencies[alert['id']] = alertWithDependencies
|
|
alert['resolvedDependencies'] = alertWithDependencies
|
|
self.alert_list.append(alert)
|
|
|
|
def validate(self) :
|
|
for id, awd in self.alertToAlertWithDependencies.items() :
|
|
config.validateDependencies(id, awd, self.alertToAlertWithDependencies, MockLogger())
|
|
|
|
def checkDepLen(self, id, n) :
|
|
dep = self.alertToAlertWithDependencies[id]
|
|
self.assertEqual(len(dep.getDependencies()), n)
|
|
|
|
class MockLogger() :
|
|
def __init__(self) :
|
|
return
|
|
def info(self, *args, **kwargs) :
|
|
return
|
|
def debug(self, *args, **kwargs) :
|
|
return
|
|
def error(self, *args, **kwargs) :
|
|
return
|
|
|
|
if __name__ == "__main__" :
|
|
unittest.main()
|