def test_file_versions_download(self):        
        if self.imaging_api.api_client.configuration.on_premise:
            return

        folder = self.temp_folder + '/Storage'
        file1 = 'Storage.txt'
        file2 = 'Folder1/Folder1.txt'

        try:
            if self.imaging_api.object_exists(
                requests.ObjectExistsRequest(
                    folder, self.test_storage)).exists:
                self.imaging_api.delete_folder(
                    requests.DeleteFolderRequest(
                        folder, self.test_storage, True))

            self.assertFalse(
                self.imaging_api.object_exists(
                    requests.ObjectExistsRequest(
                        folder, self.test_storage)).exists)

            self.imaging_api.copy_file(
                requests.CopyFileRequest(
                    self.original_data_folder + '/' + file1,
                    folder + '/' + file1,
                    self.test_storage,
                    self.test_storage))
            self.imaging_api.copy_file(
                requests.CopyFileRequest(
                    self.original_data_folder + '/' + file2,
                    folder + '/' + file1,
                    self.test_storage,
                    self.test_storage))
            versions = self.imaging_api.get_file_versions(
                requests.GetFileVersionsRequest(
                    folder + '/' + file1, self.test_storage)).value
            recent_version = next(x for x in versions if x.is_latest is True)
            old_version = next(x for x in versions if x.is_latest is not True)

            with open(self.imaging_api.download_file(
                    requests.DownloadFileRequest(folder + '/' + file1, self.test_storage,
                                                 old_version.version_id)), 'r') as old_file:
                self.assertEqual(old_version.size, len(old_file.read()))

            with open(self.imaging_api.download_file(
                    requests.DownloadFileRequest(folder + '/' + file1, self.test_storage,
                                                 recent_version.version_id)), 'r') as old_file:
                self.assertEqual(recent_version.size, len(old_file.read()))

        finally:
            if self.imaging_api.object_exists(
                requests.ObjectExistsRequest(
                    folder, self.test_storage)).exists:
                self.imaging_api.delete_folder(
                    requests.DeleteFolderRequest(
                        folder, self.test_storage, True))
    def test_file_versions_move(self):        
        if self.imaging_api.api_client.configuration.on_premise:
            return

        folder = self.temp_folder + '/Storage'
        file1 = 'Storage.txt'
        file2 = 'Folder1/Folder1.txt'

        try:
            if self.imaging_api.object_exists(
                requests.ObjectExistsRequest(
                    folder, self.test_storage)).exists:
                self.imaging_api.delete_folder(
                    requests.DeleteFolderRequest(
                        folder, self.test_storage, True))

            self.assertFalse(
                self.imaging_api.object_exists(
                    requests.ObjectExistsRequest(
                        folder, self.test_storage)).exists)

            self.imaging_api.copy_file(
                requests.CopyFileRequest(
                    self.original_data_folder + '/' + file1,
                    folder + '/' + file1,
                    self.test_storage,
                    self.test_storage))
            self.imaging_api.copy_file(
                requests.CopyFileRequest(
                    self.original_data_folder + '/' + file2,
                    folder + '/' + file1,
                    self.test_storage,
                    self.test_storage))
            versions = self.imaging_api.get_file_versions(
                requests.GetFileVersionsRequest(
                    folder + '/' + file1, self.test_storage)).value
            recent_version = next(x for x in versions if x.is_latest is True)

            self.imaging_api.move_file(
                requests.MoveFileRequest(
                    folder + '/' + file1,
                    folder + '/' + file1 + '.recent',
                    self.test_storage,
                    self.test_storage,
                    recent_version.version_id))
            copied_versions = self.imaging_api.get_file_versions(
                requests.GetFileVersionsRequest(
                    folder + '/' + file1 + '.recent',
                    self.test_storage)).value
            self.assertEqual(1, len(copied_versions))
            self.assertTrue(copied_versions[0].is_latest)
            self.assertEqual(recent_version.size, copied_versions[0].size)

            self.imaging_api.copy_file(
                requests.CopyFileRequest(
                    self.original_data_folder + '/' + file1,
                    folder + '/' + file1,
                    self.test_storage,
                    self.test_storage))
            self.imaging_api.copy_file(
                requests.CopyFileRequest(
                    self.original_data_folder + '/' + file2,
                    folder + '/' + file1,
                    self.test_storage,
                    self.test_storage))
            versions = self.imaging_api.get_file_versions(
                requests.GetFileVersionsRequest(
                    folder + '/' + file1, self.test_storage)).value
            old_version = next(x for x in versions if x.is_latest is not True)

            self.imaging_api.move_file(
                requests.MoveFileRequest(
                    folder + '/' + file1,
                    folder + '/' + file1 + '.old',
                    self.test_storage,
                    self.test_storage,
                    old_version.version_id))
            copied_versions = self.imaging_api.get_file_versions(
                requests.GetFileVersionsRequest(folder + '/' + file1 + '.old',
                                                self.test_storage)).value
            self.assertEqual(1, len(copied_versions))
            self.assertTrue(copied_versions[0].is_latest)
            self.assertEqual(old_version.size, copied_versions[0].size)

        finally:
            if self.imaging_api.object_exists(
                requests.ObjectExistsRequest(
                    folder, self.test_storage)).exists:
                self.imaging_api.delete_folder(
                    requests.DeleteFolderRequest(
                        folder, self.test_storage, True))
    def test_file_versions_create(self):        
        if self.imaging_api.api_client.configuration.on_premise:
            return

        folder = self.temp_folder + '/Storage'
        file1 = 'Storage.txt'
        file2 = 'Folder1/Folder1.txt'

        file1_size = next(
            x for x in self.imaging_api.get_files_list(
                requests.GetFilesListRequest(
                    self.original_data_folder,
                    self.test_storage)).value if x.name == file1).size

        file2_size = next(
            x for x in self.imaging_api.get_files_list(
                requests.GetFilesListRequest(
                    self.original_data_folder + '/Folder1',
                    self.test_storage)).value if x.name == 'Folder1.txt').size

        try:
            if self.imaging_api.object_exists(
                requests.ObjectExistsRequest(
                    folder, self.test_storage)).exists:
                self.imaging_api.delete_folder(
                    requests.DeleteFolderRequest(
                        folder, self.test_storage, True))

            self.assertFalse(
                self.imaging_api.object_exists(
                    requests.ObjectExistsRequest(
                        folder, self.test_storage)).exists)

            self.imaging_api.copy_file(
                requests.CopyFileRequest(
                    self.original_data_folder + '/' + file1,
                    folder + '/' + file1,
                    self.test_storage,
                    self.test_storage))
            self.imaging_api.copy_file(
                requests.CopyFileRequest(
                    self.original_data_folder + '/' + file2,
                    folder + '/' + file1,
                    self.test_storage,
                    self.test_storage))
            versions = self.imaging_api.get_file_versions(
                requests.GetFileVersionsRequest(
                    folder + '/' + file1, self.test_storage)).value

            self.assertEqual(2, len(versions))
            recent_version_size = next(
                x for x in versions if x.is_latest is True).size
            old_version_size = next(
                x for x in versions if x.is_latest is not True).size
            self.assertNotEqual(recent_version_size, old_version_size)
            self.assertEqual(old_version_size, file1_size)
            self.assertEqual(recent_version_size, file2_size)

        finally:
            if self.imaging_api.object_exists(
                requests.ObjectExistsRequest(
                    folder, self.test_storage)).exists:
                self.imaging_api.delete_folder(
                    requests.DeleteFolderRequest(
                        folder, self.test_storage, True))