Best Python code snippet using localstack_python
test_bucket.py
Source:test_bucket.py
...16import random17def test_simple(h3):18 """List, create, delete a bucket."""19 assert h3.list_buckets() == []20 assert h3.create_bucket('b1') == True21 with pytest.raises(pyh3lib.H3ExistsError):22 h3.create_bucket('b1')23 bucket_info = h3.info_bucket('b1')24 assert bucket_info.stats == None25 assert type(bucket_info.creation) == float26 bucket_info = h3.info_bucket('b1', get_stats=True)27 assert bucket_info.stats != None28 assert bucket_info.stats.size == 029 assert bucket_info.stats.count == 030 assert h3.list_buckets() == ['b1']31 assert h3.delete_bucket('b1') == True32 with pytest.raises(pyh3lib.H3NotExistsError):33 h3.delete_bucket('b1')34 with pytest.raises(pyh3lib.H3NotExistsError):35 h3.info_bucket('b1')36 assert h3.list_buckets() == []37def test_arguments(h3):38 """Pass invalid arguments."""39 # Empty name40 with pytest.raises(pyh3lib.H3InvalidArgsError):41 h3.create_bucket('')42 with pytest.raises(TypeError):43 h3.create_bucket(None)44 # Large name45 with pytest.raises(pyh3lib.H3NameTooLongError):46 h3.create_bucket('a' * (h3.BUCKET_NAME_SIZE + 1))47 # Invalid name48 with pytest.raises(pyh3lib.H3InvalidArgsError):49 h3.create_bucket('/bucketId')50 h3.create_bucket('\bucketId')51 h3.delete_bucket('\bucketId')52def test_many(h3):53 """Manage many buckets."""54 count = 100 # More than 1055 assert h3.list_buckets() == []56 for i in range(count):57 assert h3.create_bucket('bucket%d' % i) == True58 for i in random.sample(range(count), 10):59 with pytest.raises(pyh3lib.H3ExistsError):60 h3.create_bucket('bucket%d' % i)61 for i in range(count):62 bucket_info = h3.info_bucket('bucket%d' % i)63 assert bucket_info.stats == None64 assert type(bucket_info.creation) == float65 assert h3.list_buckets() == [('bucket%d' % i) for i in range(count)]66 for i in range(count):67 assert h3.delete_bucket('bucket%d' % i) == True68 for i in random.sample(range(count), 10):69 with pytest.raises(pyh3lib.H3NotExistsError):70 h3.delete_bucket('bucket%d' % i)71 for i in random.sample(range(count), 10):72 with pytest.raises(pyh3lib.H3NotExistsError):73 h3.info_bucket('bucket%d' % i)74 assert h3.list_buckets() == []
example.py
Source:example.py
...13print oss_api.get_services()14# è·å object å表15print oss_api.list(BUCKET)16# å建 bucket17print oss_api.create_bucket(CREATE_BUCKET)18# 设置 bucket acl19print oss_api.update_bucket_acl(CREATE_BUCKET, {'x-amz-acl': "public-read"})20# æ¥è¯¢ bucket acl21oss_api.query_bucket_acl(CREATE_BUCKET)22# å é¤ bucket23print oss_api.delete_bucket(CREATE_BUCKET)24# 大æ件å段ä¸ä¼ ï¼å°è£
æ¥å£...
lab4_2a.py
Source:lab4_2a.py
...4"""5import boto36import logging 7from botocore.exceptions import ClientError8def create_bucket(bucket_name,region = None):9 try:10 if region is None:11 12 s3_client = boto3.client('s3')13 14 s3_client.create_bucket(Bucket=bucket_name)15 16 #s3.create_bucket(Bucket='mybucket')17 else:18 19 s3_client = boto3.client('s3',region_name = region)20 location = {'LocationConstraint':region}21 s3_client.create_bucket(Bucket=bucket_name,CreateBucketConfiguration = location)22 except ClientError as e : 23 print("ERROR")24 logging.error(e)25 return False 26 return True ...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!