1
# -*- coding: utf-8 -*-
3
# Authors: Alejandro J. Cura <alecu@canonical.com>
4
# Natalia B. Bidart <nataliabidart@canonical.com>
5
# Eric Casteleijn <eric.casteleijn@canonical.com>
7
# Copyright 2011 Canonical Ltd.
9
# This program is free software: you can redistribute it and/or modify it
10
# under the terms of the GNU General Public License version 3, as published
11
# by the Free Software Foundation.
13
# This program is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranties of
15
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16
# PURPOSE. See the GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License along
19
# with this program. If not, see <http://www.gnu.org/licenses/>.
21
"""Tests for the control panel backend DBus service."""
26
from dbus.mainloop.glib import DBusGMainLoop
27
from twisted.internet import defer
29
from ubuntuone.controlpanel.gui.gtk import gui
30
from ubuntuone.devtools.testcases.dbus import DBusTestCase
31
from twisted.trial.unittest import TestCase
34
class MockWindow(object):
39
def __init__(self, switch_to=None, alert=False):
42
def draw_attention(self):
43
"""Draw attention to the control panel."""
44
self.called.append('draw_attention')
46
def switch_to(self, panel):
47
"""Switch to named panel."""
48
self.called.append(('switch_to', panel))
51
class DBusServiceMockTestCase(TestCase):
52
"""Tests for the main function."""
54
@defer.inlineCallbacks
56
yield super(DBusServiceMockTestCase, self).setUp()
57
self.mocker = mocker.Mocker()
59
@defer.inlineCallbacks
61
yield super(DBusServiceMockTestCase, self).tearDown()
65
def test_dbus_service_main(self):
66
"""The main method starts the loop and hooks up to DBus."""
67
self.patch(gui, 'ControlPanelWindow', MockWindow)
68
dbus_gmain_loop = self.mocker.replace(
69
"dbus.mainloop.glib.DBusGMainLoop")
70
register_service = self.mocker.replace(
71
"ubuntuone.controlpanel.gui.gtk.gui.register_service")
72
publish_service = self.mocker.replace(
73
"ubuntuone.controlpanel.gui.gtk.gui.publish_service")
74
main = self.mocker.replace("gtk.main")
75
dbus_gmain_loop(set_as_default=True)
76
loop = self.mocker.mock()
77
self.mocker.result(loop)
78
register_service(mocker.ANY)
79
self.mocker.result(True)
80
publish_service(switch_to='', alert=False)
86
class DBusServiceTestCase(DBusTestCase):
87
"""Test for the DBus service."""
89
def _set_called(self, *args, **kwargs):
90
"""Keep track of function calls, useful for monkeypatching."""
91
self._called = (args, kwargs)
93
@defer.inlineCallbacks
95
"""Initialize each test run."""
96
yield super(DBusServiceTestCase, self).setUp()
97
DBusGMainLoop(set_as_default=True)
100
def test_register_service(self):
101
"""The DBus service is successfully registered."""
102
bus = dbus.SessionBus()
103
ret = gui.register_service(bus)