@@ -635,7 +635,7 @@ def test_media_io_base_download_unknown_media_size(self):
635635BATCH_RESPONSE = b"""--batch_foobarbaz
636636Content-Type: application/http
637637Content-Transfer-Encoding: binary
638- Content-ID: <randomness+ 1>
638+ Content-ID: <randomness + 1>
639639
640640HTTP/1.1 200 OK
641641Content-Type: application/json
@@ -645,7 +645,7 @@ def test_media_io_base_download_unknown_media_size(self):
645645--batch_foobarbaz
646646Content-Type: application/http
647647Content-Transfer-Encoding: binary
648- Content-ID: <randomness+ 2>
648+ Content-ID: <randomness + 2>
649649
650650HTTP/1.1 200 OK
651651Content-Type: application/json
@@ -657,7 +657,7 @@ def test_media_io_base_download_unknown_media_size(self):
657657BATCH_ERROR_RESPONSE = b"""--batch_foobarbaz
658658Content-Type: application/http
659659Content-Transfer-Encoding: binary
660- Content-ID: <randomness+ 1>
660+ Content-ID: <randomness + 1>
661661
662662HTTP/1.1 200 OK
663663Content-Type: application/json
@@ -667,7 +667,7 @@ def test_media_io_base_download_unknown_media_size(self):
667667--batch_foobarbaz
668668Content-Type: application/http
669669Content-Transfer-Encoding: binary
670- Content-ID: <randomness+ 2>
670+ Content-ID: <randomness + 2>
671671
672672HTTP/1.1 403 Access Not Configured
673673Content-Type: application/json
@@ -693,7 +693,7 @@ def test_media_io_base_download_unknown_media_size(self):
693693BATCH_RESPONSE_WITH_401 = b"""--batch_foobarbaz
694694Content-Type: application/http
695695Content-Transfer-Encoding: binary
696- Content-ID: <randomness+ 1>
696+ Content-ID: <randomness + 1>
697697
698698HTTP/1.1 401 Authorization Required
699699Content-Type: application/json
@@ -704,7 +704,7 @@ def test_media_io_base_download_unknown_media_size(self):
704704--batch_foobarbaz
705705Content-Type: application/http
706706Content-Transfer-Encoding: binary
707- Content-ID: <randomness+ 2>
707+ Content-ID: <randomness + 2>
708708
709709HTTP/1.1 200 OK
710710Content-Type: application/json
@@ -716,7 +716,7 @@ def test_media_io_base_download_unknown_media_size(self):
716716BATCH_SINGLE_RESPONSE = b"""--batch_foobarbaz
717717Content-Type: application/http
718718Content-Transfer-Encoding: binary
719- Content-ID: <randomness+ 1>
719+ Content-ID: <randomness + 1>
720720
721721HTTP/1.1 200 OK
722722Content-Type: application/json
@@ -1211,6 +1211,39 @@ def test_execute_request_body(self):
12111211 header = parts [1 ].splitlines ()[1 ]
12121212 self .assertEqual ('Content-Type: application/http' , header )
12131213
1214+ def test_execute_request_body_with_custom_long_request_ids (self ):
1215+ batch = BatchHttpRequest ()
1216+
1217+ batch .add (self .request1 , request_id = 'abc' * 20 )
1218+ batch .add (self .request2 , request_id = 'def' * 20 )
1219+ http = HttpMockSequence ([
1220+ ({'status' : '200' ,
1221+ 'content-type' : 'multipart/mixed; boundary="batch_foobarbaz"' },
1222+ 'echo_request_body' ),
1223+ ])
1224+ try :
1225+ batch .execute (http = http )
1226+ self .fail ('Should raise exception' )
1227+ except BatchError as e :
1228+ boundary , _ = e .content .split (None , 1 )
1229+ self .assertEqual ('--' , boundary [:2 ])
1230+ parts = e .content .split (boundary )
1231+ self .assertEqual (4 , len (parts ))
1232+ self .assertEqual ('' , parts [0 ])
1233+ self .assertEqual ('--' , parts [3 ].rstrip ())
1234+ for partindex , request_id in ((1 , 'abc' * 20 ), (2 , 'def' * 20 )):
1235+ lines = parts [partindex ].splitlines ()
1236+ for n , line in enumerate (lines ):
1237+ if line .startswith ('Content-ID:' ):
1238+ # assert correct header folding
1239+ self .assertTrue (line .endswith ('+' ), line )
1240+ header_continuation = lines [n + 1 ]
1241+ self .assertEqual (
1242+ header_continuation ,
1243+ ' %s>' % request_id ,
1244+ header_continuation
1245+ )
1246+
12141247 def test_execute_initial_refresh_oauth2 (self ):
12151248 batch = BatchHttpRequest ()
12161249 callbacks = Callbacks ()
0 commit comments