Skip to content

Commit

Permalink
update testcase.
Browse files Browse the repository at this point in the history
  • Loading branch information
huiguangjun committed Jul 20, 2022
1 parent e003043 commit 38d23d1
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 97 deletions.
15 changes: 8 additions & 7 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@
def random_string(n):
return ''.join(random.choice(string.ascii_lowercase) for i in range(n))

OSS_BUCKET = ''
OSS_BUCKET_BASE = ''
if OSS_TEST_BUCKET is None:
OSS_BUCKET = 'oss-python-sdk-'+random_string(10)
OSS_BUCKET_BASE = 'oss-python-sdk-'+random_string(6)
else:
OSS_BUCKET = OSS_TEST_BUCKET + random_string(10)
OSS_BUCKET_BASE = OSS_TEST_BUCKET + random_string(6)

def random_bytes(n):
return oss2.to_bytes(random_string(n))
Expand Down Expand Up @@ -174,18 +174,19 @@ def setUp(self):
global OSS_AUTH_VERSION
OSS_AUTH_VERSION = os.getenv('OSS_TEST_AUTH_VERSION')

self.bucket = oss2.Bucket(oss2.make_auth(OSS_ID, OSS_SECRET, OSS_AUTH_VERSION), OSS_ENDPOINT, OSS_BUCKET)
self.OSS_BUCKET = OSS_BUCKET_BASE + random_string(4)
self.bucket = oss2.Bucket(oss2.make_auth(OSS_ID, OSS_SECRET, OSS_AUTH_VERSION), OSS_ENDPOINT, self.OSS_BUCKET)

try:
self.bucket.create_bucket()
except:
pass

self.rsa_crypto_bucket = oss2.CryptoBucket(oss2.make_auth(OSS_ID, OSS_SECRET, OSS_AUTH_VERSION), OSS_ENDPOINT,
OSS_BUCKET, crypto_provider=oss2.RsaProvider(key_pair))
self.OSS_BUCKET, crypto_provider=oss2.RsaProvider(key_pair))

self.kms_crypto_bucket = oss2.CryptoBucket(oss2.make_auth(OSS_ID, OSS_SECRET, OSS_AUTH_VERSION), OSS_ENDPOINT,
OSS_BUCKET, crypto_provider=oss2.AliKMSProvider(OSS_ID, OSS_SECRET,
self.OSS_BUCKET, crypto_provider=oss2.AliKMSProvider(OSS_ID, OSS_SECRET,
OSS_REGION, OSS_CMK))

self.key_list = []
Expand All @@ -196,7 +197,7 @@ def tearDown(self):
oss2.utils.silently_remove(temp_file)

clean_and_delete_bucket(self.bucket)
clean_and_delete_bucket_by_prefix(OSS_BUCKET + "-test-")
clean_and_delete_bucket_by_prefix(self.OSS_BUCKET + "-test-")

def random_key(self, suffix=''):
key = self.prefix + random_string(12) + suffix
Expand Down
12 changes: 6 additions & 6 deletions tests/test_api_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
class TestApiBase(OssTestCase):
if OSS_CNAME:
def test_cname_bucket(self):
bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), OSS_CNAME, OSS_BUCKET, is_cname=True)
bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), OSS_CNAME, self.OSS_BUCKET, is_cname=True)
bucket.get_bucket_acl()

def test_cname_object(self):
bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), OSS_CNAME, OSS_BUCKET, is_cname=True)
bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), OSS_CNAME, self.OSS_BUCKET, is_cname=True)
bucket.put_object('hello.txt', 'hello world')

def test_https(self):
Expand Down Expand Up @@ -78,13 +78,13 @@ def test_check_endpoint(self):
'test-bucket')

def test_whitespace(self):
bucket = oss2.Bucket(oss2.Auth(OSS_ID, ' ' + OSS_SECRET + ' '), OSS_ENDPOINT, OSS_BUCKET)
bucket = oss2.Bucket(oss2.Auth(OSS_ID, ' ' + OSS_SECRET + ' '), OSS_ENDPOINT, self.OSS_BUCKET)
bucket.get_bucket_acl()

bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), ' ' + OSS_ENDPOINT + ' ', OSS_BUCKET)
bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), ' ' + OSS_ENDPOINT + ' ', self.OSS_BUCKET)
bucket.get_bucket_acl()

bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), OSS_ENDPOINT, ' ' + OSS_BUCKET + ' ')
bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), OSS_ENDPOINT, ' ' + self.OSS_BUCKET + ' ')
bucket.get_bucket_acl()

if sys.version_info >= (3, 3):
Expand All @@ -111,7 +111,7 @@ def do_request(session_self, req, timeout):

# 加app_name
assert_found = True
bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), OSS_ENDPOINT, OSS_BUCKET,
bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), OSS_ENDPOINT, self.OSS_BUCKET,
app_name=app)
self.assertRaises(oss2.exceptions.ClientError, bucket.get_bucket_acl)

Expand Down
10 changes: 5 additions & 5 deletions tests/test_async_fetch_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):

def test_async_fetch_task(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-async-fetch-task"
bucket_name = self.OSS_BUCKET + "-test-async-fetch-task"
bucket = oss2.Bucket(auth, self.endpoint, bucket_name)
bucket.create_bucket()

Expand Down Expand Up @@ -52,7 +52,7 @@ def test_async_fetch_task(self):

def test_async_fetch_task_with_few_argument(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-async-fetch-task"
bucket_name = self.OSS_BUCKET + "-test-async-fetch-task"
bucket = oss2.Bucket(auth, self.endpoint, bucket_name)
bucket.create_bucket()

Expand Down Expand Up @@ -80,7 +80,7 @@ def test_async_fetch_task_with_few_argument(self):

def test_fetch_success_callback_failed_state(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-async-fetch-task-callback"
bucket_name = self.OSS_BUCKET + "-test-async-fetch-task-callback"
bucket = oss2.Bucket(auth, self.endpoint, bucket_name)
bucket.create_bucket()

Expand Down Expand Up @@ -112,7 +112,7 @@ def test_fetch_success_callback_failed_state(self):

def test_failed_state(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-async-fetch-task-callback"
bucket_name = self.OSS_BUCKET + "-test-async-fetch-task-callback"
bucket = oss2.Bucket(auth, self.endpoint, bucket_name)
bucket.create_bucket()

Expand All @@ -134,7 +134,7 @@ def test_failed_state(self):

def test_ignore_same_key(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-async-fetch-task"
bucket_name = self.OSS_BUCKET + "-test-async-fetch-task"
bucket = oss2.Bucket(auth, self.endpoint, bucket_name)
bucket.create_bucket()

Expand Down
22 changes: 11 additions & 11 deletions tests/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class TestBucket(OssTestCase):
def test_bucket(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-bucket"
bucket_name = self.OSS_BUCKET + "-test-bucket"
bucket = oss2.Bucket(auth, OSS_ENDPOINT, bucket_name)

bucket.create_bucket(oss2.BUCKET_ACL_PRIVATE)
Expand All @@ -35,7 +35,7 @@ def test_bucket(self):

def test_bucket_with_storage_class(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-storage-class"
bucket_name = self.OSS_BUCKET + "-test-storage-class"
bucket = oss2.Bucket(auth, OSS_ENDPOINT, bucket_name)

bucket.create_bucket(oss2.BUCKET_ACL_PRIVATE, oss2.models.BucketCreateConfig(oss2.BUCKET_STORAGE_CLASS_IA))
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_bucket_with_storage_class(self):

def test_bucket_with_data_redundancy_type(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-redundancy-type"
bucket_name = self.OSS_BUCKET + "-test-redundancy-type"
bucket = oss2.Bucket(auth, OSS_ENDPOINT, bucket_name)

# LRS
Expand All @@ -86,7 +86,7 @@ def test_bucket_with_data_redundancy_type(self):

def test_acl(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-acl"
bucket_name = self.OSS_BUCKET + "-test-acl"
bucket = oss2.Bucket(auth, OSS_ENDPOINT, bucket_name)

bucket.create_bucket(oss2.BUCKET_ACL_PUBLIC_READ)
Expand All @@ -104,7 +104,7 @@ def test_acl(self):
bucket.delete_bucket()

def test_logging(self):
bucket_name = OSS_BUCKET + "-test-logging"
bucket_name = self.OSS_BUCKET + "-test-logging"
other_bucket = oss2.Bucket(self.bucket.auth, OSS_ENDPOINT, bucket_name)
other_bucket.create_bucket(oss2.BUCKET_ACL_PRIVATE)

Expand Down Expand Up @@ -560,7 +560,7 @@ def test_cors(self):

def test_bucket_stat(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-stat"
bucket_name = self.OSS_BUCKET + "-test-stat"
bucket = oss2.Bucket(auth, OSS_ENDPOINT, bucket_name)

bucket.create_bucket(oss2.BUCKET_ACL_PRIVATE)
Expand All @@ -587,7 +587,7 @@ def test_bucket_stat(self):

def test_bucket_stat_all_param(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-stat-all"
bucket_name = self.OSS_BUCKET + "-test-stat-all"
bucket = oss2.Bucket(auth, OSS_ENDPOINT, bucket_name)

bucket.create_bucket(oss2.BUCKET_ACL_PRIVATE)
Expand Down Expand Up @@ -627,7 +627,7 @@ def test_bucket_stat_all_param(self):

def test_bucket_info(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-info"
bucket_name = self.OSS_BUCKET + "-test-info"
bucket = oss2.Bucket(auth, OSS_ENDPOINT, bucket_name)

self.assertRaises(oss2.exceptions.NoSuchBucket, bucket.get_bucket_info)
Expand Down Expand Up @@ -801,14 +801,14 @@ def test_list_bucket_with_tagging(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
service = oss2.Service(auth, OSS_ENDPOINT)

bucket_name1 = OSS_BUCKET + "-test-with-tagging-1"
bucket_name1 = self.OSS_BUCKET + "-test-with-tagging-1"
bucket1 = oss2.Bucket(auth, OSS_ENDPOINT, bucket_name1)

bucket1.create_bucket(oss2.BUCKET_ACL_PRIVATE)

wait_meta_sync()

bucket_name2 = OSS_BUCKET + "-test-with-tagging-2"
bucket_name2 = self.OSS_BUCKET + "-test-with-tagging-2"
bucket2 = oss2.Bucket(auth, OSS_ENDPOINT, bucket_name2)

bucket2.create_bucket(oss2.BUCKET_ACL_PRIVATE)
Expand Down Expand Up @@ -851,7 +851,7 @@ def test_list_bucket_with_tagging(self):

def test_bucket_policy(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-policy"
bucket_name = self.OSS_BUCKET + "-test-policy"
bucket = oss2.Bucket(auth, OSS_ENDPOINT, bucket_name)

self.assertRaises(oss2.exceptions.NoSuchBucket, bucket.get_bucket_info)
Expand Down
14 changes: 7 additions & 7 deletions tests/test_bucket_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class TestBucketInventory(OssTestCase):
def setUp(self):
OssTestCase.setUp(self)
self.endpoint = OSS_ENDPOINT
bucket_name = OSS_BUCKET + "-test-inventory"
bucket_name = self.OSS_BUCKET + "-test-inventory"
self.bucket1 = oss2.Bucket(oss2.make_auth(OSS_ID, OSS_SECRET, OSS_AUTH_VERSION), self.endpoint, bucket_name)
self.bucket1.create_bucket()


def test_bucket_inventory(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
dest_bucket_name = OSS_BUCKET + "-test-inventory-dest"
dest_bucket_name = self.OSS_BUCKET + "-test-inventory-dest"
dest_bucket = oss2.Bucket(auth, self.endpoint, dest_bucket_name)
dest_bucket.create_bucket()

Expand Down Expand Up @@ -91,7 +91,7 @@ def test_error_bucket_encryption(self):

def test_list_few_bucket_inventory(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
dest_bucket_name = OSS_BUCKET + "-test-inventory-dest"
dest_bucket_name = self.OSS_BUCKET + "-test-inventory-dest"
dest_bucket = oss2.Bucket(auth, self.endpoint, dest_bucket_name)
dest_bucket.create_bucket()
time.sleep(5)
Expand All @@ -105,7 +105,7 @@ def test_list_few_bucket_inventory(self):
bucket_destination = InventoryBucketDestination(
account_id=OSS_INVENTORY_BUCKET_DESTINATION_ACCOUNT,
role_arn=OSS_INVENTORY_BUCKET_DESTINATION_ARN,
bucket=OSS_BUCKET,
bucket=self.OSS_BUCKET,
inventory_format=INVENTORY_FORMAT_CSV,
prefix="destination-prefix",
sse_kms_encryption=InventoryServerSideEncryptionKMS(OSS_CMK))
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_list_few_bucket_inventory(self):

def test_list_lot_bucket_inventory(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
dest_bucket_name = OSS_BUCKET + "-test-inventory-dest"
dest_bucket_name = self.OSS_BUCKET + "-test-inventory-dest"
dest_bucket = oss2.Bucket(auth, self.endpoint, dest_bucket_name)
dest_bucket.create_bucket()

Expand All @@ -152,7 +152,7 @@ def test_list_lot_bucket_inventory(self):
bucket_destination = InventoryBucketDestination(
account_id=OSS_INVENTORY_BUCKET_DESTINATION_ACCOUNT,
role_arn=OSS_INVENTORY_BUCKET_DESTINATION_ARN,
bucket=OSS_BUCKET,
bucket=self.OSS_BUCKET,
inventory_format=INVENTORY_FORMAT_CSV,
prefix="destination-prefix")

Expand Down Expand Up @@ -184,7 +184,7 @@ def test_list_lot_bucket_inventory(self):

def test_list_none_inventory(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
dest_bucket_name = OSS_BUCKET + "-test-none-inventory"
dest_bucket_name = self.OSS_BUCKET + "-test-none-inventory"
dest_bucket = oss2.Bucket(auth, self.endpoint, dest_bucket_name)
dest_bucket.create_bucket()
self.assertRaises(oss2.exceptions.NoSuchInventory, dest_bucket.list_bucket_inventory_configurations)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bucket_meta_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_1_bucket_meta_query(self):

def test_2_bucket_meta_query_aggregation(self):
auth = oss2.Auth(OSS_ID, OSS_SECRET)
dest_bucket_name = OSS_BUCKET + "-test-meta-query"
dest_bucket_name = self.OSS_BUCKET + "-test-meta-query"
dest_bucket = oss2.Bucket(auth, OSS_ENDPOINT, dest_bucket_name)
dest_bucket.create_bucket()

Expand Down
4 changes: 2 additions & 2 deletions tests/test_bucket_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
class TestBucketReplication(OssTestCase):
def setUp(self):
OssTestCase.setUp(self)
source_bucket_name = OSS_BUCKET + '-test-replica-source-' + random_string(10)
source_bucket_name = self.OSS_BUCKET + '-test-replica-source-' + random_string(10)
self.source_bucket = oss2.Bucket(oss2.make_auth(OSS_ID, OSS_SECRET, OSS_AUTH_VERSION), OSS_ENDPOINT, source_bucket_name)
self.source_bucket.create_bucket()

self.replica_endpoint = "oss-ap-south-1"
self.transfer_type = 'oss_acc'
self.replica_bucket_name = OSS_BUCKET + "-test-replica-dest-" + random_string(10)
self.replica_bucket_name = self.OSS_BUCKET + "-test-replica-dest-" + random_string(10)
self.replica_bucket = oss2.Bucket(oss2.make_auth(OSS_ID, OSS_SECRET, OSS_AUTH_VERSION), self.replica_endpoint + '.aliyuncs.com', self.replica_bucket_name)
self.replica_bucket.create_bucket()

Expand Down
8 changes: 4 additions & 4 deletions tests/test_bucket_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_bucket_versioning_wrong(self):

from oss2.models import BucketVersioningConfig
auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-bucket-versioning-wrong"
bucket_name = self.OSS_BUCKET + "-test-bucket-versioning-wrong"
bucket = oss2.Bucket(auth, self.endpoint, bucket_name)
bucket.create_bucket(oss2.BUCKET_ACL_PRIVATE)

Expand All @@ -35,7 +35,7 @@ def test_bucket_versioning(self):
from oss2.models import BucketVersioningConfig

auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-versioning"
bucket_name = self.OSS_BUCKET + "-test-versioning"
bucket = oss2.Bucket(auth, self.endpoint, bucket_name)

self.assertRaises(oss2.exceptions.NoSuchBucket, bucket.get_bucket_info)
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_list_object_versions_wrong(self):
from oss2.models import BucketVersioningConfig

auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-list-object-versions-wrong"
bucket_name = self.OSS_BUCKET + "-test-list-object-versions-wrong"
bucket = oss2.Bucket(auth, self.endpoint, bucket_name)

self.assertRaises(oss2.exceptions.NoSuchBucket, bucket.get_bucket_info)
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_list_object_versions_truncated(self):
from oss2.models import BatchDeleteObjectVersionList

auth = oss2.Auth(OSS_ID, OSS_SECRET)
bucket_name = OSS_BUCKET + "-test-list-object-versions-truncated"
bucket_name = self.OSS_BUCKET + "-test-list-object-versions-truncated"
bucket = oss2.Bucket(auth, self.endpoint, bucket_name)

bucket.create_bucket(oss2.BUCKET_ACL_PRIVATE)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_credentials_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setUp(self):
OssTestCase.setUp(self)
self.auth_server_host = self.create_fake_ecs_credentials_url()
self.endpoint = OSS_ENDPOINT
self.bucket_name = OSS_BUCKET + "-test-ecs-ram-role"
self.bucket_name = self.OSS_BUCKET + "-test-ecs-ram-role"

def tearDown(self):
OssTestCase.tearDown(self)
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_auth(self):
test_bucket.delete_object(object_name)
test_bucket.delete_bucket()

bucket_name = OSS_BUCKET + '-test-auth-bucket'
bucket_name = self.OSS_BUCKET + '-test-auth-bucket'
object_name = 'test-auth-obj'
auth1 = oss2.make_auth(OSS_ID, OSS_SECRET, oss2.AUTH_VERSION_1)
test_bucket2 = oss2.Bucket(auth1, OSS_ENDPOINT, bucket_name)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_crypto_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def test_crypto_object_incorrect_description(self):
provider_1 = RsaProvider(key_pair={'private_key': private_key_str_1, 'public_key': public_key_str_1},
passphrase=passphrase_1, mat_desc=mat_desc_1)
crypto_bucket_1 = oss2.CryptoBucket(oss2.make_auth(OSS_ID, OSS_SECRET, OSS_AUTH_VERSION), OSS_ENDPOINT,
OSS_BUCKET, crypto_provider=provider_1)
self.OSS_BUCKET, crypto_provider=provider_1)
private_key_2 = RSA.generate(2048)
public_key_2 = private_key_2.publickey()
passphrase_2 = random_string(6)
Expand All @@ -328,7 +328,7 @@ def test_crypto_object_incorrect_description(self):
provider_2 = RsaProvider(key_pair={'private_key': private_key_str_2, 'public_key': public_key_str_2},
passphrase=passphrase_2, mat_desc=mat_desc_2)
crypto_bucket_2 = oss2.CryptoBucket(oss2.make_auth(OSS_ID, OSS_SECRET, OSS_AUTH_VERSION), OSS_ENDPOINT,
OSS_BUCKET, crypto_provider=provider_2)
self.OSS_BUCKET, crypto_provider=provider_2)
key = self.random_key('.js')
content = random_bytes(1024)
crypto_bucket_1.put_object(key, content)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class TestIterator(OssTestCase):
def test_bucket_iterator(self):
service = oss2.Service(oss2.Auth(OSS_ID, OSS_SECRET), OSS_ENDPOINT)
self.assertTrue(OSS_BUCKET in (b.name for b in oss2.BucketIterator(service, max_keys=2)))
self.assertTrue(self.OSS_BUCKET in (b.name for b in oss2.BucketIterator(service, max_keys=2)))

def test_object_iterator(self):
prefix = self.random_key('/')
Expand Down
Loading

0 comments on commit 38d23d1

Please sign in to comment.