~diegosarmentero/ubuntuone-client/udf-issue

« back to all changes in this revision

Viewing changes to tests/platform/test_u1sdtool.py

- Provide a get_home_dir() method to get a proper home dir in unicode environments (LP: #898640).
- Handle link creation with unicode paths (LP: #891173).

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    FakeDownload,
29
29
    FakeUpload,
30
30
)
 
31
from ubuntuone.syncdaemon.vm_helper import get_udf_path
31
32
from ubuntuone.syncdaemon.volume_manager import (
32
33
    ACCESS_LEVEL_RO,
33
34
    Share,
58
59
        out = StringIO()
59
60
        d = self.tool.get_shares()
60
61
        d.addCallback(lambda result: show_shares(result, out))
 
62
 
61
63
        def check(result):
62
64
            """check the output"""
63
65
            self.assertEqual('No shares\n', out.getvalue())
86
88
        out = StringIO()
87
89
        d = self.tool.list_shared()
88
90
        d.addCallback(lambda result: show_shared(result, out))
 
91
 
89
92
        def check(result):
90
93
            """check the output"""
91
94
            self.assertEqual('No shared\n', out.getvalue())
98
101
        self.fs.create(path, "")
99
102
        self.fs.set_node_id(path, "node_id")
100
103
        # helper function, pylint: disable-msg=C0111
 
104
 
101
105
        def fake_create_share(node_id, user, name, access_level, marker, path):
102
106
            self.main.vm.handle_AQ_CREATE_SHARE_OK(share_id='share_id',
103
107
                                              marker=marker)
110
114
                "path=%s\n" % path.decode('utf-8')
111
115
        d = self.tool.list_shared()
112
116
        d.addCallback(lambda result: show_shared(result, out))
 
117
 
113
118
        def check(result):
114
119
            """check the output"""
115
120
            self.assertEqual(out.getvalue(), expected)
166
171
  stat: %(stat)s
167
172
"""
168
173
        # the callback, pylint: disable-msg=C0111
 
174
 
169
175
        def callback(result):
170
176
            if encoding is not None:
171
177
                result.update(dict(path_info=path))
176
182
            value = expected % result
177
183
            self.assertEqual(out.getvalue(), value)
178
184
        # helper callback, pylint: disable-msg=C0111
 
185
 
179
186
        def show(result):
180
187
            show_path_info(result, path, out)
181
188
            return result
191
198
        d.addCallback(lambda _: self.tool.get_current_downloads())
192
199
        d.addCallback(lambda result: show_downloads(result, out))
193
200
        expected = u'Current uploads: 0\nCurrent downloads: 0\n'
 
201
 
194
202
        def check(result):
195
203
            """check the output"""
196
204
            self.assertEqual(out.getvalue(), expected)
241
249
        ]
242
250
        d = self.tool.get_status()
243
251
        d.addCallback(lambda result: show_state(result, out))
 
252
 
244
253
        def check(result):
245
254
            """check the output"""
246
255
            info = [x.strip() for x in out.getvalue().split("\n") if x.strip()]
274
283
        self.action_q.queue.waiting.extend([cmd1, cmd2])
275
284
 
276
285
        out = StringIO()
277
 
        expected =  (
 
286
        expected = (
278
287
            "  FakeCommand(running=True, share_id='', "
279
288
                                    "node_id='node1', path='foo', other='')\n"
280
289
            "  FakeCommand(running=False, share_id='', "
294
303
        self.action_q.queue.waiting.extend([cmd1, cmd2])
295
304
 
296
305
        out = StringIO()
297
 
        expected =  (
 
306
        expected = (
298
307
            "Warning: this option is deprecated! Use '--waiting' instead\n"
299
308
            "  FakeCommand(running=True, share_id='', node_id='node1', "
300
309
                           "path='p', other='')\n"
344
353
        out = StringIO()
345
354
        d = self.tool.get_folders()
346
355
        d.addCallback(lambda result: show_folders(result, out))
 
356
 
347
357
        def check(result):
348
358
            """check the output"""
349
359
            self.assertEqual('No folders\n', out.getvalue())
354
364
    def test_show_folders_subscribed(self):
355
365
        """Test the output of --list-folders."""
356
366
        out = StringIO()
357
 
        path = u'ñoño'.encode('utf-8')
358
 
        suggested_path = os.path.join("~", u'ñoño')
 
367
        suggested_path = u"~/ñoño"
 
368
        path = get_udf_path(suggested_path)
359
369
 
360
370
        udf = UDF("folder_id", "node_id", suggested_path, path,
361
371
                  subscribed=True)
362
372
        yield self.main.vm.add_udf(udf)
363
373
        expected = u"Folder list:\n  id=folder_id subscribed=True " + \
364
 
                   u"path=\xf1o\xf1o\n"
 
374
                   u"path=%s\n" % path.decode('utf-8')
365
375
        result = yield self.tool.get_folders()
366
376
        show_folders(result, out)
367
377
        self.assertEqual(out.getvalue(), expected)