Esempio n. 1
0
 def test_stream_from_backup_uses_show_deleted_param_on_get_file_path_metadata(
     self,
     mocker,
     storage_archive_service,
     restore_job_manager,
     file_size_poller,
 ):
     mock_walking_to_downloads_folder(mocker, storage_archive_service)
     archive_accessor = ArchiveContentStreamer(
         TEST_DEVICE_GUID,
         TEST_SESSION_ID,
         TEST_DESTINATION_GUID_1,
         storage_archive_service,
         restore_job_manager,
         file_size_poller,
     )
     archive_accessor.stream_from_backup(TEST_BACKUP_SET_ID,
                                         TEST_DOWNLOADS_DIR)
     storage_archive_service.get_file_path_metadata.assert_called_with(
         TEST_SESSION_ID,
         TEST_DEVICE_GUID,
         TEST_BACKUP_SET_ID,
         file_id=mocker.ANY,
         show_deleted=True,
     )
Esempio n. 2
0
    def test_stream_from_backup_when_not_ignoring_file_size_calc_returns_size_sums_from_response(
        self, mocker, storage_archive_service, restore_job_manager, file_size_poller
    ):
        mock_walking_to_downloads_folder(mocker, storage_archive_service)
        archive_accessor = ArchiveContentStreamer(
            TEST_DEVICE_GUID,
            TEST_SESSION_ID,
            TEST_DESTINATION_GUID_1,
            storage_archive_service,
            restore_job_manager,
            file_size_poller,
        )

        def get_file_sizes(*args, **kwargs):
            return [
                {"numFiles": 1, "numDirs": 2, "size": 3},
                {"numFiles": 4, "numDirs": 5, "size": 6},
            ]

        file_size_poller.get_file_sizes.side_effect = get_file_sizes
        archive_accessor.stream_from_backup(
            TEST_BACKUP_SET_ID,
            [TEST_PATH_TO_FILE_IN_DOWNLOADS_DIR, TEST_DOWNLOADS_DIR],
        )
        expected_file_selection = [
            get_file_selection(
                FileType.FILE, TEST_PATH_TO_FILE_IN_DOWNLOADS_DIR, 1, 2, 3,
            ),
            get_file_selection(FileType.DIRECTORY, TEST_DOWNLOADS_DIR, 4, 5, 6,),
        ]
        restore_job_manager.get_stream.assert_called_once_with(
            TEST_BACKUP_SET_ID, expected_file_selection, show_deleted=None,
        )
Esempio n. 3
0
    def test_stream_from_backup_with_case_sensitive_drive_not_in_archive_raises_exception(
        self,
        mocker,
        storage_archive_service,
        restore_job_manager,
        file_size_poller,
    ):
        mock_walking_to_downloads_folder(mocker, storage_archive_service)
        archive_accessor = ArchiveContentStreamer(
            TEST_DEVICE_GUID,
            TEST_SESSION_ID,
            TEST_DESTINATION_GUID_1,
            storage_archive_service,
            restore_job_manager,
            file_size_poller,
        )
        invalid_path_in_downloads_folder = (
            "c:/Users/qa/Downloads/file-not-in-archive.txt")
        with pytest.raises(Py42ArchiveFileNotFoundError) as e:
            archive_accessor.stream_from_backup(
                TEST_BACKUP_SET_ID, invalid_path_in_downloads_folder)

        expected_message = u"File not found in archive for device device-guid at path {}".format(
            invalid_path_in_downloads_folder)
        assert e.value.args[0] == expected_message
        restore_job_manager.get_stream.assert_not_called()
Esempio n. 4
0
 def test_stream_from_backup_normalizes_windows_paths(
     self,
     mocker,
     storage_archive_service,
     restore_job_manager,
     file_size_poller,
 ):
     mock_walking_tree_for_windows_path(mocker, storage_archive_service)
     archive_accessor = ArchiveContentStreamer(
         TEST_DEVICE_GUID,
         TEST_SESSION_ID,
         TEST_DESTINATION_GUID_1,
         storage_archive_service,
         restore_job_manager,
         file_size_poller,
     )
     archive_accessor.stream_from_backup(TEST_BACKUP_SET_ID,
                                         "C:\\",
                                         file_size_calc_timeout=0)
     expected_file_selection = [
         get_file_selection(FileType.DIRECTORY, "C:/")
     ]
     restore_job_manager.get_stream.assert_called_once_with(
         TEST_BACKUP_SET_ID,
         expected_file_selection,
         show_deleted=None,
     )
Esempio n. 5
0
 def test_stream_from_backup_with_file_path_calls_get_stream(
         self, mocker, storage_archive_service, restore_job_manager,
         file_size_poller):
     mock_walking_to_downloads_folder(mocker, storage_archive_service)
     archive_accessor = ArchiveContentStreamer(
         TEST_DEVICE_GUID,
         TEST_SESSION_ID,
         TEST_DESTINATION_GUID_1,
         storage_archive_service,
         restore_job_manager,
         file_size_poller,
     )
     archive_accessor.stream_from_backup(
         TEST_BACKUP_SET_ID,
         TEST_PATH_TO_FILE_IN_DOWNLOADS_DIR,
         file_size_calc_timeout=0,
     )
     expected_file_selection = [
         get_file_selection(FileType.FILE,
                            TEST_PATH_TO_FILE_IN_DOWNLOADS_DIR)
     ]
     restore_job_manager.get_stream.assert_called_once_with(
         TEST_BACKUP_SET_ID,
         expected_file_selection,
         show_deleted=None,
     )
Esempio n. 6
0
 def test_stream_from_backup_with_root_level_folder_calls_get_stream(
         self, mocker, storage_archive_service, restore_job_manager,
         file_size_poller):
     mock_get_file_path_metadata_responses(
         mocker,
         storage_archive_service,
         [
             GetFilePathMetadataResponses.NULL_ID,
             GetFilePathMetadataResponses.ROOT
         ],
     )
     archive_accessor = ArchiveContentStreamer(
         TEST_DEVICE_GUID,
         TEST_SESSION_ID,
         TEST_DESTINATION_GUID_1,
         storage_archive_service,
         restore_job_manager,
         file_size_poller,
     )
     archive_accessor.stream_from_backup(TEST_BACKUP_SET_ID,
                                         USERS_DIR,
                                         show_deleted=True)
     expected_file_selection = [
         get_file_selection(FileType.DIRECTORY, USERS_DIR)
     ]
     restore_job_manager.get_stream.assert_called_once_with(
         TEST_BACKUP_SET_ID,
         expected_file_selection,
         show_deleted=True,
     )
Esempio n. 7
0
 def test_stream_from_backup_calls_get_file_size_with_expected_params(
     self, mocker, storage_archive_service, restore_job_manager, file_size_poller,
 ):
     mock_walking_to_downloads_folder(mocker, storage_archive_service)
     archive_accessor = ArchiveContentStreamer(
         TEST_DEVICE_GUID,
         TEST_SESSION_ID,
         TEST_DESTINATION_GUID_1,
         storage_archive_service,
         restore_job_manager,
         file_size_poller,
     )
     archive_accessor.stream_from_backup(
         TEST_BACKUP_SET_ID,
         TEST_PATH_TO_FILE_IN_DOWNLOADS_DIR,
         file_size_calc_timeout=10,
     )
     file_size_poller.get_file_sizes.assert_called_once_with(
         [TEST_DOWNLOADS_FILE_ID], timeout=10
     )