def test_search_paths_calls_get_with_expected_params(self, connection): storage_archive_service = StorageArchiveService(connection) storage_archive_service.search_paths("session_id", "device_id", "regex", 1000, "timestamp", True) connection.get.assert_called_once_with( "/api/WebRestoreSearch", params={ "webRestoreSessionId": "session_id", "guid": "device_id", "regex": "regex", "maxResults": 1000, "timestamp": "timestamp", "showDeleted": True, }, )
def test_get_file_size_calls_get_with_expected_params(self, connection): storage_archive_service = StorageArchiveService(connection) storage_archive_service.get_file_size("device_guid", "file_id", "timestamp", True, "backupset_id") connection.get.assert_called_once_with( u"/api/WebRestoreFileSize", params={ "guid": "device_guid", "fileId": "file_id", "timestamp": "timestamp", "showDeleted": True, "backupSetId": "backupset_id", }, )
def test_start_restore_with_opt_zip_result_as_true_calls_post_with_zip_result_in_data( self, connection): storage_archive_service = StorageArchiveService(connection) storage_archive_service.start_restore( DEVICE_GUID, WEB_RESTORE_SESSION_ID, PATH_SET, NUM_FILES, NUM_DIRS, SIZE, zip_result=True, ) json_arg = connection.post.call_args[KWARGS_INDEX][JSON_KEYWORD] assert json_arg.get(ZIP_RESULT_KEY) is True
def test_start_restore_with_expire_job_as_false_calls_post_with_expire_job_in_data( self, connection): storage_archive_service = StorageArchiveService(connection) storage_archive_service.start_restore( DEVICE_GUID, WEB_RESTORE_SESSION_ID, PATH_SET, NUM_FILES, NUM_DIRS, SIZE, expire_job=False, ) json_arg = connection.post.call_args[KWARGS_INDEX][JSON_KEYWORD] assert json_arg.get(EXPIRE_JOB_KEY) is False
def test_start_restore_calls_post_with_correct_url(self, connection): storage_archive_service = StorageArchiveService(connection) storage_archive_service.start_restore( TEST_DEVICE_GUID, TEST_SESSION_ID, RESTORE_GROUPS, TEST_NUM_FILES, TEST_NUM_DIRS, TEST_NUM_BYTES, ) assert ( connection.post.call_args[ARGS_INDEX][ARGS_INDEX] == START_WEB_RESTORE_JOB_URL )
def test_create_restore_session_when_invalid_encryption_key_raises_expected_error( self, mocker, connection): def side_effect(*args, **kwargs): base_err = HTTPError() base_err.response = mocker.MagicMock(spec=Response) base_err.response.text = """ [{"name":"CUSTOM_KEY_INVALID","description":"An error has occurred. See server logs for more information.","objects":[]}] """ raise Py42InternalServerError(base_err) connection.post.side_effect = side_effect storage_archive_service = StorageArchiveService(connection) with pytest.raises(Py42InvalidArchiveEncryptionKey) as err: storage_archive_service.create_restore_session( TEST_DEVICE_GUID, encryption_key=TEST_ENCRYPTION_KEY) assert "Invalid archive encryption key." in str(err.value)
def test_create_restore_session_when_invalid_password_raises_expected_error( self, mocker, connection): def side_effect(*args, **kwargs): base_err = HTTPError() base_err.response = mocker.MagicMock(spec=Response) base_err.response.text = """ [{"name":"PRIVATE_PASSWORD_INVALID","description":"An error has occurred. See server logs for more information.","objects":[]}] """ raise Py42InternalServerError(base_err) connection.post.side_effect = side_effect storage_archive_service = StorageArchiveService(connection) with pytest.raises(Py42InvalidArchivePassword) as err: storage_archive_service.create_restore_session( TEST_DEVICE_GUID, private_password=TEST_PASSWORD) assert "Invalid archive password." in str(err.value)
def test_create_restore_session_calls_post_with_correct_url( self, mocker, connection): storage_archive_service = StorageArchiveService(connection) storage_archive_service.create_restore_session(DEVICE_GUID) connection.post.assert_called_once_with(WEB_RESTORE_SESSION_URL, json=mocker.ANY)
def create_archive_service(self, device_guid, destination_guid): auth = FileArchiveAuth(self._connection, u"my", device_guid, destination_guid) conn = self._connection_manager.get_storage_connection(auth) return StorageArchiveService(conn)