~ubuntu-branches/ubuntu/precise/ubuntuone-client/precise

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_main.py

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2011-12-21 15:46:25 UTC
  • mfrom: (1.1.56)
  • Revision ID: package-import@ubuntu.com-20111221154625-ujvunri4frsecj2k
Tags: 2.99.0-0ubuntu1
* New upstream release.
  - Verify timestamp to avoid invalid auth failures (LP: #692597)
  - Files in new UDFs not uploaded due to filtering (LP: #869920)
* debian/patches:
  - Remove upstreamed patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
2
#
3
 
# Author: Guillermo Gonzalez <guillermo.gonzalez@canonical.com>
4
 
#
5
 
# Copyright 2009 Canonical Ltd.
 
3
# Copyright 2009-2011 Canonical Ltd.
6
4
#
7
5
# This program is free software: you can redistribute it and/or modify it
8
6
# under the terms of the GNU General Public License version 3, as published
22
20
 
23
21
from twisted.internet import defer, reactor
24
22
from ubuntuone.devtools.handlers import MementoHandler
 
23
from ubuntuone.platform import expand_user
25
24
 
26
25
from contrib.testing.testcase import (
27
26
    BaseTwistedTestCase, FAKED_CREDENTIALS,
28
27
)
29
 
from tests.platform import setup_main_test, get_main_params
30
28
from ubuntuone.clientdefs import VERSION
31
29
from ubuntuone.platform import (
32
30
    is_link,
38
36
from ubuntuone.syncdaemon import main as main_mod
39
37
 
40
38
 
41
 
def _get_main_common_params(testcase):
42
 
    """Return the parameters used by the all platforms."""
43
 
    return dict(root_dir=testcase.root,
44
 
                shares_dir=testcase.shares,
45
 
                data_dir=testcase.data,
46
 
                partials_dir=testcase.partials_dir,
47
 
                host='localhost', port=0,
48
 
                dns_srv=False, ssl=False,
49
 
                mark_interval=60,
50
 
                handshake_timeout=2,
51
 
                oauth_credentials=FAKED_CREDENTIALS)
52
 
 
53
 
 
54
39
class FakeListener(object):
55
40
    """Just an object that will listen something."""
56
41
 
78
63
        self.shares = self.mktemp('shares')
79
64
        self.data = self.mktemp('data')
80
65
        self.partials_dir = self.mktemp('partials_dir')
81
 
        # perform the extra setup steps according to the platform
82
 
        setup_main_test(self)
83
66
 
84
 
        self.patch(main_mod, 'ExternalInterface', FakedExternalInterface)
 
67
        self.patch(main_mod, 'SyncdaemonService', FakedExternalInterface)
85
68
        # no event logger by default
86
69
        self.patch(main_mod.event_logging, "get_listener", lambda *a: None)
87
70
        # no status listener by default
93
76
        self._logger.addHandler(self.handler)
94
77
        self.addCleanup(self._logger.removeHandler, self.handler)
95
78
 
 
79
    def _get_main_common_params(self):
 
80
        """Return the parameters used by the all platforms."""
 
81
        return dict(root_dir=self.root,
 
82
                    shares_dir=self.shares,
 
83
                    data_dir=self.data,
 
84
                    partials_dir=self.partials_dir,
 
85
                    host='localhost', port=0,
 
86
                    dns_srv=False, ssl=False,
 
87
                    mark_interval=60,
 
88
                    handshake_timeout=2,
 
89
                    oauth_credentials=FAKED_CREDENTIALS)
 
90
 
96
91
    def build_main(self, **kwargs):
97
92
        """Build and return a Main object.
98
93
 
101
96
 
102
97
        """
103
98
        # get the params using the platform code to ensure they are correct
104
 
        params = get_main_params(self, _get_main_common_params(self))
 
99
        params = self._get_main_common_params()
105
100
        params.update(kwargs)
106
101
        m = main_mod.Main(**params)
107
102
        self.addCleanup(m.shutdown)
130
125
    @defer.inlineCallbacks
131
126
    def test_shutdown_pushes_sys_quit(self):
132
127
        """When shutting down, the SYS_QUIT event is pushed."""
133
 
        params = get_main_params(self, _get_main_common_params(self))
 
128
        params = self._get_main_common_params()
134
129
        main = main_mod.Main(**params)
135
130
        events = []
136
131
        self.patch(main.event_q, 'push',
269
264
 
270
265
    def test_get_rootdir(self):
271
266
        """The get_rootdir returns the root dir."""
272
 
        expected = os.path.expanduser(os.path.join('~', 'Ubuntu Test One'))
 
267
        expected = expand_user(os.path.join('~', 'Ubuntu Test One'))
273
268
        main = self.build_main(root_dir=expected)
274
269
        self.assertEqual(main.get_rootdir(), expected)
275
270
 
276
271
    def test_get_sharesdir(self):
277
272
        """The get_sharesdir returns the shares dir."""
278
 
        expected = os.path.expanduser(os.path.join('~', 'Share it to Me'))
 
273
        expected = expand_user(os.path.join('~', 'Share it to Me'))
279
274
        main = self.build_main(shares_dir=expected)
280
275
        self.assertEqual(main.get_sharesdir(), expected)
281
276