~didrocks/ubuntuone-client/use_result_var

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_main.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-02-11 16:18:11 UTC
  • mfrom: (1.1.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20110211161811-lbelxu332e8r2dov
Tags: 1.5.4-0ubuntu1
* New upstream release.
  - Files still get downloaded from unsubscribed folder (LP: #682878)
  - Add subscription capabilities to shares (LP: #708335)
  - Nautilus offers Publish option within other's shares (LP: #712674)
  - Shares dir name may not be unique (LP: #715776)
  - Send a notification when new Volume is available (LP: #702055)
  - Add messaging menu entry for new Volumes (LP: #702075)
  - Aggregate notifications for completed operations (LP: #702128)
  - Send a notification for new Share offers (LP: #702138)
  - Add messaging menu entry for new Share offers (LP: #702144)
* Remove ubuntuone-client-tools as u1sync has been moved out.
* Simplify python package as we don't have multiple python packages now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# You should have received a copy of the GNU General Public License along
17
17
# with this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
""" Tests for main.Main class """
19
 
import dbus
20
 
from dbus.mainloop.glib import DBusGMainLoop
21
19
import os
22
20
import shutil
23
21
 
27
25
from contrib.testing.testcase import (
28
26
    BaseTwistedTestCase, FAKED_CREDENTIALS,
29
27
)
 
28
from tests.platform import setup_main_test, get_main_params
 
29
 
 
30
def _get_main_common_params(testcase):
 
31
    """Return the parameters used by the all platforms."""
 
32
    return dict(root_dir=testcase.root,
 
33
                shares_dir=testcase.shares,
 
34
                data_dir=testcase.data,
 
35
                partials_dir=testcase.partials_dir,
 
36
                host='localhost', port=0,
 
37
                dns_srv=False, ssl=False,
 
38
                mark_interval=60,
 
39
                handshake_timeout=2,
 
40
                oauth_credentials=FAKED_CREDENTIALS)
30
41
 
31
42
 
32
43
class MainTests(BaseTwistedTestCase):
39
50
        self.shares = self.mktemp('shares')
40
51
        self.data = self.mktemp('data')
41
52
        self.partials_dir = self.mktemp('partials_dir')
42
 
        # monkeypatch busName.__del__ to avoid errors on gc
43
 
        # we take care of releasing the name in shutdown
44
 
        dbus.service.BusName.__del__ = lambda _: None
 
53
        # perform the extra setup steps according to the platform
 
54
        setup_main_test(self)
45
55
 
46
56
    def build_main(self, **kwargs):
47
57
        """
48
58
        Build and return a Main object, using reasonable defaults for
49
59
        the tests, plus whatever extra kwargs are passed in.
50
60
        """
51
 
        params = dict(root_dir=self.root,
52
 
                      shares_dir=self.shares,
53
 
                      data_dir=self.data,
54
 
                      partials_dir=self.partials_dir,
55
 
                      host='localhost', port=0,
56
 
                      dns_srv=False, ssl=False,
57
 
                      mark_interval=60,
58
 
                      handshake_timeout=2,
59
 
                      oauth_credentials=FAKED_CREDENTIALS,
60
 
                      glib_loop=DBusGMainLoop(set_as_default=True))
 
61
        # get the params using the platform code to ensure they are correct
 
62
        params =  get_main_params(self, _get_main_common_params(self))
61
63
        params.update(kwargs)
62
64
        m = main_mod.Main(**params)
63
65
        m.local_rescan = lambda *_: m.event_q.push('SYS_LOCAL_RESCAN_DONE')
246
248
        main = self.build_main()
247
249
        self.addCleanup(lambda: main.shutdown())
248
250
        self.assertNotIn(main.status_listener, main.event_q._listeners)
 
251
 
 
252
    def test_get_rootdir(self):
 
253
        """The get_rootdir returns the root dir."""
 
254
        expected = '~/Ubuntu Test One'
 
255
        main = self.build_main(root_dir=expected)
 
256
        self.addCleanup(lambda: main.shutdown())
 
257
 
 
258
        self.assertEqual(main.get_rootdir(), expected)
 
259
 
 
260
    def test_get_sharesdir(self):
 
261
        """The get_sharesdir returns the shares dir."""
 
262
        expected = '~/Share it to Me'
 
263
        main = self.build_main(shares_dir=expected)
 
264
        self.addCleanup(lambda: main.shutdown())
 
265
 
 
266
        self.assertEqual(main.get_sharesdir(), expected)
 
267
 
 
268
    def test_get_sharesdirlink(self):
 
269
        """The get_sharesdirlink returns the shares dir link."""
 
270
        expected = 'Share it to Me'
 
271
        main = self.build_main(shares_symlink_name=expected)
 
272
        self.addCleanup(lambda: main.shutdown())
 
273
 
 
274
        self.assertEqual(main.get_sharesdir_link(),
 
275
                         os.path.join(main.get_rootdir(), expected))