Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions pydrive2/test/test_fs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import errno
import json
import os
import posixpath
import secrets
import uuid
from concurrent import futures
from io import StringIO
from itertools import count
from urllib.parse import parse_qsl, urlsplit

import fsspec
Expand Down Expand Up @@ -542,27 +542,41 @@ def test_get_file_callback(fs, tmpdir, remote_dir):
assert callback.value == 40


def carried_out(response, content):
if 200 <= response.status < 300:
return True
if response.status != 409:
return False
error = json.loads(content)["error"]["errors"][0]
return error["reason"] == "fileIdInUse"


@pytest.fixture
def lose_answers(service_auth, monkeypatch):
"""Send requests of this thread to Drive and lose their answers.

Drive has done what a request asked by then, as when a connection
drops while the answer is on its way. One answer is lost unless
`times` says more, after `skip` matching requests.
`times` says more.

Only answers to requests Drive carried out are lost and counted: a
success, or the 409 `fileIdInUse` that says an earlier try did the
work. Any other answer, such as a rate limit under load or a 308 that
asks for more of an upload, reaches the filesystem as it is.
"""

def install(lost_method, path_end, skip=0, times=1):
def install(lost_method, path_end, times=1):
http = service_auth.Get_Http_Object()
send = http.request
matches = count()
lost = []

def request(uri, method="GET", **kwargs):
answer = send(uri, method, **kwargs)
if (
method == lost_method
and urlsplit(uri).path.endswith(path_end)
and skip <= next(matches) < skip + times
and carried_out(*answer)
and len(lost) < times
):
lost.append(uri)
raise ConnectionResetError("the answer was lost")
Expand Down Expand Up @@ -729,8 +743,7 @@ def test_cp_file_of_a_shortcut_after_the_answer_was_lost_leaves_one_copy(
fs, fs_factory, remote_dir, workspace_files, lose_answers
):
fs.makedirs(remote_dir)
# Drive refuses the first copy, which carries an ID meant for files.
lost = lose_answers("POST", "/copy", skip=1)
lost = lose_answers("POST", "/copy")
Comment thread
shcheklein marked this conversation as resolved.
Resolved
fs.cp_file(f"root/{workspace_files}-link", remote_dir + "/copy")
assert len(lost) == 1
assert items_below(fs_factory()[0], remote_dir) == ["copy"]