Skip to content

Commit

Permalink
fix a bug in io.put, when key is None and extra.params is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
SunRunAway committed Jul 3, 2013
1 parent ace4a75 commit b989d5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions qiniu/io.py
Expand Up @@ -30,8 +30,8 @@ def put(uptoken, key, data, extra=None):
extra = PutExtra()

if extra.params:
for key in extra.params:
fields[key] = str(extra.params[key])
for k in extra.params:
fields[k] = str(extra.params[k])

if extra.check_crc:
fields["crc32"] = str(extra.crc32)
Expand Down
13 changes: 10 additions & 3 deletions qiniu/test/io_test.py
Expand Up @@ -21,6 +21,7 @@
policy = rs.PutPolicy(bucket_name)
extra = io.PutExtra()
extra.mime_type = "text/plain"
extra.params = {'x:a':'a'}

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

def test_put_same_crc():
key = "test_%s" % r(9)
data = "hello bubby!"
extra.check_crc = 2
ret, err = io.put(policy.token(), key, data, extra)
assert err is None
assert ret['key'] == key

def test_put_no_key():
data = r(100)
ret, err = io.put(policy.token(), key=None, data=data)
ret, err = io.put(policy.token(), key=None, data=data, extra)
assert err is None
assert ret['hash'] == ret['key']

def test_put_unicode1():
key = "test_%s" % r(9) + '你好'
data = key
ret, err = io.put(policy.token(), key, data)
ret, err = io.put(policy.token(), key, data, extra)
assert err is None
assert ret[u'key'].endswith(u'你好')

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

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

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

test_put()
test_put_same_crc()
Expand All @@ -132,7 +139,7 @@ def test_put_file(self):
extra.check_crc = 1
ret, err = io.put_file(policy.token(), key, localfile, extra)
assert err is None
assert ret is not None
assert ret['key'] == key

def test_put_crc_fail(self):
key = "test_%s" % r(9)
Expand Down

0 comments on commit b989d5d

Please sign in to comment.