~nataliabidart/ubuntuone-control-panel/cloud-to-computer-page

« back to all changes in this revision

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

  • Committer: Natalia B. Bidart
  • Date: 2012-03-16 20:41:10 UTC
  • mfrom: (286.2.1 ubuntuone-control-panel)
  • Revision ID: natalia.bidart@canonical.com-20120316204110-z3svlrt2w5akemsy
MergedĀ trunkĀ in.

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
class DefaultFoldersTestCase(TestCase):
91
91
    """Test the default_folders method."""
92
92
 
93
 
    def test_special_folders(self):
 
93
    def test_special_folders(self, names=None):
94
94
        """Test that default_folders does the right thing."""
95
95
        folders = utils.default_folders()
96
96
 
97
 
        names = ('PERSONAL', 'MYMUSIC', 'MYPICTURES', 'MYVIDEO')
 
97
        if names is None:
 
98
            names = ('PERSONAL', 'MYMUSIC', 'MYPICTURES', 'MYVIDEO')
 
99
 
98
100
        self.assertEqual(len(folders), len(names))
99
101
        self.assertEqual(folders, [os.path.abspath(f) for f in folders])
100
102
 
106
108
 
107
109
        self.assertEqual(sorted(folders), sorted(expected))
108
110
 
 
111
    def test_special_folders_with_error(self):
 
112
        """Test that default_folders handles errors."""
 
113
        failing_name = 'MYVIDEO'
 
114
        original_func = utils.windows.shell.SHGetFolderPath
 
115
 
 
116
        class SomeError(Exception):
 
117
            """For test only."""
 
118
 
 
119
        def fail_for_some(code, name, parent, flag):
 
120
            """Custom failer."""
 
121
            fail = getattr(utils.windows.shellcon, 'CSIDL_%s' % failing_name)
 
122
            if name == fail:
 
123
                raise SomeError('The parameter is incorrect.')
 
124
            else:
 
125
                return original_func(code, name, parent, flag)
 
126
 
 
127
        self.patch(utils.windows.shell, 'SHGetFolderPath', fail_for_some)
 
128
        self.test_special_folders(names=('PERSONAL', 'MYMUSIC', 'MYPICTURES'))
 
129
 
109
130
 
110
131
class GetPathTestCase(TestCase):
111
132
    """Test the code that is used for the auto update process."""