1
# tests.platform.event_logging.test_linux
3
# Author: Alejandro J. Cura <alecu@canonical.com>
5
# Copyright 2010-2012 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
# In addition, as a special exception, the copyright holders give
20
# permission to link the code of portions of this program with the
21
# OpenSSL library under certain conditions as described in each
22
# individual source file, and distribute linked combinations
24
# You must obey the GNU General Public License in all respects
25
# for all of the code used other than OpenSSL. If you modify
26
# file(s) with this exception, you may extend this exception to your
27
# version of the file(s), but you are not obligated to do so. If you
28
# do not wish to do so, delete this exception statement from your
29
# version. If you delete this exception statement from all source
30
# files in the program, then also delete it here.
31
"""Test the event logging on linux."""
35
from twisted.trial.unittest import TestCase
37
import ubuntuone.platform.event_logging.linux as event_logging
40
class ZeitgeistDetectionTestCase(TestCase):
41
"""Test the is_zeitgeist_installed function."""
43
def patch_module(self, module_name, fake_module):
44
"""Monkey patch a module for the duration of the test."""
46
real_module = sys.modules.get(module_name, UNDEFINED)
49
"""Restore the real_module."""
50
if real_module is UNDEFINED:
51
del(sys.modules[module_name])
53
sys.modules[module_name] = real_module
55
self.addCleanup(restore)
56
sys.modules[module_name] = fake_module
58
def test_zg_installed_returns_true(self):
59
"""When zg is installed, it returns true."""
60
self.patch_module("zeitgeist", object())
61
self.patch_module("zeitgeist.mimetypes", object())
62
result = event_logging.is_zeitgeist_installed()
63
self.assertEqual(result, True)
65
def test_zg_not_installed_returns_false(self):
66
"""When zg is not installed, it returns false."""
67
self.patch_module("zeitgeist", None)
68
result = event_logging.is_zeitgeist_installed()
69
self.assertEqual(result, False)
71
def test_old_zg_installed_returns_false(self):
72
"""When an old zg is installed, it returns false."""
73
self.patch_module("zeitgeist", object())
74
self.patch_module("zeitgeist.mimetypes", None)
75
result = event_logging.is_zeitgeist_installed()
76
self.assertEqual(result, False)
79
class GetListenerTestCase(TestCase):
80
"""The zg listener is created."""
82
def test_zeitgeist_installed_returns_listener(self):
83
"""get_listener returns a listener if ZG installed."""
84
self.patch(event_logging, "is_zeitgeist_installed", lambda: True)
85
listener = event_logging.get_listener(None, None)
86
self.assertNotEqual(listener, None)
88
def test_zeitgeist_not_installed_returns_none(self):
89
"""get_listener returns None if ZG not installed."""
90
self.patch(event_logging, "is_zeitgeist_installed", lambda: False)
91
listener = event_logging.get_listener(None, None)
92
self.assertEqual(listener, None)