~ubuntu-branches/ubuntu/raring/ubuntuone-control-panel/raring

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/utils/tests/test_darwin.py

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2012-08-23 15:19:03 UTC
  • mfrom: (1.1.36)
  • Revision ID: package-import@ubuntu.com-20120823151903-3xm1f1477ut3tqxc
Tags: 3.99.4-0ubuntu1
* New upstream release.
  - Show error for folder subscribe if local path already exists and is not
    a folder. (LP: #1033488)
* debian/copyright:
  - Update to be more in line with dep5.
* debian/patches:
  - Remove patches included upstream.
* debian/rules:
  - Update to allow building directly on older versions of Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Copyright 2012 Canonical Ltd.
 
4
#
 
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.
 
8
#
 
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.
 
13
#
 
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/>.
 
16
 
 
17
"""Test the darwin utils functions."""
 
18
 
 
19
import os
 
20
import sys
 
21
 
 
22
from twisted.internet import defer
 
23
 
 
24
from ubuntuone.controlpanel import utils
 
25
from ubuntuone.devtools.testcases import TestCase
 
26
 
 
27
# let me use protected methods
 
28
# pylint: disable=W0212
 
29
 
 
30
 
 
31
class InstallConfigTestCase(TestCase):
 
32
    """Test install_config_and_daemons."""
 
33
 
 
34
    @defer.inlineCallbacks
 
35
    def setUp(self):
 
36
        """Set up multi-call checker."""
 
37
        yield super(InstallConfigTestCase, self).setUp()
 
38
        self._called = []
 
39
 
 
40
    def _set_called(self, *args, **kwargs):
 
41
        """Store 'args' and 'kwargs for test assertions."""
 
42
        self._called.append((args, kwargs))
 
43
 
 
44
    def test_do_nothing_unfrozen(self):
 
45
        """Test that install_config_and_daemons does nothing when unfrozen."""
 
46
 
 
47
        self.patch(utils.darwin, 'save_config_path',
 
48
                   self._set_called)
 
49
        utils.install_config_and_daemons()
 
50
        self.assertEqual(self._called, [])
 
51
 
 
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',
 
60
                   self._set_called)
 
61
        utils.install_config_and_daemons()
 
62
 
 
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'),
 
73
                           {})])
 
74
 
 
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, [])