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 """
20
from dbus.mainloop.glib import DBusGMainLoop
27
25
from contrib.testing.testcase import (
28
26
BaseTwistedTestCase, FAKED_CREDENTIALS,
28
from tests.platform import setup_main_test, get_main_params
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,
40
oauth_credentials=FAKED_CREDENTIALS)
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
46
56
def build_main(self, **kwargs):
48
58
Build and return a Main object, using reasonable defaults for
49
59
the tests, plus whatever extra kwargs are passed in.
51
params = dict(root_dir=self.root,
52
shares_dir=self.shares,
54
partials_dir=self.partials_dir,
55
host='localhost', port=0,
56
dns_srv=False, ssl=False,
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)
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())
258
self.assertEqual(main.get_rootdir(), expected)
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())
266
self.assertEqual(main.get_sharesdir(), expected)
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())
274
self.assertEqual(main.get_sharesdir_link(),
275
os.path.join(main.get_rootdir(), expected))