@@ -78,6 +78,13 @@ def test_path_normal(self):
78
78
key = self ._makeOne (bucket , KEY )
79
79
self .assertEqual (key .path , '/b/name/o/%s' % KEY )
80
80
81
+ def test_path_w_slash_in_name (self ):
82
+ KEY = 'parent/child'
83
+ connection = _Connection ()
84
+ bucket = _Bucket (connection )
85
+ key = self ._makeOne (bucket , KEY )
86
+ self .assertEqual (key .path , '/b/name/o/parent%2Fchild' )
87
+
81
88
def test_public_url (self ):
82
89
KEY = 'key'
83
90
connection = _Connection ()
@@ -87,6 +94,15 @@ def test_public_url(self):
87
94
'http://commondatastorage.googleapis.com/name/%s' %
88
95
KEY )
89
96
97
+ def test_public_url_w_slash_in_name (self ):
98
+ KEY = 'parent/child'
99
+ connection = _Connection ()
100
+ bucket = _Bucket (connection )
101
+ key = self ._makeOne (bucket , KEY )
102
+ self .assertEqual (
103
+ key .public_url ,
104
+ 'http://commondatastorage.googleapis.com/name/parent%2Fchild' )
105
+
90
106
def test_generate_signed_url_w_default_met
67E6
hod (self ):
91
107
KEY = 'key'
92
108
EXPIRATION = '2014-10-16T20:34:37Z'
@@ -99,6 +115,19 @@ def test_generate_signed_url_w_default_method(self):
99
115
self .assertEqual (connection ._signed ,
100
116
[('/name/key' , EXPIRATION , {'method' : 'GET' })])
101
117
118
+ def test_generate_signed_url_w_slash_in_name (self ):
119
+ KEY = 'parent/child'
120
+ EXPIRATION = '2014-10-16T20:34:37Z'
121
+ connection = _Connection ()
122
+ bucket = _Bucket (connection )
123
+ key = self ._makeOne (bucket , KEY )
124
+ self .assertEqual (key .generate_signed_url (EXPIRATION ),
125
+ 'http://example.com/abucket/akey?Signature=DEADBEEF'
126
+ '&Expiration=2014-10-16T20:34:37Z' )
127
+ self .assertEqual (connection ._signed ,
128
+ [('/name/parent%2Fchild' ,
129
+ EXPIRATION , {'method': 'GET' })])
130
+
102
131
def test_generate_signed_url_w_explicit_method (self ):
103
132
KEY = 'key'
104
133
EXPIRATION = '2014-10-16T20:34:37Z'
@@ -238,6 +267,52 @@ def test_upload_from_file(self):
238
267
self .assertEqual (rq [2 ]['data' ], DATA [5 :])
239
268
self .assertEqual (rq [2 ]['headers' ], {'Content-Range' : 'bytes 5-5/6' })
240
269
270
+ def test_upload_from_file_w_slash_in_name (self ):
271
+ from tempfile import NamedTemporaryFile
272
+ from urlparse import parse_qsl
273
+ from urlparse import urlsplit
274
+ KEY = 'parent/child'
275
+ UPLOAD_URL = 'http://example.com/upload/name/parent%2Fchild'
276
+ DATA = 'ABCDEF'
277
+ loc_response = {'location' : UPLOAD_URL }
278
+ chunk1_response = {}
279
+ chunk2_response = {}
280
+ connection = _Connection (
281
+ (loc_response , '' ),
282
+ (chunk1_response , '' ),
283
+ (chunk2_response , '' ),
284
+ )
285
+ bucket = _Bucket (connection )
286
+ key = self ._makeOne (bucket , KEY )
287
+ key .CHUNK_SIZE = 5
288
+ with NamedTemporaryFile () as fh :
289
+ fh .write (DATA )
290
+ fh .flush ()
291
+ key .upload_from_file (fh , rewind = True )
292
+ rq = connection ._requested
293
+ self .assertEqual (len (rq ), 3 )
294
+ self .assertEqual (rq [0 ]['method' ], 'POST' )
295
+ uri = rq [0 ]['url' ]
296
+ scheme , netloc , path , qs , _ = urlsplit (uri )
297
+ self .assertEqual (scheme , 'http' )
298
+ self .assertEqual (netloc , 'example.com' )
299
+ self .assertEqual (path , '/b/name/o' )
300
+ self .assertEqual (dict (parse_qsl (qs )),
301
+ {'uploadType' : 'resumable' , 'name' : 'parent%2Fchild' })
302
+ self .assertEqual (rq [0 ]['headers' ],
303
+ {'X-Upload-Content-Length' : 6 ,
304
+ 'X-Upload-Content-Type' : 'application/unknown' })
305
+ self .assertEqual (rq [1 ]['method' ], 'POST' )
306
+ self .assertEqual (rq [1 ]['url' ], UPLOAD_URL )
307
+ self .assertEqual (rq [1 ]['content_type' ], 'text/plain' )
308
+ self .assertEqual (rq [1 ]['data' ], DATA [:5 ])
309
+ self .assertEqual (rq [1 ]['headers' ], {'Content-Range' : 'bytes 0-4/6' })
310
+ self .assertEqual (rq [2 ]['method' ], 'POST' )
311
+ self .assertEqual (rq [2 ]['url' ], UPLOAD_URL )
312
+ self .assertEqual (rq [2 ]['content_type' ], 'text/plain' )
313
+ self .assertEqual (rq [2 ]['data' ], DATA [5 :])
314
+ self .assertEqual (rq [2 ]['headers' ], {'Content-Range' : 'bytes 5-5/6' })
315
+
241
316
def test_upload_from_filename (self ):
242
317
from tempfile import NamedTemporaryFile
243
318
from urlparse import parse_qsl
0 commit comments