~canonical-platform-qa/ubuntu-system-tests/use_keyboard_reset_lp1481770

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/helpers/mtp.py

Three test cases implemented:
 . Copy to ubuntu host from sd card through mtp
 . Copy to sd card from ubuntu host to through mtp
 . Check There is one entry per inode.

Approved by Richard Huddie, PS Jenkins bot, Brendan Donegan.

Show diffs side-by-side

added added

removed removed

Lines of Context:
253
253
    def __init__(self, remote_helper):
254
254
        self.remote_helper = remote_helper
255
255
        self.mtp_dir = self._calculate_mtp_dir()
 
256
        self.mtp_media_dir = self._calculate_mtp_media_dir()
256
257
 
257
258
    def get_mtp_path(self, *paths):
258
259
        """ Retrieve the mtp path following the desired paths
261
262
        """
262
263
        return '"' + os.path.join(self.mtp_dir, *paths) + '"'
263
264
 
 
265
    def get_mtp_media_path(self, *paths):
 
266
        """ Retrieve the mtp path following the desired paths
 
267
        :param paths: A list of subdir to the destination path
 
268
        :return: The mtp path already escaped to the destination path
 
269
        :raises: RuntimeError: When the media directory is not detected
 
270
        """
 
271
        if not self.mtp_media_dir:
 
272
            raise RuntimeError("No mtp media directory detected")
 
273
        return '"' + os.path.join(self.mtp_media_dir, *paths) + '"'
 
274
 
 
275
    def _calculate_mtp_media_dir(self):
 
276
        """ Get the path in the ubuntu host machine which maps to the mtp
 
277
        media dir. Use a random file to identify the device internal storage
 
278
        destination.
 
279
        """
 
280
        try:
 
281
            docs_media_dir = fs.get_media_folder_dir(fs.DIR_DOCUMENTS)
 
282
            file = fs.create_random_file(docs_media_dir, ext='.tmp')
 
283
            docs_mtp_dir = self._get_mtp_dir(fs.DIR_DOCUMENTS,
 
284
                                             os.path.basename(file))
 
285
            os.remove(file)
 
286
            return os.path.dirname(docs_mtp_dir)
 
287
        except RuntimeError:
 
288
            return None
 
289
 
264
290
    def _calculate_mtp_dir(self):
265
291
        """ Get the path in the ubuntu host machine which maps to the mtp dir.
266
292
        Use a random file to identify the device internal storage destination.