~nskaggs/ubuntu-filemanager-app/revert-r209

« back to all changes in this revision

Viewing changes to tests/autopilot/filemanager/tests/__init__.py

Refactored the first group of context menu tests.

Approved by Nicholas Skaggs, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Filemanager app autopilot tests."""
18
18
 
 
19
import logging
19
20
import os
20
21
import shutil
21
 
import logging
22
22
 
23
23
import fixtures
24
24
from autopilot import logging as autopilot_logging
32
32
    fixture_setup as toolkit_fixtures
33
33
)
34
34
 
35
 
from filemanager import emulators
 
35
from filemanager import emulators, fixture_setup
36
36
 
37
37
logger = logging.getLogger(__name__)
38
38
 
52
52
    local_location_qml = os.path.join(local_location,
53
53
                                      'src/app/qml/filemanager.qml')
54
54
    local_location_binary = os.path.join(local_location, 'src/app/filemanager')
55
 
    installed_location_qml = "/usr/share/filemanager/qml/filemanager.qml"
 
55
    installed_location_qml = '/usr/share/filemanager/qml/filemanager.qml'
56
56
    installed_location_binary = '/usr/bin/filemanager'
57
57
 
58
58
    def get_launcher_and_type(self):
111
111
            emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
112
112
 
113
113
    def _copy_xauthority_file(self, directory):
114
 
        """ Copy .Xauthority file to directory, if it exists in /home
115
 
        """
116
 
        xauth = os.path.expanduser(os.path.join('~', '.Xauthority'))
 
114
        """Copy .Xauthority file to directory, if it exists in /home"""
 
115
        xauth = os.path.join(os.environ.get('HOME'), '.Xauthority')
117
116
        if os.path.isfile(xauth):
118
117
            logger.debug("Copying .Xauthority to " + directory)
119
118
            shutil.copyfile(
120
 
                os.path.expanduser(os.path.join('~', '.Xauthority')),
 
119
                os.path.join(os.environ.get('HOME'), '.Xauthority'),
121
120
                os.path.join(directory, '.Xauthority'))
122
121
 
123
122
    def _patch_home(self):
124
 
        """ mock /home for testing purposes to preserve user data
125
 
        """
 
123
        """mock /home for testing purposes to preserve user data"""
126
124
        temp_dir_fixture = fixtures.TempDir()
127
125
        self.useFixture(temp_dir_fixture)
128
126
        temp_dir = temp_dir_fixture.path
142
140
            self.useFixture(fixtures.EnvironmentVariable('HOME',
143
141
                                                         newvalue=temp_dir))
144
142
 
145
 
        logger.debug("Patched home to fake home directory " + temp_dir)
 
143
        logger.debug('Patched home to fake home directory ' + temp_dir)
146
144
 
147
145
        return temp_dir
148
146
 
149
147
    @property
150
148
    def main_view(self):
151
149
        return self.app.wait_select_single(emulators.MainView)
 
150
 
 
151
    def make_file_in_home(self):
 
152
        return self.make_content_in_home('file')
 
153
 
 
154
    def make_directory_in_home(self):
 
155
        return self.make_content_in_home('directory')
 
156
 
 
157
    def make_content_in_home(self, type_):
 
158
        if type_ != 'file' and type_ != 'directory':
 
159
            raise ValueError('Unknown content type: "{0}"', type_)
 
160
        if type_ == 'file':
 
161
            temp_file = fixture_setup.TemporaryFileInDirectory(self.home_dir)
 
162
            self.useFixture(temp_file)
 
163
            path = temp_file.path
 
164
        else:
 
165
            temp_dir = fixture_setup.TemporaryDirectoryInDirectory(
 
166
                self.home_dir)
 
167
            self.useFixture(temp_dir)
 
168
            path = temp_dir.path
 
169
        logger.debug('Directory Listing for HOME\n%s' %
 
170
                     os.listdir(self.home_dir))
 
171
        self._assert_number_of_files(1)
 
172
        return path
 
173
 
 
174
    def _assert_number_of_files(self, expected_number_of_files, home=True):
 
175
        if home:
 
176
            expected_number_of_files += self.original_file_count
 
177
        folder_list_page = self.main_view.get_folder_list_page()
 
178
        self.assertThat(
 
179
            folder_list_page.get_number_of_files_from_list,
 
180
            Eventually(Equals(expected_number_of_files), timeout=60))
 
181
        self.assertThat(
 
182
            folder_list_page.get_number_of_files_from_header,
 
183
            Eventually(Equals(expected_number_of_files), timeout=60))