mirror of https://github.com/caronc/apprise
added exception handling for (dbus://) SessionBus
parent
5dbdf411c1
commit
5ee9065b5b
|
@ -54,6 +54,7 @@ try:
|
|||
from dbus import Interface
|
||||
from dbus import Byte
|
||||
from dbus import ByteArray
|
||||
from dbus import DBusException
|
||||
|
||||
#
|
||||
# now we try to determine which mainloop(s) we can access
|
||||
|
@ -249,7 +250,20 @@ class NotifyDBus(NotifyBase):
|
|||
return False
|
||||
|
||||
# Acquire our session
|
||||
session = SessionBus(mainloop=MAINLOOP_MAP[self.schema])
|
||||
try:
|
||||
session = SessionBus(mainloop=MAINLOOP_MAP[self.schema])
|
||||
|
||||
except DBusException:
|
||||
# Handle exception
|
||||
self.logger.warning('Failed to send DBus notification.')
|
||||
self.logger.exception('DBus Exception')
|
||||
return False
|
||||
|
||||
# If there is no title, but there is a body, swap the two to get rid
|
||||
# of the weird whitespace
|
||||
if not title:
|
||||
title = body
|
||||
body = ''
|
||||
|
||||
# acquire our dbus object
|
||||
dbus_obj = session.get_object(
|
||||
|
|
|
@ -50,6 +50,8 @@ if 'dbus' not in sys.modules:
|
|||
# Environment doesn't allow for dbus
|
||||
pytest.skip("Skipping dbus-python based tests", allow_module_level=True)
|
||||
|
||||
from dbus import DBusException # noqa E402
|
||||
|
||||
|
||||
@mock.patch('dbus.SessionBus')
|
||||
@mock.patch('dbus.Interface')
|
||||
|
@ -344,6 +346,15 @@ def test_dbus_plugin(mock_mainloop, mock_byte, mock_bytearray,
|
|||
# Verify this all works in the event a ValueError is also thronw
|
||||
# out of the call to gi.require_version()
|
||||
|
||||
mock_sessionbus.side_effect = DBusException('test')
|
||||
# Handle Dbus Session Initialization error
|
||||
assert obj.notify(
|
||||
title='title', body='body',
|
||||
notify_type=apprise.NotifyType.INFO) is False
|
||||
|
||||
# Return side effect to normal
|
||||
mock_sessionbus.side_effect = None
|
||||
|
||||
# Emulate require_version function:
|
||||
gi.require_version.side_effect = ValueError()
|
||||
|
||||
|
|
Loading…
Reference in New Issue