@@ -635,7 +635,7 @@ def test_media_io_base_download_unknown_media_size(self):
635
635
BATCH_RESPONSE = b"""--batch_foobarbaz
636
636
Content-Type: application/http
637
637
Content-Transfer-Encoding: binary
638
- Content-ID: <randomness+ 1>
638
+ Content-ID: <randomness + 1>
639
639
640
640
HTTP/1.1 200 OK
641
641
Content-Type: application/json
@@ -645,7 +645,7 @@ def test_media_io_base_download_unknown_media_size(self):
645
645
--batch_foobarbaz
646
646
Content-Type: application/http
647
647
Content-Transfer-Encoding: binary
648
- Content-ID: <randomness+ 2>
648
+ Content-ID: <randomness + 2>
649
649
650
650
HTTP/1.1 200 OK
651
651
Content-Type: application/json
@@ -657,7 +657,7 @@ def test_media_io_base_download_unknown_media_size(self):
657
657
BATCH_ERROR_RESPONSE = b"""--batch_foobarbaz
658
658
Content-Type: application/http
659
659
Content-Transfer-Encoding: binary
660
- Content-ID: <randomness+ 1>
660
+ Content-ID: <randomness + 1>
661
661
662
662
HTTP/1.1 200 OK
663
663
Content-Type: application/json
@@ -667,7 +667,7 @@ def test_media_io_base_download_unknown_media_size(self):
667
667
--batch_foobarbaz
668
668
Content-Type: application/http
669
669
Content-Transfer-Encoding: binary
670
- Content-ID: <randomness+ 2>
670
+ Content-ID: <randomness + 2>
671
671
672
672
HTTP/1.1 403 Access Not Configured
673
673
Content-Type: application/json
@@ -693,7 +693,7 @@ def test_media_io_base_download_unknown_media_size(self):
693
693
BATCH_RESPONSE_WITH_401 = b"""--batch_foobarbaz
694
694
Content-Type: application/http
695
695
Content-Transfer-Encoding: binary
696
- Content-ID: <randomness+ 1>
696
+ Content-ID: <randomness + 1>
697
697
698
698
HTTP/1.1 401 Authorization Required
699
699
Content-Type: application/json
@@ -704,7 +704,7 @@ def test_media_io_base_download_unknown_media_size(self):
704
704
--batch_foobarbaz
705
705
Content-Type: application/http
706
706
Content-Transfer-Encoding: binary
707
- Content-ID: <randomness+ 2>
707
+ Content-ID: <randomness + 2>
708
708
709
709
HTTP/1.1 200 OK
710
710
Content-Type: application/json
@@ -716,7 +716,7 @@ def test_media_io_base_download_unknown_media_size(self):
716
716
BATCH_SINGLE_RESPONSE = b"""--batch_foobarbaz
717
717
Content-Type: application/http
718
718
Content-Transfer-Encoding: binary
719
- Content-ID: <randomness+ 1>
719
+ Content-ID: <randomness + 1>
720
720
721
721
HTTP/1.1 200 OK
722
722
Content-Type: application/json
@@ -1211,6 +1211,39 @@ def test_execute_request_body(self):
1211
1211
header = parts [1 ].splitlines ()[1 ]
1212
1212
self .assertEqual ('Content-Type: application/http' , header )
1213
1213
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
+
1214
1247
def test_execute_initial_refresh_oauth2 (self ):
1215
1248
batch = BatchHttpRequest ()
1216
1249
callbacks = Callbacks ()
0 commit comments