Skip to content

Commit b989d5d

Browse files
committed
fix a bug in io.put, when key is None and extra.params is not empty
1 parent ace4a75 commit b989d5d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

qiniu/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def put(uptoken, key, data, extra=None):
3030
extra = PutExtra()
3131

3232
if extra.params:
33-
for key in extra.params:
34-
fields[key] = str(extra.params[key])
33+
for k in extra.params:
34+
fields[k] = str(extra.params[k])
3535

3636
if extra.check_crc:
3737
fields["crc32"] = str(extra.crc32)

qiniu/test/io_test.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
policy = rs.PutPolicy(bucket_name)
2222
extra = io.PutExtra()
2323
extra.mime_type = "text/plain"
24+
extra.params = {'x:a':'a'}
2425

2526
def r(length):
2627
lib = string.ascii_uppercase
@@ -36,23 +37,26 @@ def test_put():
3637
extra.crc32 = binascii.crc32(data) & 0xFFFFFFFF
3738
ret, err = io.put(policy.token(), key, data, extra)
3839
assert err is None
40+
assert ret['key'] == key
3941

4042
def test_put_same_crc():
4143
key = "test_%s" % r(9)
4244
data = "hello bubby!"
4345
extra.check_crc = 2
4446
ret, err = io.put(policy.token(), key, data, extra)
4547
assert err is None
48+
assert ret['key'] == key
4649

4750
def test_put_no_key():
4851
data = r(100)
49-
ret, err = io.put(policy.token(), key=None, data=data)
52+
ret, err = io.put(policy.token(), key=None, data=data, extra)
5053
assert err is None
54+
assert ret['hash'] == ret['key']
5155

5256
def test_put_unicode1():
5357
key = "test_%s" % r(9) + '你好'
5458
data = key
55-
ret, err = io.put(policy.token(), key, data)
59+
ret, err = io.put(policy.token(), key, data, extra)
5660
assert err is None
5761
assert ret[u'key'].endswith(u'你好')
5862

@@ -86,12 +90,14 @@ def test_put_StringIO():
8690
data = cStringIO.StringIO('hello buddy!')
8791
ret, err = io.put(policy.token(), key, data)
8892
assert err is None
93+
assert ret['key'] == key
8994

9095
def test_put_urlopen():
9196
key = "test_%s" % r(9)
9297
data = urllib.urlopen('http://cheneya.qiniudn.com/hello_jpg')
9398
ret, err = io.put(policy.token(), key, data)
9499
assert err is None
100+
assert ret['key'] == key
95101

96102
def test_put_no_length():
97103
class test_reader(object):
@@ -113,6 +119,7 @@ def read(self, n=None):
113119
extra.crc32 = binascii.crc32('abc') & 0xFFFFFFFF
114120
ret, err = io.put(policy.token(), key, data, extra)
115121
assert err is None
122+
assert ret['key'] == key
116123

117124
test_put()
118125
test_put_same_crc()
@@ -132,7 +139,7 @@ def test_put_file(self):
132139
extra.check_crc = 1
133140
ret, err = io.put_file(policy.token(), key, localfile, extra)
134141
assert err is None
135-
assert ret is not None
142+
assert ret['key'] == key
136143

137144
def test_put_crc_fail(self):
138145
key = "test_%s" % r(9)

0 commit comments

Comments
 (0)