1
# -*- coding: utf-8 -*-
3
# Copyright 2012 Canonical Ltd.
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 3, as published
7
# by the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12
# PURPOSE. See the GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License along
15
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
"""Test the darwin utils functions."""
22
from twisted.internet import defer
24
from ubuntuone.controlpanel import utils
25
from ubuntuone.devtools.testcases import TestCase
27
# let me use protected methods
28
# pylint: disable=W0212
31
class InstallConfigTestCase(TestCase):
32
"""Test install_config_and_daemons."""
34
@defer.inlineCallbacks
36
"""Set up multi-call checker."""
37
yield super(InstallConfigTestCase, self).setUp()
40
def _set_called(self, *args, **kwargs):
41
"""Store 'args' and 'kwargs for test assertions."""
42
self._called.append((args, kwargs))
44
def test_do_nothing_unfrozen(self):
45
"""Test that install_config_and_daemons does nothing when unfrozen."""
47
self.patch(utils.darwin, 'save_config_path',
49
utils.install_config_and_daemons()
50
self.assertEqual(self._called, [])
52
def _test_copying_conf_files(self, exists):
53
"""Call install_config_and_daemons, parameterize os.path.exists."""
54
sys.frozen = 'macosx_app'
55
self.addCleanup(delattr, sys, 'frozen')
56
self.patch(utils.darwin, 'save_config_path', lambda x: "TARGET_PATH")
57
self.patch(utils.darwin, '__file__', "/path/to/Main.app/ignore")
58
self.patch(os.path, "exists", lambda x: exists)
59
self.patch(utils.darwin.shutil, 'copyfile',
61
utils.install_config_and_daemons()
63
def test_copies_conf_files(self):
64
"""When frozen, we copy the conf files if they don't exist."""
65
self._test_copying_conf_files(False)
66
self.assertEqual(self._called,
67
[(('/path/to/Main.app/Contents/'
68
'Resources/syncdaemon.conf',
69
'TARGET_PATH/syncdaemon.conf'), {}),
70
(('/path/to/Main.app/Contents/'
71
'Resources/logging.conf',
72
'TARGET_PATH/logging.conf'),
75
def test_does_not_copy_conf_files(self):
76
"""When frozen, we do not copy the conf files if they do exist."""
77
self._test_copying_conf_files(True)
78
self.assertEqual(self._called, [])