add several test_object_set_get_metadata_* tests

This commit is contained in:
Stephon Striplin 2011-07-11 12:14:38 -07:00
parent 56aeecce8c
commit 1db99c0b0e

View file

@ -18,6 +18,8 @@ from nose.plugins.attrib import attr
from utils import assert_raises from utils import assert_raises
import AnonymousAuth import AnonymousAuth
from email.header import decode_header
NONEXISTENT_EMAIL = 'doesnotexist@dreamhost.com.invalid' NONEXISTENT_EMAIL = 'doesnotexist@dreamhost.com.invalid'
s3 = bunch.Bunch() s3 = bunch.Bunch()
@ -298,28 +300,100 @@ def test_object_write_read_update_read_delete():
key.delete() key.delete()
def test_object_set_get_metadata(): def _set_get_metadata(metadata, bucket=None):
if bucket is None:
bucket = get_new_bucket() bucket = get_new_bucket()
key = boto.s3.key.Key(bucket) key = boto.s3.key.Key(bucket)
key.key = ('foo') key.key = ('foo')
key.set_metadata('meta1', 'mymeta') key.set_metadata('meta1', metadata)
key.set_contents_from_string('bar') key.set_contents_from_string('bar')
key2 = bucket.get_key('foo') key2 = bucket.get_key('foo')
got = key2.get_metadata('meta1') return key2.get_metadata('meta1')
def test_object_set_get_metadata_none_to_good():
got = _set_get_metadata('mymeta')
eq(got, 'mymeta') eq(got, 'mymeta')
def test_object_set_get_metadata_empty(): def test_object_set_get_metadata_none_to_empty():
bucket = get_new_bucket() got = _set_get_metadata('')
key = boto.s3.key.Key(bucket)
key.key = ('foo')
key.set_metadata('meta1', '')
key.set_contents_from_string('bar')
key2 = bucket.get_key('foo')
got = key2.get_metadata('meta1')
eq(got, '') eq(got, '')
def test_object_set_get_metadata_overwrite_to_good():
bucket = get_new_bucket()
got = _set_get_metadata('oldmeta', bucket)
eq(got, 'oldmeta')
got = _set_get_metadata('newmeta', bucket)
eq(got, 'newmeta')
def test_object_set_get_metadata_overwrite_to_empty():
bucket = get_new_bucket()
got = _set_get_metadata('oldmeta', bucket)
eq(got, 'oldmeta')
got = _set_get_metadata('', bucket)
eq(got, '')
def _set_get_metadata_unreadable(metadata, bucket=None):
got = _set_get_metadata(metadata, bucket)
got = decode_header(got)
return got
@attr('fails_on_dho')
def test_object_set_get_metadata_empty_to_unreadable_prefix():
metadata = '\x04w'
got = _set_get_metadata_unreadable(metadata)
eq(got, [(metadata, 'utf-8')])
@attr('fails_on_dho')
def test_object_set_get_metadata_empty_to_unreadable_suffix():
metadata = 'h\x04'
got = _set_get_metadata_unreadable(metadata)
eq(got, [(metadata, 'utf-8')])
@attr('fails_on_dho')
def test_object_set_get_metadata_empty_to_unreadable_infix():
metadata = 'h\x04w'
got = _set_get_metadata_unreadable(metadata)
eq(got, [(metadata, 'utf-8')])
@attr('fails_on_dho')
def test_object_set_get_metadata_overwrite_to_unreadable_prefix():
metadata = '\x04w'
got = _set_get_metadata_unreadable(metadata)
eq(got, [(metadata, 'utf-8')])
metadata2 = '\x05w'
got2 = _set_get_metadata_unreadable(metadata2)
eq(got2, [(metadata2, 'utf-8')])
@attr('fails_on_dho')
def test_object_set_get_metadata_overwrite_to_unreadable_suffix():
metadata = 'h\x04'
got = _set_get_metadata_unreadable(metadata)
eq(got, [(metadata, 'utf-8')])
metadata2 = 'h\x05'
got2 = _set_get_metadata_unreadable(metadata2)
eq(got2, [(metadata2, 'utf-8')])
@attr('fails_on_dho')
def test_object_set_get_metadata_overwrite_to_unreadable_infix():
metadata = 'h\x04w'
got = _set_get_metadata_unreadable(metadata)
eq(got, [(metadata, 'utf-8')])
metadata2 = 'h\x05w'
got2 = _set_get_metadata_unreadable(metadata2)
eq(got2, [(metadata2, 'utf-8')])
def test_object_write_file(): def test_object_write_file():
# boto Key.set_contents_from_file / .send_file uses Expect: # boto Key.set_contents_from_file / .send_file uses Expect:
# 100-Continue, so this test exercises that (though a bit too # 100-Continue, so this test exercises that (though a bit too