Exemplo n.º 1
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,
        )
Exemplo n.º 2
0
def archive_explorer(mocker):
    mock = mocker.MagicMock(spec=ArchiveExplorer)
    mock.destination_guid = TEST_DESTINATION_GUID_1
    mock.create_file_selections.return_value = [
        get_file_selection(TEST_PATHS[0], FileType.FILE),
        get_file_selection(TEST_PATHS[1], FileType.FILE),
    ]
    return mock
Exemplo n.º 3
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,
     )
Exemplo n.º 4
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,
     )
Exemplo n.º 5
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,
     )
Exemplo n.º 6
0
from tests.conftest import TEST_RESTORE_PATH

from py42.clients._archiveaccess import ArchiveContentPusher
from py42.clients._archiveaccess import ArchiveContentStreamer
from py42.clients._archiveaccess import ArchiveExplorer
from py42.clients._archiveaccess import FileType
from py42.clients._archiveaccess.accessorfactory import ArchiveAccessorFactory
from py42.clients.archive import ArchiveClient


TEST_ARCHIVE_GUID = "4224"
TEST_DAYS = 42
TEST_ORG_ID = 424242
TEST_PATHS = ["path/to/first/file", "path/to/second/file"]
TEST_FILE_SELECTIONS = [
    get_file_selection(TEST_PATHS[0], FileType.FILE),
    get_file_selection(TEST_PATHS[1], FileType.FILE),
]


@pytest.fixture
def archive_accessor_factory(mocker):
    return mocker.MagicMock(spec=ArchiveAccessorFactory)


@pytest.fixture
def archive_content_streamer(mocker):
    mock = mocker.MagicMock(spec=ArchiveContentStreamer)
    mock.destination_guid = TEST_DESTINATION_GUID_1
    return mock
Exemplo n.º 7
0
def single_dir_selection():
    return [get_file_selection(FileType.DIRECTORY, PATH_TO_DOWNLOADS_FOLDER)]