File tree Expand file tree Collapse file tree
google/api_core/resumable_media
tests/unit/resumable_media Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,7 +72,13 @@ def invalid(self) -> bool:
7272
7373 @property
7474 def chunk_size (self ) -> int :
75- """int: The block-aligned chunk size informed by server granularity."""
75+ """int: The block-aligned chunk size informed by server granularity.
76+
77+ All chunks (except the last one) must have a size that is a multiple
78+ of the server's chunk granularity. We round the user's requested size
79+ up to the nearest granularity multiple to ensure all intermediate
80+ chunks conform to this protocol constraint.
81+ """
7682 if self ._chunk_granularity :
7783 return (
7884 (self ._chunk_size + self ._chunk_granularity - 1 )
Original file line number Diff line number Diff line change @@ -186,12 +186,16 @@ def _log_request(
186186 def _log_response (self , response : requests .Response ):
187187 if not _LOGGER .isEnabledFor (logging .DEBUG ):
188188 return
189+ try :
190+ body = response .text
191+ except (ValueError , AttributeError ):
192+ body = "<unavailable or closed>"
189193 _LOGGER .debug (
190194 "HTTP Response: %s %s\n Headers: %s\n Body: %s" ,
191195 response .status_code ,
192196 response .reason ,
193197 response .headers ,
194- response . text ,
198+ body ,
195199 )
196200
197201 def initiate (
Original file line number Diff line number Diff line change @@ -43,7 +43,13 @@ def test_deadline_exceeded():
4343
4444
4545@responses .activate
46- def test_happy_path_upload ():
46+ def test_happy_path_upload (caplog ):
47+ import logging
48+
49+ caplog .set_level (
50+ logging .DEBUG , logger = "google.api_core.resumable_media.requests_upload"
51+ )
52+
4753 initial_url = "http://example.com/start"
4854 session_url = "http://example.com/session/123"
4955 data = b"hello world"
@@ -70,7 +76,7 @@ def test_happy_path_upload():
7076 session = requests .Session ()
7177 response = requests_upload .make_resumable_upload (
7278 transport = session ,
73- request_body = "" ,
79+ request_body = "test-initiate-metadata " ,
7480 stream = stream ,
7581 upload_url = initial_url ,
7682 size = len (data ),
@@ -90,6 +96,13 @@ def test_happy_path_upload():
9096 == "upload, finalize"
9197 )
9298
99+ # Check that the initiation and chunk response logs are successfully written without raising exceptions
100+ assert f"HTTP Request: POST { initial_url } " in caplog .text
101+ assert "Body: test-initiate-metadata" in caplog .text
102+ assert f"HTTP Request: POST { session_url } " in caplog .text
103+ assert "HTTP Response: 200" in caplog .text
104+ assert "Body: Success" in caplog .text
105+
93106
94107@responses .activate
95108def test_upload_with_retry ():
You can’t perform that action at this time.
0 commit comments