def test_object_client_copy_source_is_a_directory(mocker): error_code = "source_is_a_directory" exception = BadRequest(mocker.Mock(), mocker.Mock(), error_code) mocker.patch.object(ObjectClient, "_put_raw", side_effect=exception) client = ObjectClient(mocker.Mock(), mocker.Mock()) with pytest.raises(SourceIsADirectory, match="'source' is a directory"): client.copy(PROJECT_ID, "source", "destination")
def test_object_client_copy_source_not_found(mocker): error_code = "source_path_not_found" exception = NotFound(mocker.Mock(), mocker.Mock(), error_code) mocker.patch.object(ObjectClient, "_put_raw", side_effect=exception) client = ObjectClient(mocker.Mock(), mocker.Mock()) with pytest.raises(PathNotFound, match="'source' cannot be found"): client.copy(PROJECT_ID, "source", "destination")
def test_object_client_copy(mocker, recursive, expected_recursive): mocker.patch.object(ObjectClient, "_put_raw") client = ObjectClient(mocker.Mock(), mocker.Mock()) client.copy(PROJECT_ID, "source", "destination", recursive=recursive) ObjectClient._put_raw.assert_called_once_with( "/project/{}/object/{}".format(PROJECT_ID, "destination"), params={ "sourcePath": "source", "recursive": expected_recursive }, )
def test_object_client_copy_url_encoding(mocker): mocker.patch.object(ObjectClient, "_put_raw") client = ObjectClient(mocker.Mock(), mocker.Mock()) client.copy(PROJECT_ID, "source", "/[1]/") ObjectClient._put_raw.assert_called_once_with( "/project/{}/object/%5B1%5D/".format(PROJECT_ID), params={ "sourcePath": "source", "recursive": 0 }, )