Refactor nonexistent bucket tests.

They can use a fixed name, nuke_prefixed_buckets guarantees the
bucket doesn't exist. Use assert_raises and check details of the
error. Move near existing non-existent bucket test.
This commit is contained in:
Tommi Virtanen 2011-06-10 10:20:36 -07:00
parent c7816632b9
commit a85204a0e5

View file

@ -225,6 +225,26 @@ def test_bucket_notexist():
eq(e.error_code, 'NoSuchBucket') eq(e.error_code, 'NoSuchBucket')
def test_bucket_delete_notexist():
name = '{prefix}foo'.format(prefix=prefix)
print 'Trying bucket {name!r}'.format(name=name)
e = assert_raises(boto.exception.S3ResponseError, s3.main.delete_bucket, name)
eq(e.status, 404)
eq(e.reason, 'Not Found')
eq(e.error_code, 'NoSuchBucket')
def test_object_write_to_nonexist_bucket():
name = '{prefix}foo'.format(prefix=prefix)
print 'Trying bucket {name!r}'.format(name=name)
bucket = s3.main.get_bucket(name, validate=False)
key = bucket.new_key('foo123bar')
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'foo')
eq(e.status, 404)
eq(e.reason, 'Not Found')
eq(e.error_code, 'NoSuchBucket')
def test_bucket_create_delete(): def test_bucket_create_delete():
name = '{prefix}foo'.format(prefix=prefix) name = '{prefix}foo'.format(prefix=prefix)
print 'Trying bucket {name!r}'.format(name=name) print 'Trying bucket {name!r}'.format(name=name)
@ -844,24 +864,6 @@ def test_bucket_create_naming_good_contains_period():
def test_bucket_create_naming_good_contains_hyphen(): def test_bucket_create_naming_good_contains_hyphen():
check_good_bucket_name('aaa-111') check_good_bucket_name('aaa-111')
def test_bucket_delete_notexist():
name = get_new_bucket_name()
try:
bucket = s3.main.delete_bucket(name)
raise RuntimeError("S3 implementation allowed us to delete a bucket that shouldn't exist")
except boto.exception.S3ResponseError, e:
pass
def test_object_write_to_nonexist_bucket():
name = get_new_bucket_name()
bucket = s3.main.get_bucket(name, validate=False)
key = bucket.new_key('foo123bar')
try:
key.set_contents_from_string('foo')
raise RuntimeError("S3 implementation allowed us to write a key to a bucket that shouldn't exist")
except boto.exception.S3ResponseError, e:
pass
def test_object_copy_same_bucket(): def test_object_copy_same_bucket():
bucket = get_new_bucket() bucket = get_new_bucket()
key = bucket.new_key('foo123bar') key = bucket.new_key('foo123bar')