~nataliabidart/ubuntuone-control-panel/stable-3-0-update-2.99.92

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/tests/test_sd_client.py

  • Committer: Natalia B. Bidart
  • Date: 2012-04-03 12:40:00 UTC
  • mfrom: (238.1.70 ubuntuone-control-panel)
  • Revision ID: natalia.bidart@canonical.com-20120403124000-lfpv28ymajeblg3s
- Updating from trunk up to revno 308.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
 
 
3
 
# Authors: Alejandro J. Cura <alecu@canonical.com>
4
 
# Authors: Natalia B. Bidart <natalia.bidart@canonical.com>
5
2
#
6
 
# Copyright 2010 Canonical Ltd.
 
3
# Copyright 2010-2012 Canonical Ltd.
7
4
#
8
5
# This program is free software: you can redistribute it and/or modify it
9
6
# under the terms of the GNU General Public License version 3, as published
24
21
 
25
22
from twisted.internet import defer
26
23
from twisted.internet.defer import inlineCallbacks, returnValue
27
 
from ubuntuone.devtools.testcases import skipIfNotOS
28
 
# No name 'tools' in module 'ubuntuone.platform'
29
 
# pylint: disable=E0611
30
24
from ubuntuone.platform import tools
31
 
# pylint: enable=E0611
32
25
from ubuntuone.syncdaemon.interaction_interfaces import bool_str
33
26
 
34
27
from ubuntuone.controlpanel import sd_client
164
157
        """Get the list of the shares "shared"/created/offered."""
165
158
        self.called['list_shared'] = None
166
159
 
 
160
    def validate_path(self, path):
 
161
        """Validate a path for folder creation."""
 
162
        return path not in [f['path'] for f in self.folders.itervalues()]
 
163
 
167
164
    def create_folder(self, path):
168
165
        """Create a user defined folder in the specified path."""
169
166
        if path == '':  # simulate an error
183
180
    @inlineCallbacks
184
181
    def subscribe_folder(self, folder_id):
185
182
        """Subscribe to a user defined folder given its id."""
186
 
        yield self._set_folder_attr(folder_id,
187
 
                                                   u'subscribed', True)
 
183
        yield self._set_folder_attr(folder_id, u'subscribed', True)
188
184
 
189
185
    @inlineCallbacks
190
186
    def unsubscribe_folder(self, folder_id):
191
187
        """Unsubscribe from a user defined folder given its id."""
192
 
        yield self._set_folder_attr(folder_id,
193
 
                                                   u'subscribed', False)
 
188
        yield self._set_folder_attr(folder_id, u'subscribed', False)
194
189
 
195
190
    @inlineCallbacks
196
191
    def get_folders(self):
315
310
        """Return the shares link directory."""
316
311
        return self.shares_dir_link
317
312
 
318
 
    def set_status_changed_handler(self, handler):
 
313
    def connect_signal(self, signal_name, handler):
319
314
        """Set the handler for the status changed signal."""
320
 
        self.called['status_changed_handler'] = handler
 
315
        self.called[signal_name] = handler
321
316
 
322
317
 
323
318
class BaseTestCase(TestCase):
519
514
        yield self.assertFailure(self.sd.get_folders(), CustomError)
520
515
 
521
516
    @inlineCallbacks
 
517
    def test_validate_path(self):
 
518
        """Check if a folder path is valid."""
 
519
        path = '~/bar/baz'
 
520
        result = yield self.sd.validate_path(path)
 
521
 
 
522
        self.assertTrue(result)
 
523
 
 
524
        yield self.sd.create_folder(path)
 
525
        result = yield self.sd.validate_path(path)
 
526
 
 
527
        self.assertFalse(result)
 
528
 
 
529
    @inlineCallbacks
522
530
    def test_create_folder(self):
523
531
        """Create a new folder."""
524
532
        path = '~/bar/baz'
694
702
 
695
703
        self.assertEqual(self.sd.proxy.called['quit'], None)
696
704
 
697
 
    @skipIfNotOS('win32', 'The tested function is only defined on windows')
698
705
    @inlineCallbacks
699
706
    def test_set_status_changed_handler(self):
700
707
        """Connect a handler to the status changed signal."""
701
708
        sample_handler = object()
702
709
        yield self.sd.set_status_changed_handler(sample_handler)
703
 
        self.assertEqual(sample_handler,
704
 
                   self.sd.proxy.called['status_changed_handler'])
 
710
        self.assertEqual(sample_handler, self.sd.proxy.called['StatusChanged'])
705
711
 
706
712
 
707
713
class BasicTestCase(BaseTestCase):