File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import contextlib
2+ import io
13import os
24import unittest
35
46import requests_mock
57
8+ from tableauserverclient .config import BYTES_PER_MB , config
69from tableauserverclient .server import Server
710from ._utils import asset
811
1114FILEUPLOAD_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+
1428class 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 ())
You can’t perform that action at this time.
0 commit comments