~ralsina/ubuntuone-control-panel/fix-scroll

« back to all changes in this revision

Viewing changes to ubuntuone/control_panel/tests/test_gui.py

  • Committer: natalia.bidart at canonical
  • Date: 2010-09-15 21:43:48 UTC
  • Revision ID: natalia.bidart@canonical.com-20100915214348-qd7vpoj85z0jhx0m
Initial directory structure for new project.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
 
4
#
 
5
# Copyright 2010 Canonical Ltd.
 
6
#
 
7
# This program is free software: you can redistribute it and/or modify it
 
8
# under the terms of the GNU General Public License version 3, as published
 
9
# by the Free Software Foundation.
 
10
#
 
11
# This program is distributed in the hope that it will be useful, but
 
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
14
# PURPOSE.  See the GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License along
 
17
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
"""The test suite for the control panel user interface."""
 
20
 
 
21
import gtk
 
22
 
 
23
from twisted.trial.unittest import TestCase
 
24
 
 
25
from ubuntuone.control_panel import gui, utils
 
26
 
 
27
 
 
28
class FakedBuilder(object):
 
29
    """A faked builder."""
 
30
 
 
31
    def __init__(self):
 
32
        self.add_from_file = lambda fname: setattr(self, 'filename', fname)
 
33
        self.connect_signals = lambda arg: setattr(self, 'signals', arg)
 
34
        self.get_objects = lambda: []
 
35
 
 
36
 
 
37
class BasicControlPanelUITestCase(TestCase):
 
38
    """The basic test suite for the control panel user interface."""
 
39
 
 
40
    def setUp(self):
 
41
        self._called = False
 
42
 
 
43
    def _set_called(self, *args, **kwargs):
 
44
        """Store 'args' and 'kwargs' for test assertions."""
 
45
        self._called = (args, kwargs)
 
46
 
 
47
    def test_ui_can_be_created(self):
 
48
        """UI main class exists and can be created."""
 
49
        ui = gui.ControlPanelUI()
 
50
        self.assertTrue(ui is not None)
 
51
 
 
52
    def test_main_start_gtk_main_loop(self):
 
53
        """The GTK main loop is started when calling main()."""
 
54
        ui = gui.ControlPanelUI()
 
55
        self.patch(gtk, 'main', self._set_called)
 
56
        ui.main()
 
57
        self.assertEqual(self._called, ((), {}), 'gtk.main was called.')
 
58
 
 
59
    def test_ui_file_is_read_at_startup(self):
 
60
        """The ui file is read and parse at startup."""
 
61
        self.patch(gtk, 'Builder', FakedBuilder)
 
62
        ui = gui.ControlPanelUI()
 
63
        self.assertEqual(ui.builder.filename, utils.get_data_file('main.ui'))
 
64
 
 
65
    def test_signals_are_connected_at_startup(self):
 
66
        """The signals are connectedt at startup."""
 
67
        self.patch(gtk, 'Builder', FakedBuilder)
 
68
        ui = gui.ControlPanelUI()
 
69
        self.assertEqual(ui.builder.signals, ui.builder)