17
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
"""Test the event logging on linux."""
20
22
from twisted.trial.unittest import TestCase
22
24
from ubuntuone.platform.linux import event_logging
27
class ZeitgeistDetectionTestCase(TestCase):
28
"""Test the is_zeitgeist_installed function."""
30
def patch_module(self, module_name, fake_module):
31
"""Monkey patch a module for the duration of the test."""
33
real_module = sys.modules.get(module_name, UNDEFINED)
36
"""Restore the real_module."""
37
if real_module is UNDEFINED:
38
del(sys.modules[module_name])
40
sys.modules[module_name] = real_module
42
self.addCleanup(restore)
43
sys.modules[module_name] = fake_module
45
def test_zg_installed_returns_true(self):
46
"""When zg is installed, it returns true."""
47
self.patch_module("zeitgeist", object())
48
self.patch_module("zeitgeist.mimetypes", object())
49
result = event_logging.is_zeitgeist_installed()
50
self.assertEqual(result, True)
52
def test_zg_not_installed_returns_false(self):
53
"""When zg is not installed, it returns false."""
54
self.patch_module("zeitgeist", None)
55
result = event_logging.is_zeitgeist_installed()
56
self.assertEqual(result, False)
58
def test_old_zg_installed_returns_false(self):
59
"""When an old zg is installed, it returns false."""
60
self.patch_module("zeitgeist", object())
61
self.patch_module("zeitgeist.mimetypes", None)
62
result = event_logging.is_zeitgeist_installed()
63
self.assertEqual(result, False)
25
66
class GetListenerTestCase(TestCase):
26
67
"""The zg listener is created."""