syncevolution/test/notification-daemon.py
Patrick Ohly 430de7a7ed testing: verify that auto sync triggers notifications
This is tested as part of the existing auto sync test which produces
notifications. It would be nice to monitor the method calls via
Python, but it doesn't seem to be possible to watch method calls. So
instead we check the dbus-monitor output after the test has completed.

What makes this a bit harder is that depending on how test-dbus.py is
started, there may or may not be a real notification daemon
running. If there is, then the notifications triggered by testing will
show up on the tester's desktop. If there is not, then
syncevo-dbus-daemon will not send the expected notifications.

To ensure that testing of notifications still works in the nightly testing
where X is not running and thus GNOME notification daemon doesn't work,
a fake implementation of the org.freedesktop.notifications API is
provided and started as part of the test-dbus.py script in a forked
process.

The stand-alone version of the fake notification daemon is also available,
but would be harder to start (PATH must be set, etc.), so it is not used.
2011-08-24 18:42:14 +02:00

51 lines
2 KiB
Python
Executable file

#! /usr/bin/python -u
#
# Copyright (C) 2009 Intel Corporation
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) version 3.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import dbus.service
import gobject
import random
class Notifications (dbus.service.Object):
'''fake org.freedesktop.Notifications implementation,'''
'''used when there is none already registered on the session bus'''
@dbus.service.method(dbus_interface='org.freedesktop.Notifications', in_signature='', out_signature='ssss')
def GetServerInformation(self):
return ('test-dbus', 'SyncEvolution', '0.1', '1.1')
@dbus.service.method(dbus_interface='org.freedesktop.Notifications', in_signature='', out_signature='as')
def GetCapabilities(self):
return ['actions', 'body', 'body-hyperlinks', 'body-markup', 'icon-static', 'sound']
@dbus.service.method(dbus_interface='org.freedesktop.Notifications', in_signature='susssasa{sv}i', out_signature='u')
def Notify(self, app, replaces, icon, summary, body, actions, hints, expire):
return random.randint(1,100)
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
loop = gobject.MainLoop()
name = dbus.service.BusName("org.freedesktop.Notifications", bus)
# start dummy notification daemon, if possible;
# if it fails, ignore (probably already one running)
notifications = Notifications(bus, "/org/freedesktop/Notifications")
loop.run()