mirror of
https://github.com/ceph/s3-tests.git
synced 2024-11-22 19:29:48 +00:00
Fix bug where prefix was None.
Accessing a non-constant global from another module is tricky, as the import binds to the original object. Rebinding the name in the original module does not change it in importers. Use a getter as a quick workaround.
This commit is contained in:
parent
02a4c82dfa
commit
91a39caf46
2 changed files with 18 additions and 12 deletions
|
@ -13,6 +13,9 @@ config = bunch.Bunch()
|
||||||
# this will be assigned by setup()
|
# this will be assigned by setup()
|
||||||
prefix = None
|
prefix = None
|
||||||
|
|
||||||
|
def get_prefix():
|
||||||
|
assert prefix is not None
|
||||||
|
return prefix
|
||||||
|
|
||||||
def choose_bucket_prefix(template, max_len=30):
|
def choose_bucket_prefix(template, max_len=30):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -22,7 +22,7 @@ from . import (
|
||||||
get_new_bucket,
|
get_new_bucket,
|
||||||
s3,
|
s3,
|
||||||
config,
|
config,
|
||||||
prefix,
|
get_prefix,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ def test_bucket_list_empty():
|
||||||
eq(l, [])
|
eq(l, [])
|
||||||
|
|
||||||
def test_bucket_notexist():
|
def test_bucket_notexist():
|
||||||
name = '{prefix}foo'.format(prefix=prefix)
|
name = '{prefix}foo'.format(prefix=get_prefix())
|
||||||
print 'Trying bucket {name!r}'.format(name=name)
|
print 'Trying bucket {name!r}'.format(name=name)
|
||||||
e = assert_raises(boto.exception.S3ResponseError, s3.main.get_bucket, name)
|
e = assert_raises(boto.exception.S3ResponseError, s3.main.get_bucket, name)
|
||||||
eq(e.status, 404)
|
eq(e.status, 404)
|
||||||
|
@ -70,7 +70,7 @@ def test_bucket_notexist():
|
||||||
|
|
||||||
|
|
||||||
def test_bucket_delete_notexist():
|
def test_bucket_delete_notexist():
|
||||||
name = '{prefix}foo'.format(prefix=prefix)
|
name = '{prefix}foo'.format(prefix=get_prefix())
|
||||||
print 'Trying bucket {name!r}'.format(name=name)
|
print 'Trying bucket {name!r}'.format(name=name)
|
||||||
e = assert_raises(boto.exception.S3ResponseError, s3.main.delete_bucket, name)
|
e = assert_raises(boto.exception.S3ResponseError, s3.main.delete_bucket, name)
|
||||||
eq(e.status, 404)
|
eq(e.status, 404)
|
||||||
|
@ -91,7 +91,7 @@ def test_bucket_delete_nonempty():
|
||||||
eq(e.error_code, 'BucketNotEmpty')
|
eq(e.error_code, 'BucketNotEmpty')
|
||||||
|
|
||||||
def test_object_write_to_nonexist_bucket():
|
def test_object_write_to_nonexist_bucket():
|
||||||
name = '{prefix}foo'.format(prefix=prefix)
|
name = '{prefix}foo'.format(prefix=get_prefix())
|
||||||
print 'Trying bucket {name!r}'.format(name=name)
|
print 'Trying bucket {name!r}'.format(name=name)
|
||||||
bucket = s3.main.get_bucket(name, validate=False)
|
bucket = s3.main.get_bucket(name, validate=False)
|
||||||
key = bucket.new_key('foo123bar')
|
key = bucket.new_key('foo123bar')
|
||||||
|
@ -102,7 +102,7 @@ def test_object_write_to_nonexist_bucket():
|
||||||
|
|
||||||
|
|
||||||
def test_bucket_create_delete():
|
def test_bucket_create_delete():
|
||||||
name = '{prefix}foo'.format(prefix=prefix)
|
name = '{prefix}foo'.format(prefix=get_prefix())
|
||||||
print 'Trying bucket {name!r}'.format(name=name)
|
print 'Trying bucket {name!r}'.format(name=name)
|
||||||
bucket = s3.main.create_bucket(name)
|
bucket = s3.main.create_bucket(name)
|
||||||
# make sure it's actually there
|
# make sure it's actually there
|
||||||
|
@ -317,7 +317,7 @@ def check_good_bucket_name(name, _prefix=None):
|
||||||
# their own setup/teardown nukes, with their custom prefix; this
|
# their own setup/teardown nukes, with their custom prefix; this
|
||||||
# should be very rare
|
# should be very rare
|
||||||
if _prefix is None:
|
if _prefix is None:
|
||||||
_prefix = prefix
|
_prefix = get_prefix()
|
||||||
s3.main.create_bucket('{prefix}{name}'.format(
|
s3.main.create_bucket('{prefix}{name}'.format(
|
||||||
prefix=_prefix,
|
prefix=_prefix,
|
||||||
name=name,
|
name=name,
|
||||||
|
@ -325,6 +325,7 @@ def check_good_bucket_name(name, _prefix=None):
|
||||||
|
|
||||||
|
|
||||||
def _test_bucket_create_naming_good_long(length):
|
def _test_bucket_create_naming_good_long(length):
|
||||||
|
prefix = get_prefix()
|
||||||
assert len(prefix) < 255
|
assert len(prefix) < 255
|
||||||
num = length - len(prefix)
|
num = length - len(prefix)
|
||||||
s3.main.create_bucket('{prefix}{name}'.format(
|
s3.main.create_bucket('{prefix}{name}'.format(
|
||||||
|
@ -357,6 +358,7 @@ def test_bucket_create_naming_good_long_255():
|
||||||
_test_bucket_create_naming_good_long(255)
|
_test_bucket_create_naming_good_long(255)
|
||||||
|
|
||||||
def test_bucket_list_long_name():
|
def test_bucket_list_long_name():
|
||||||
|
prefix = get_prefix()
|
||||||
length = 251
|
length = 251
|
||||||
num = length - len(prefix)
|
num = length - len(prefix)
|
||||||
bucket = s3.main.create_bucket('{prefix}{name}'.format(
|
bucket = s3.main.create_bucket('{prefix}{name}'.format(
|
||||||
|
@ -387,6 +389,7 @@ def test_bucket_create_naming_dns_underscore():
|
||||||
|
|
||||||
|
|
||||||
def test_bucket_create_naming_dns_long():
|
def test_bucket_create_naming_dns_long():
|
||||||
|
prefix = get_prefix()
|
||||||
assert len(prefix) < 50
|
assert len(prefix) < 50
|
||||||
num = 100 - len(prefix)
|
num = 100 - len(prefix)
|
||||||
check_good_bucket_name(num * 'a')
|
check_good_bucket_name(num * 'a')
|
||||||
|
@ -1119,21 +1122,21 @@ def test_list_buckets_bad_auth():
|
||||||
# control the initial character of the bucket name
|
# control the initial character of the bucket name
|
||||||
@attr('fails_on_rgw')
|
@attr('fails_on_rgw')
|
||||||
@nose.with_setup(
|
@nose.with_setup(
|
||||||
setup=lambda: nuke_prefixed_buckets(prefix='a'+prefix),
|
setup=lambda: nuke_prefixed_buckets(prefix='a'+get_prefix()),
|
||||||
teardown=lambda: nuke_prefixed_buckets(prefix='a'+prefix),
|
teardown=lambda: nuke_prefixed_buckets(prefix='a'+get_prefix()),
|
||||||
)
|
)
|
||||||
def test_bucket_create_naming_good_starts_alpha():
|
def test_bucket_create_naming_good_starts_alpha():
|
||||||
check_good_bucket_name('foo', _prefix='a'+prefix)
|
check_good_bucket_name('foo', _prefix='a'+get_prefix())
|
||||||
|
|
||||||
# this test goes outside the user-configure prefix because it needs to
|
# this test goes outside the user-configure prefix because it needs to
|
||||||
# control the initial character of the bucket name
|
# control the initial character of the bucket name
|
||||||
@attr('fails_on_rgw')
|
@attr('fails_on_rgw')
|
||||||
@nose.with_setup(
|
@nose.with_setup(
|
||||||
setup=lambda: nuke_prefixed_buckets(prefix='0'+prefix),
|
setup=lambda: nuke_prefixed_buckets(prefix='0'+get_prefix()),
|
||||||
teardown=lambda: nuke_prefixed_buckets(prefix='0'+prefix),
|
teardown=lambda: nuke_prefixed_buckets(prefix='0'+get_prefix()),
|
||||||
)
|
)
|
||||||
def test_bucket_create_naming_good_starts_digit():
|
def test_bucket_create_naming_good_starts_digit():
|
||||||
check_good_bucket_name('foo', _prefix='0'+prefix)
|
check_good_bucket_name('foo', _prefix='0'+get_prefix())
|
||||||
|
|
||||||
def test_bucket_create_naming_good_contains_period():
|
def test_bucket_create_naming_good_contains_period():
|
||||||
check_good_bucket_name('aaa.111')
|
check_good_bucket_name('aaa.111')
|
||||||
|
|
Loading…
Reference in a new issue