Exemple #1
0
    def test_create_restore_session_with_device_guid_calls_post_with_device_guid_in_json(
            self, session):
        storage_archive_client = StorageArchiveClient(session)

        storage_archive_client.create_restore_session(DEVICE_GUID)
        json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]
        assert json_arg.get(COMPUTER_GUID_KEY) == DEVICE_GUID
Exemple #2
0
 def test_start_restore_with_all_args_calls_post_with_all_args_in_data(
         self, session):
     storage_archive_client = StorageArchiveClient(session)
     storage_archive_client.start_restore(
         DEVICE_GUID,
         WEB_RESTORE_SESSION_ID,
         PATH_SET,
         NUM_FILES,
         NUM_DIRS,
         SIZE,
         zip_result=True,
         expire_job=True,
         show_deleted=True,
         restore_full_path=True,
         timestamp=TIMESTAMP,
         exceptions=EXCEPTIONS,
         backup_set_id=BACKUP_SET_ID,
     )
     json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]
     expected_data = {
         GUID_KEY: DEVICE_GUID,
         WEB_RESTORE_SESSION_ID_KEY: WEB_RESTORE_SESSION_ID,
         PATH_SET_KEY: PATH_SET,
         NUM_FILES_KEY: NUM_FILES,
         NUM_DIRS_KEY: NUM_DIRS,
         SIZE_KEY: SIZE,
         ZIP_RESULT_KEY: True,
         EXPIRE_JOB_KEY: True,
         SHOW_DELETED_KEY: True,
         RESTORE_FULL_PATH_KEY: True,
         TIMESTAMP_KEY: TIMESTAMP,
         EXCEPTIONS_KEY: EXCEPTIONS,
         BACKUP_SET_ID_KEY: BACKUP_SET_ID,
     }
     assert json_arg == expected_data
Exemple #3
0
    def test_start_restore_with_required_args_calls_post_with_all_args_in_json(
            self, session):
        storage_archive_client = StorageArchiveClient(session)
        storage_archive_client.start_restore(DEVICE_GUID,
                                             WEB_RESTORE_SESSION_ID, PATH_SET,
                                             NUM_FILES, NUM_DIRS, SIZE)

        json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]

        keys = [
            GUID_KEY,
            WEB_RESTORE_SESSION_ID_KEY,
            PATH_SET_KEY,
            NUM_FILES_KEY,
            NUM_DIRS_KEY,
            SIZE_KEY,
            ZIP_RESULT_KEY,
            EXPIRE_JOB_KEY,
            SHOW_DELETED_KEY,
            RESTORE_FULL_PATH_KEY,
            TIMESTAMP_KEY,
            EXCEPTIONS_KEY,
            BACKUP_SET_ID_KEY,
        ]

        assert sorted(json_arg.keys()) == sorted(keys)
Exemple #4
0
 def test_cancel_restore_calls_delete_with_correct_url(
         self, mocker, session):
     storage_archive_client = StorageArchiveClient(session)
     api_response = mocker.MagicMock(spec=Py42Response)
     session.delete.return_value = api_response
     storage_archive_client.cancel_restore(WEB_RESTORE_JOB_ID)
     session.delete.assert_called_once_with(WEB_RESTORE_JOB_URL,
                                            json=mocker.ANY)
Exemple #5
0
    def test_create_restore_session_with_private_password_calls_post_with_private_password_in_json(
            self, session):
        storage_archive_client = StorageArchiveClient(session)

        storage_archive_client.create_restore_session(
            DEVICE_GUID, private_password=PRIVATE_PASSWORD)
        json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]
        assert json_arg.get(PRIVATE_PASSWORD_KEY) == PRIVATE_PASSWORD
Exemple #6
0
 def test_stream_restore_result_status_calls_get_with_correct_url(
         self, mocker, session):
     storage_archive_client = StorageArchiveClient(session)
     api_response = mocker.MagicMock(spec=Py42Response)
     session.get.return_value = api_response
     storage_archive_client.stream_restore_result(WEB_RESTORE_JOB_ID)
     expected_url = WEB_RESTORE_JOB_RESULT_URL + "/" + WEB_RESTORE_JOB_ID
     session.get.assert_called_once_with(expected_url, stream=True)
Exemple #7
0
    def test_start_restore_calls_post_with_correct_url(self, session):
        storage_archive_client = StorageArchiveClient(session)

        storage_archive_client.start_restore(DEVICE_GUID,
                                             WEB_RESTORE_SESSION_ID, PATH_SET,
                                             NUM_FILES, NUM_DIRS, SIZE)
        assert session.post.call_args[ARGS_INDEX][
            ARGS_INDEX] == WEB_RESTORE_JOB_URL
Exemple #8
0
    def test_create_restore_session_with_encryption_key_calls_post_with_encryption_key_in_json(
            self, session):
        storage_archive_client = StorageArchiveClient(session)

        storage_archive_client.create_restore_session(
            DEVICE_GUID, encryption_key=ENCRYPTION_KEY)
        json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]
        assert json_arg.get(ENCRYPTION_KEY_KEY) == ENCRYPTION_KEY
Exemple #9
0
    def test_create_restore_session_with_data_key_token_calls_post_with_data_key_token_in_json(
            self, session):
        storage_archive_client = StorageArchiveClient(session)

        storage_archive_client.create_restore_session(
            DEVICE_GUID, data_key_token=DATA_KEY_TOKEN)
        json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]
        assert json_arg.get(DATA_KEY_TOKEN_KEY) == DATA_KEY_TOKEN
Exemple #10
0
 def test_cancel_restore_calls_delete_with_job_id_in_data(
         self, mocker, session):
     storage_archive_client = StorageArchiveClient(session)
     api_response = mocker.MagicMock(spec=Py42Response)
     text = json.dumps({JOB_ID_KEY: WEB_RESTORE_JOB_ID})
     session.delete.return_value = api_response
     storage_archive_client.cancel_restore(WEB_RESTORE_JOB_ID)
     json_arg = session.delete.call_args[KWARGS_INDEX][JSON_KEYWORD]
     expected_data = {JOB_ID_KEY: WEB_RESTORE_JOB_ID}
     assert json_arg == expected_data
Exemple #11
0
 def test_start_restore_with_backup_set_id_calls_post_with_backup_set_id_in_data(
         self, session):
     storage_archive_client = StorageArchiveClient(session)
     storage_archive_client.start_restore(
         DEVICE_GUID,
         WEB_RESTORE_SESSION_ID,
         PATH_SET,
         NUM_FILES,
         NUM_DIRS,
         SIZE,
         backup_set_id=BACKUP_SET_ID,
     )
     json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]
     assert json_arg.get(BACKUP_SET_ID_KEY) == BACKUP_SET_ID
Exemple #12
0
 def test_start_restore_with_exceptions_calls_post_with_exceptions_in_data(
         self, session):
     storage_archive_client = StorageArchiveClient(session)
     storage_archive_client.start_restore(
         DEVICE_GUID,
         WEB_RESTORE_SESSION_ID,
         PATH_SET,
         NUM_FILES,
         NUM_DIRS,
         SIZE,
         exceptions=EXCEPTIONS,
     )
     json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]
     assert json_arg.get(EXCEPTIONS_KEY) == EXCEPTIONS
Exemple #13
0
 def test_start_restore_with_restore_full_path_false_calls_post_with_restore_full_path_true_in_data(
         self, session):
     storage_archive_client = StorageArchiveClient(session)
     storage_archive_client.start_restore(
         DEVICE_GUID,
         WEB_RESTORE_SESSION_ID,
         PATH_SET,
         NUM_FILES,
         NUM_DIRS,
         SIZE,
         restore_full_path=False,
     )
     json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]
     assert json_arg.get(RESTORE_FULL_PATH_KEY) is False
Exemple #14
0
 def test_start_restore_with_show_deleted_false_calls_post_with_show_deleted_false_in_data(
         self, session):
     storage_archive_client = StorageArchiveClient(session)
     storage_archive_client.start_restore(
         DEVICE_GUID,
         WEB_RESTORE_SESSION_ID,
         PATH_SET,
         NUM_FILES,
         NUM_DIRS,
         SIZE,
         show_deleted=False,
     )
     json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]
     assert json_arg.get(SHOW_DELETED_KEY) is False
Exemple #15
0
 def test_start_restore_with_timestamp_calls_post_with_timestamp_in_data(
         self, session):
     storage_archive_client = StorageArchiveClient(session)
     storage_archive_client.start_restore(
         DEVICE_GUID,
         WEB_RESTORE_SESSION_ID,
         PATH_SET,
         NUM_FILES,
         NUM_DIRS,
         SIZE,
         timestamp=TIMESTAMP,
     )
     json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]
     assert json_arg.get(TIMESTAMP_KEY) == TIMESTAMP
Exemple #16
0
    def test_start_restore_with_opt_zip_result_as_true_calls_post_with_zip_result_in_data(
            self, session):
        storage_archive_client = StorageArchiveClient(session)

        storage_archive_client.start_restore(
            DEVICE_GUID,
            WEB_RESTORE_SESSION_ID,
            PATH_SET,
            NUM_FILES,
            NUM_DIRS,
            SIZE,
            zip_result=True,
        )
        json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]
        assert json_arg.get(ZIP_RESULT_KEY) is True
Exemple #17
0
    def test_start_restore_with_expire_job_as_false_calls_post_with_expire_job_in_data(
            self, session):
        storage_archive_client = StorageArchiveClient(session)

        storage_archive_client.start_restore(
            DEVICE_GUID,
            WEB_RESTORE_SESSION_ID,
            PATH_SET,
            NUM_FILES,
            NUM_DIRS,
            SIZE,
            expire_job=False,
        )
        json_arg = session.post.call_args[KWARGS_INDEX][JSON_KEYWORD]
        assert json_arg.get(EXPIRE_JOB_KEY) is False
Exemple #18
0
 def __init__(self, session):
     super(StorageClient, self).__init__(session)
     self._archive_client = StorageArchiveClient(session)
     self._security_client = StorageSecurityClient(session)
Exemple #19
0
 def test_create_restore_session_calls_post_with_correct_url(
         self, mocker, session):
     storage_archive_client = StorageArchiveClient(session)
     storage_archive_client.create_restore_session(DEVICE_GUID)
     session.post.assert_called_once_with(WEB_RESTORE_SESSION_URL,
                                          json=mocker.ANY)