forked from TrueCloudLab/s3-tests
Refactor to share code, hide counter implementation.
This commit is contained in:
parent
19ac38791c
commit
c7816632b9
1 changed files with 18 additions and 12 deletions
30
test_s3.py
30
test_s3.py
|
@ -153,6 +153,21 @@ def teardown():
|
||||||
bucket_counter = itertools.count(1)
|
bucket_counter = itertools.count(1)
|
||||||
|
|
||||||
|
|
||||||
|
def get_new_bucket_name():
|
||||||
|
"""
|
||||||
|
Get a bucket name that probably does not exist.
|
||||||
|
|
||||||
|
We make every attempt to use a unique random prefix, so if a
|
||||||
|
bucket by this name happens to exist, it's ok if tests give
|
||||||
|
false negatives.
|
||||||
|
"""
|
||||||
|
name = '{prefix}{num}'.format(
|
||||||
|
prefix=prefix,
|
||||||
|
num=next(bucket_counter),
|
||||||
|
)
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
def get_new_bucket(connection=None):
|
def get_new_bucket(connection=None):
|
||||||
"""
|
"""
|
||||||
Get a bucket that exists and is empty.
|
Get a bucket that exists and is empty.
|
||||||
|
@ -162,10 +177,7 @@ def get_new_bucket(connection=None):
|
||||||
"""
|
"""
|
||||||
if connection is None:
|
if connection is None:
|
||||||
connection = s3.main
|
connection = s3.main
|
||||||
name = '{prefix}{num}'.format(
|
name = get_new_bucket_name()
|
||||||
prefix=prefix,
|
|
||||||
num=next(bucket_counter),
|
|
||||||
)
|
|
||||||
# the only way for this to fail with a pre-existing bucket is if
|
# the only way for this to fail with a pre-existing bucket is if
|
||||||
# someone raced us between setup nuke_prefixed_buckets and here;
|
# someone raced us between setup nuke_prefixed_buckets and here;
|
||||||
# ignore that as astronomically unlikely
|
# ignore that as astronomically unlikely
|
||||||
|
@ -833,10 +845,7 @@ 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():
|
def test_bucket_delete_notexist():
|
||||||
name = '{prefix}{num}'.format(
|
name = get_new_bucket_name()
|
||||||
prefix=prefix,
|
|
||||||
num=next(bucket_counter),
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
bucket = s3.main.delete_bucket(name)
|
bucket = s3.main.delete_bucket(name)
|
||||||
raise RuntimeError("S3 implementation allowed us to delete a bucket that shouldn't exist")
|
raise RuntimeError("S3 implementation allowed us to delete a bucket that shouldn't exist")
|
||||||
|
@ -844,10 +853,7 @@ def test_bucket_delete_notexist():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_object_write_to_nonexist_bucket():
|
def test_object_write_to_nonexist_bucket():
|
||||||
name = '{prefix}{num}'.format(
|
name = get_new_bucket_name()
|
||||||
prefix=prefix,
|
|
||||||
num=next(bucket_counter),
|
|
||||||
)
|
|
||||||
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')
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue