1
# tests.platform.linux.test_messaging
3
# Author: Eric Casteleijn <eric.casteleijn@canonical.com>
5
# Copyright 2010 Canonical Ltd.
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.
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.
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/>.
19
"""Test the messaging on linux. These tests are kind of stupid, but at
20
least they ensure 100% coverage and hence no silly/syntax errors.
25
from mocker import Mocker
26
from twisted.trial.unittest import TestCase
28
from ubuntuone.platform.linux.messaging import Messaging, hide_message
37
def callback(indicator, message_time=None):
42
class MessagingTestCase(TestCase):
43
"""Test the Messaging API."""
46
self.mocker = Mocker()
52
# pylint: disable=R0913
53
def _show_message_setup(self, message_time=None, message_count=None,
54
icon=None, update_count=None, hide=False):
55
"""Set up the mocker expectations for show_method."""
56
indicate = self.mocker.replace("indicate")
57
mock_server = self.mocker.mock()
58
indicate.indicate_server_ref_default()
59
self.mocker.result(mock_server)
60
mock_server.set_type("message.u1")
61
mock_server.set_desktop_file(
62
"/usr/share/applications/ubuntuone-control-panel-gtk.desktop")
63
mock_indicator = self.mocker.mock()
65
self.mocker.result(mock_indicator)
66
mock_indicator.set_property("subtype", "u1")
67
mock_indicator.set_property("name", FAKE_SENDER)
68
mock_indicator.set_property("sender", FAKE_SENDER)
69
mock_indicator.connect("user-display", callback)
71
mock_indicator.set_property_icon("icon", icon)
72
if message_count is not None:
73
mock_indicator.set_property("count", str(message_count))
75
if message_time is None:
76
mock_time = self.mocker.replace("time.time")
78
self.mocker.result(FAKE_TIME2)
79
mock_indicator.set_property_time("time", FAKE_TIME2)
81
mock_indicator.set_property_time("time", message_time)
82
mock_indicator.set_property("draw-attention", "true")
85
mock_indicator.get_property("count")
86
self.mocker.result("1200")
87
mock_indicator.set_property("count", '2500')
89
mock_indicator.set_property('draw-attention', 'false')
93
# pylint: enable=R0913
95
def test_show_message(self):
96
"""On message, libnotify receives the proper calls."""
97
self._show_message_setup()
98
messaging = Messaging()
99
messaging.show_message(FAKE_SENDER, callback)
101
def test_show_message_with_time(self):
102
"""On message with time, libnotify receives the proper calls."""
103
self._show_message_setup(FAKE_TIME)
104
messaging = Messaging()
105
messaging.show_message(FAKE_SENDER, callback, message_time=FAKE_TIME)
107
def test_show_message_with_icon(self):
108
"""On message with icon, libnotify receives the proper calls."""
109
self._show_message_setup(icon=FAKE_ICON)
110
messaging = Messaging()
111
messaging.show_message(FAKE_SENDER, callback, icon=FAKE_ICON)
113
def test_show_message_with_count(self):
114
"""On message with count, libnotify receives the proper calls."""
115
self._show_message_setup(message_count='1200')
116
messaging = Messaging()
117
messaging.show_message(FAKE_SENDER, callback, message_count=1200)
119
def test_update_count(self):
120
"""On message count update, libnotify receives the proper calls."""
121
self._show_message_setup(message_count='1200', update_count='1300')
122
messaging = Messaging()
123
indicator = messaging.show_message(
124
FAKE_SENDER, callback, message_count=1200)
125
messaging.update_count(indicator, 1300)
127
def test_hide_message(self):
128
"""On message hide, libnotify receives the proper calls."""
129
self._show_message_setup(hide=True)
130
messaging = Messaging()
131
mock_indicator = messaging.show_message(FAKE_SENDER, callback)
132
hide_message(mock_indicator)