~didrocks/ubuntuone-client/use_result_var

« back to all changes in this revision

Viewing changes to tests/platform/linux/test_event_logging.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-02-11 16:18:11 UTC
  • mto: This revision was merged to the branch mainline in revision 67.
  • Revision ID: james.westby@ubuntu.com-20110211161811-n18dj9lde7dxqjzr
Tags: upstream-1.5.4
ImportĀ upstreamĀ versionĀ 1.5.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# with this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
"""Test the event logging on linux."""
19
19
 
 
20
import sys
 
21
 
20
22
from twisted.trial.unittest import TestCase
21
23
 
22
24
from ubuntuone.platform.linux import event_logging
23
25
 
24
26
 
 
27
class ZeitgeistDetectionTestCase(TestCase):
 
28
    """Test the is_zeitgeist_installed function."""
 
29
 
 
30
    def patch_module(self, module_name, fake_module):
 
31
        """Monkey patch a module for the duration of the test."""
 
32
        UNDEFINED = object()
 
33
        real_module = sys.modules.get(module_name, UNDEFINED)
 
34
 
 
35
        def restore():
 
36
            """Restore the real_module."""
 
37
            if real_module is UNDEFINED:
 
38
                del(sys.modules[module_name])
 
39
            else:
 
40
                sys.modules[module_name] = real_module
 
41
 
 
42
        self.addCleanup(restore)
 
43
        sys.modules[module_name] = fake_module
 
44
 
 
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)
 
51
 
 
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)
 
57
 
 
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)
 
64
 
 
65
 
25
66
class GetListenerTestCase(TestCase):
26
67
    """The zg listener is created."""
27
68