Skip to content

Commit afc293e

Browse files
committed
test: chunk size env var
1 parent f2710cd commit afc293e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/test_fileuploads.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import contextlib
2+
import io
13
import os
24
import unittest
35

46
import requests_mock
57

8+
from tableauserverclient.config import BYTES_PER_MB, config
69
from tableauserverclient.server import Server
710
from ._utils import asset
811

@@ -11,6 +14,17 @@
1114
FILEUPLOAD_APPEND = os.path.join(TEST_ASSET_DIR, "fileupload_append.xml")
1215

1316

17+
@contextlib.contextmanager
18+
def set_env(**environ):
19+
old_environ = dict(os.environ)
20+
os.environ.update(environ)
21+
try:
22+
yield
23+
finally:
24+
os.environ.clear()
25+
os.environ.update(old_environ)
26+
27+
1428
class FileuploadsTests(unittest.TestCase):
1529
def setUp(self):
1630
self.server = Server("http://test", False)
@@ -62,3 +76,14 @@ def test_upload_chunks_file_object(self):
6276
actual = self.server.fileuploads.upload(file_content)
6377

6478
self.assertEqual(upload_id, actual)
79+
80+
def test_upload_chunks_config(self):
81+
data = io.BytesIO()
82+
data.write(b"1" * (config.CHUNK_SIZE_MB * BYTES_PER_MB + 1))
83+
data.seek(0)
84+
with set_env(TSC_CHUNK_SIZE_MB="1"):
85+
chunker = self.server.fileuploads._read_chunks(data)
86+
chunk = next(chunker)
87+
assert len(chunk) == config.CHUNK_SIZE_MB * BYTES_PER_MB
88+
data.seek(0)
89+
assert len(chunk) < len(data.read())

0 commit comments

Comments
 (0)