Skip to content

Commit

Permalink
[tests] updated upload session tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samschott committed Jan 28, 2023
1 parent 45d4141 commit 05366eb
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions tests/linked/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def test_upload(client: DropboxClient) -> None:

file = resources + "/file.txt"
file_size = os.path.getsize(file)
chunk_size = file_size * 2
client.UPLOAD_REQUEST_CHUNK_SIZE = file_size * 2

md = client.upload(file, "/file.txt", chunk_size=chunk_size)
md = client.upload(file, "/file.txt")
assert md.content_hash == content_hash(file)[0]


Expand All @@ -68,9 +68,9 @@ def test_upload_session(client: DropboxClient) -> None:

large_file = resources + "/large-file.pdf"
file_size = os.path.getsize(large_file)
chunk_size = file_size // 10
client.UPLOAD_REQUEST_CHUNK_SIZE = file_size // 10

md = client.upload(large_file, "/large-file.pdf", chunk_size=chunk_size)
md = client.upload(large_file, "/large-file.pdf")

assert md.content_hash == content_hash(large_file)[0]

Expand All @@ -95,13 +95,13 @@ def test_upload_session_start_hash_mismatch(client: DropboxClient, monkeypatch)

large_file = resources + "/large-file.pdf"
file_size = os.path.getsize(large_file)
chunk_size = file_size // 10
client.UPLOAD_REQUEST_CHUNK_SIZE = file_size // 10

hasher = failing_content_hasher(0, 4)
monkeypatch.setattr(maestral.client, "DropboxContentHasher", hasher)

with pytest.raises(DataCorruptionError):
client.upload(large_file, "/large-file.pdf", chunk_size=chunk_size)
client.upload(large_file, "/large-file.pdf")

assert not client.get_metadata("/large-file.pdf")

Expand All @@ -111,12 +111,12 @@ def test_upload_session_start_retry(client: DropboxClient, monkeypatch) -> None:

large_file = resources + "/large-file.pdf"
file_size = os.path.getsize(large_file)
chunk_size = file_size // 10
client.UPLOAD_REQUEST_CHUNK_SIZE = file_size // 10

hasher = failing_content_hasher(0, 3)
monkeypatch.setattr(maestral.client, "DropboxContentHasher", hasher)

md = client.upload(large_file, "/large-file.pdf", chunk_size=chunk_size)
md = client.upload(large_file, "/large-file.pdf")

assert md.content_hash == content_hash(large_file)[0]

Expand All @@ -129,13 +129,13 @@ def test_upload_session_append_hash_mismatch(

large_file = resources + "/large-file.pdf"
file_size = os.path.getsize(large_file)
chunk_size = file_size // 10
client.UPLOAD_REQUEST_CHUNK_SIZE = file_size // 10

hasher = failing_content_hasher(1, 5)
monkeypatch.setattr(maestral.client, "DropboxContentHasher", hasher)

with pytest.raises(DataCorruptionError):
client.upload(large_file, "/large-file.pdf", chunk_size=chunk_size)
client.upload(large_file, "/large-file.pdf")

assert not client.get_metadata("/large-file.pdf")

Expand All @@ -148,12 +148,12 @@ def test_upload_session_append_hash_mismatch_retry(

large_file = resources + "/large-file.pdf"
file_size = os.path.getsize(large_file)
chunk_size = file_size // 10
client.UPLOAD_REQUEST_CHUNK_SIZE = file_size // 10

hasher = failing_content_hasher(1, 4)
monkeypatch.setattr(maestral.client, "DropboxContentHasher", hasher)

md = client.upload(large_file, "/large-file.pdf", chunk_size=chunk_size)
md = client.upload(large_file, "/large-file.pdf")
assert md.content_hash == content_hash(large_file)[0]


Expand All @@ -165,13 +165,13 @@ def test_upload_session_finish_hash_mismatch(

large_file = resources + "/large-file.pdf"
file_size = os.path.getsize(large_file)
chunk_size = file_size // 10
client.UPLOAD_REQUEST_CHUNK_SIZE = file_size // 10

hasher = failing_content_hasher(9, 13)
monkeypatch.setattr(maestral.client, "DropboxContentHasher", hasher)

with pytest.raises(DataCorruptionError):
client.upload(large_file, "/large-file.pdf", chunk_size=chunk_size)
client.upload(large_file, "/large-file.pdf")

assert not client.get_metadata("/large-file.pdf")

Expand All @@ -183,12 +183,12 @@ def test_upload_session_finish_hash_mismatch_retry(

large_file = resources + "/large-file.pdf"
file_size = os.path.getsize(large_file)
chunk_size = file_size // 10
client.UPLOAD_REQUEST_CHUNK_SIZE = file_size // 10

hasher = failing_content_hasher(9, 12)
monkeypatch.setattr(maestral.client, "DropboxContentHasher", hasher)

md = client.upload(large_file, "/large-file.pdf", chunk_size=chunk_size)
md = client.upload(large_file, "/large-file.pdf")

assert md.content_hash == content_hash(large_file)[0]

Expand Down

0 comments on commit 05366eb

Please sign in to comment.