~dobey/ubuntuone-client/py-only

« back to all changes in this revision

Viewing changes to tests/platform/event_logging/test_linux.py

  • Committer: Tarmac
  • Author(s): Rodney Dawes
  • Date: 2013-02-04 22:10:27 UTC
  • mfrom: (1383.1.1 rm-zeitgeist)
  • Revision ID: tarmac-20130204221027-t8viho77hp60n5a9
Remove usage of zg to reduce complexity, as we aren't using the feature.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# tests.platform.event_logging.test_linux
2
 
#
3
 
# Author: Alejandro J. Cura <alecu@canonical.com>
4
 
#
5
 
# Copyright 2010-2012 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
 
# 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
23
 
# including the two.
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."""
32
 
 
33
 
import sys
34
 
 
35
 
from twisted.trial.unittest import TestCase
36
 
 
37
 
import ubuntuone.platform.event_logging.linux as event_logging
38
 
 
39
 
 
40
 
class ZeitgeistDetectionTestCase(TestCase):
41
 
    """Test the is_zeitgeist_installed function."""
42
 
 
43
 
    def patch_module(self, module_name, fake_module):
44
 
        """Monkey patch a module for the duration of the test."""
45
 
        UNDEFINED = object()
46
 
        real_module = sys.modules.get(module_name, UNDEFINED)
47
 
 
48
 
        def restore():
49
 
            """Restore the real_module."""
50
 
            if real_module is UNDEFINED:
51
 
                del(sys.modules[module_name])
52
 
            else:
53
 
                sys.modules[module_name] = real_module
54
 
 
55
 
        self.addCleanup(restore)
56
 
        sys.modules[module_name] = fake_module
57
 
 
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)
64
 
 
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)
70
 
 
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)
77
 
 
78
 
 
79
 
class GetListenerTestCase(TestCase):
80
 
    """The zg listener is created."""
81
 
 
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)
87
 
 
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)