~dobey/ubuntuone-control-panel/remove-gtk

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/dbustests/test_gui_service.py

  • Committer: Rodney Dawes
  • Date: 2012-02-29 19:49:44 UTC
  • Revision ID: rodney.dawes@canonical.com-20120229194944-gmbmwfmccjp3g7o3
Remove the GTK+ 2.x control panel

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
 
3
 
# Authors: Alejandro J. Cura <alecu@canonical.com>
4
 
#          Natalia B. Bidart <nataliabidart@canonical.com>
5
 
#          Eric Casteleijn <eric.casteleijn@canonical.com>
6
 
#
7
 
# Copyright 2011 Canonical Ltd.
8
 
#
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.
12
 
#
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.
17
 
#
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/>.
20
 
 
21
 
"""Tests for the control panel backend DBus service."""
22
 
 
23
 
import dbus
24
 
import mocker
25
 
 
26
 
from dbus.mainloop.glib import DBusGMainLoop
27
 
from twisted.internet import defer
28
 
 
29
 
from ubuntuone.controlpanel.gui.gtk import gui
30
 
from ubuntuone.devtools.testcases.dbus import DBusTestCase
31
 
from twisted.trial.unittest import TestCase
32
 
 
33
 
 
34
 
class MockWindow(object):
35
 
    """A mock backend."""
36
 
 
37
 
    exception = None
38
 
 
39
 
    def __init__(self, switch_to=None, alert=False):
40
 
        self.called = []
41
 
 
42
 
    def draw_attention(self):
43
 
        """Draw attention to the control panel."""
44
 
        self.called.append('draw_attention')
45
 
 
46
 
    def switch_to(self, panel):
47
 
        """Switch to named panel."""
48
 
        self.called.append(('switch_to', panel))
49
 
 
50
 
 
51
 
class DBusServiceMockTestCase(TestCase):
52
 
    """Tests for the main function."""
53
 
 
54
 
    @defer.inlineCallbacks
55
 
    def setUp(self):
56
 
        yield super(DBusServiceMockTestCase, self).setUp()
57
 
        self.mocker = mocker.Mocker()
58
 
 
59
 
    @defer.inlineCallbacks
60
 
    def tearDown(self):
61
 
        yield super(DBusServiceMockTestCase, self).tearDown()
62
 
        self.mocker.restore()
63
 
        self.mocker.verify()
64
 
 
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)
81
 
        main()
82
 
        self.mocker.replay()
83
 
        gui.main()
84
 
 
85
 
 
86
 
class DBusServiceTestCase(DBusTestCase):
87
 
    """Test for the DBus service."""
88
 
 
89
 
    def _set_called(self, *args, **kwargs):
90
 
        """Keep track of function calls, useful for monkeypatching."""
91
 
        self._called = (args, kwargs)
92
 
 
93
 
    @defer.inlineCallbacks
94
 
    def setUp(self):
95
 
        """Initialize each test run."""
96
 
        yield super(DBusServiceTestCase, self).setUp()
97
 
        DBusGMainLoop(set_as_default=True)
98
 
        self._called = False
99
 
 
100
 
    def test_register_service(self):
101
 
        """The DBus service is successfully registered."""
102
 
        bus = dbus.SessionBus()
103
 
        ret = gui.register_service(bus)
104
 
        self.assertTrue(ret)