2009-07-02 04:16:37 +00:00
|
|
|
from twisted.trial import unittest
|
|
|
|
|
|
|
|
import common
|
|
|
|
|
|
|
|
from deluge.core.alertmanager import AlertManager
|
|
|
|
from deluge.core.core import Core
|
2010-03-25 18:47:05 +00:00
|
|
|
import deluge.component as component
|
2009-07-02 04:16:37 +00:00
|
|
|
|
|
|
|
class AlertManagerTestCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.core = Core()
|
|
|
|
|
2010-03-25 18:47:05 +00:00
|
|
|
self.am = component.get("AlertManager")
|
|
|
|
component.start(["AlertManager"])
|
2009-07-02 04:16:37 +00:00
|
|
|
|
2010-03-25 18:47:05 +00:00
|
|
|
def tearDown(self):
|
|
|
|
def on_shutdown(result):
|
|
|
|
component._ComponentRegistry.components = {}
|
|
|
|
del self.am
|
|
|
|
del self.core
|
|
|
|
|
|
|
|
return component.shutdown().addCallback(on_shutdown)
|
|
|
|
|
2009-07-02 04:16:37 +00:00
|
|
|
def test_register_handler(self):
|
|
|
|
def handler(alert):
|
|
|
|
return
|
|
|
|
|
|
|
|
self.am.register_handler("dummy_alert", handler)
|
|
|
|
|
|
|
|
self.assertEquals(self.am.handlers["dummy_alert"], [handler])
|
|
|
|
|
|
|
|
def test_deregister_handler(self):
|
|
|
|
def handler(alert):
|
|
|
|
return
|
|
|
|
|
|
|
|
self.am.register_handler("dummy_alert", handler)
|
|
|
|
self.am.deregister_handler(handler)
|
|
|
|
self.assertEquals(self.am.handlers["dummy_alert"], [])
|