~mikemc/ubuntuone-client/cleanup-platform-constants

« back to all changes in this revision

Viewing changes to tests/platform/windows/test_tools.py

  • Committer: Tarmac
  • Author(s): Diego Sarmentero
  • Date: 2012-04-18 23:44:49 UTC
  • mfrom: (1222.2.6 ubuntuone-client-qq)
  • Revision ID: tarmac-20120418234449-3p8blwdo3twzmokc
- Avoid creating SyncDaemonTool if is not already running and the user wants to close it. (LP: #907479).

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
"""Tests for some tools for talking to the syncdaemon."""
30
30
 
31
31
import sys
 
32
import operator
32
33
 
33
34
from twisted.internet import defer
34
35
from twisted.trial.unittest import TestCase
50
51
        yield super(TestSyncDaemonTool, self).setUp()
51
52
        self.patch(windows.UbuntuOneClient, "connect", lambda _: defer.Deferred())
52
53
        self.sdtool = windows.SyncDaemonToolProxy()
 
54
        self.calls = {}
53
55
 
54
56
    def test_call_after_connection(self):
55
57
        """Test the _call_after_connection method."""
61
63
        self.sdtool.connected.callback("got connected!")
62
64
        self.assertEqual(len(collected_calls), 1)
63
65
 
 
66
    def test_call_after_connection_connect(self):
 
67
        """Test execute connect in _call_after_connection method."""
 
68
        self.patch(self.sdtool.client, "is_connected", lambda: False)
 
69
        my_connect = lambda *args, **kwargs: operator.setitem(
 
70
                self.calls, "connect", (args, kwargs))
 
71
        self.patch(self.sdtool.client, "connect", my_connect)
 
72
        collected_calls = []
 
73
        test_method = lambda *args: collected_calls.append(args)
 
74
        test_method = self.sdtool._call_after_connection(test_method)
 
75
        test_method(123)
 
76
        self.assertIn("connect", self.calls)
 
77
        self.assertEqual(self.calls["connect"], ((), {}))
 
78
 
 
79
    def test_call_after_connection_not_connect(self):
 
80
        """Test execute connect in _call_after_connection method."""
 
81
        self.patch(self.sdtool.client, "is_connected", lambda: True)
 
82
        my_connect = lambda *args, **kwargs: operator.setitem(
 
83
                self.calls, "connect", (args, kwargs))
 
84
        self.patch(self.sdtool.client, "connect", my_connect)
 
85
        collected_calls = []
 
86
        test_method = lambda *args: collected_calls.append(args)
 
87
        test_method = self.sdtool._call_after_connection(test_method)
 
88
        test_method(123)
 
89
        self.assertNotIn("connect", self.calls)
 
90
 
64
91
    def test_should_wrap(self):
65
92
        """Only some attributes should be wrapped."""
66
93
        test_function = "sample_function"