-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathtest_upload_api_v4.py
More file actions
64 lines (49 loc) · 1.97 KB
/
test_upload_api_v4.py
File metadata and controls
64 lines (49 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import io
import py
from mapillary_tools import upload_api_v4
from ..integration.fixtures import setup_upload
def test_upload(setup_upload: py.path.local):
upload_service = upload_api_v4.FakeUploadService(
user_access_token="TEST",
session_key="FOOBAR.txt",
chunk_size=1,
)
upload_service._error_ratio = 0
content = b"double_foobar"
cluster_id = upload_service.upload(io.BytesIO(content))
assert isinstance(cluster_id, str), cluster_id
assert (setup_upload.join("FOOBAR.txt").read_binary()) == content
# reupload should not affect the file
upload_service.upload(io.BytesIO(content))
assert (setup_upload.join("FOOBAR.txt").read_binary()) == content
def test_upload_big_chunksize(setup_upload: py.path.local):
upload_service = upload_api_v4.FakeUploadService(
user_access_token="TEST",
session_key="FOOBAR.txt",
chunk_size=1000,
)
upload_service._error_ratio = 0
content = b"double_foobar"
cluster_id = upload_service.upload(io.BytesIO(content))
assert isinstance(cluster_id, str), cluster_id
assert (setup_upload.join("FOOBAR.txt").read_binary()) == content
# reupload should not affect the file
upload_service.upload(io.BytesIO(content))
assert (setup_upload.join("FOOBAR.txt").read_binary()) == content
def test_upload_chunks(setup_upload: py.path.local):
upload_service = upload_api_v4.FakeUploadService(
user_access_token="TEST",
session_key="FOOBAR2.txt",
)
upload_service._error_ratio = 0
def _gen_chunks():
yield b"foo"
yield b""
yield b"bar"
yield b""
cluster_id = upload_service.upload_chunks(_gen_chunks())
assert isinstance(cluster_id, str), cluster_id
assert (setup_upload.join("FOOBAR2.txt").read_binary()) == b"foobar"
# reupload should not affect the file
upload_service.upload_chunks(_gen_chunks())
assert (setup_upload.join("FOOBAR2.txt").read_binary()) == b"foobar"