Best Python code snippet using localstack_python
test_api_base.py
Source: test_api_base.py
...7class TestApiBase(OssTestCase):8 if OSS_CNAME:9 def test_cname_bucket(self):10 bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), OSS_CNAME, OSS_BUCKET, is_cname=True)11 bucket.get_bucket_acl()12 def test_cname_object(self):13 bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), OSS_CNAME, OSS_BUCKET, is_cname=True)14 bucket.put_object('hello.txt', 'hello world')15 def test_https(self):16 bucket_name = random_string(63)17 bucket = oss2.Bucket(oss2.AnonymousAuth(), OSS_ENDPOINT.replace('http://', 'https://'), bucket_name)18 self.assertRaises(oss2.exceptions.NoSuchBucket, bucket.get_object, 'hello.txt')19 # åªæ¯ä¸ºäºæµè¯ï¼è¯·ä¸è¦ç¨IP访é®OSSï¼é¤éä½ æ¯å¨VPCç¯å¢ä¸ã20 def test_ip(self):21 bucket_name = random_string(63)22 ip = socket.gethostbyname(OSS_ENDPOINT.replace('https://', '').replace('http://', ''))23 bucket = oss2.Bucket(oss2.AnonymousAuth(), ip, bucket_name)24 self.assertRaises(oss2.exceptions.NoSuchBucket, bucket.get_object, 'hello.txt')25 def test_invalid_bucket_name(self):26 bucket_name = random_string(64)27 self.assertRaises(oss2.exceptions.ClientError, oss2.Bucket, oss2.AnonymousAuth(), OSS_ENDPOINT, bucket_name)28 def test_whitespace(self):29 bucket = oss2.Bucket(oss2.Auth(OSS_ID, ' ' + OSS_SECRET + ' '), OSS_ENDPOINT, OSS_BUCKET)30 bucket.get_bucket_acl()31 bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), ' ' + OSS_ENDPOINT + ' ', OSS_BUCKET)32 bucket.get_bucket_acl()33 bucket = oss2.Bucket(oss2.Auth(OSS_ID, OSS_SECRET), OSS_ENDPOINT, ' ' + OSS_BUCKET + ' ')34 bucket.get_bucket_acl()35 if sys.version_info >= (3, 3):36 def test_user_agent(self):37 app = 'fantastic-tool'38 assert_found = False39 def do_request(session_self, req, timeout):40 if assert_found:41 self.assertTrue(req.headers['User-Agent'].find(app) >= 0)42 else:43 self.assertTrue(req.headers['User-Agent'].find(app) < 0)44 raise oss2.exceptions.ClientError('intentional')45 from unittest.mock import patch46 with patch.object(oss2.Session, 'do_request', side_effect=do_request, autospec=True):47 # ä¸å app_name48 assert_found = False...
s3_barrel.py
Source: s3_barrel.py
...33 items[region] = []34 response = client.list_buckets()35 items[region].extend(response['Buckets'])36 return items37 def get_bucket_acl(self):38 if self.cache.get('get_bucket_acl'):39 return self.cache['get_bucket_acl']40 items = {}41 for region, client in self.clients.items():42 items[region] = {}43 for bucket in self.tap('list_buckets')[region]:44 response = client.get_bucket_acl(45 Bucket=bucket['Name']46 )47 items[region][bucket['Name']] = response['Grants']48 return items49 def get_bucket_versioning(self):50 if self.cache.get('get_bucket_versioning'):51 return self.cache['get_bucket_versioning']52 items = {}53 for region, client in self.clients.items():54 items[region] = {}55 for bucket in self.tap('list_buckets')[region]:56 response = client.get_bucket_versioning(57 Bucket=bucket['Name']58 )...
get_bucket_acl.py
Source: get_bucket_acl.py
1import logging2import boto33from botocore.exceptions import ClientError4def get_bucket_acl(bucket_name):5 """Retrieve the access control list of an Amazon S3 bucket6 :param bucket_name: string7 :return: Dictionary defining the bucket's access control policy consisting8 of owner and grants. If error, return None.9 """10 # Retrieve the bucket ACL11 s3 = boto3.client('s3')12 try:13 response = s3.get_bucket_acl(Bucket=bucket_name)14 except ClientError as e:15 # AllAccessDisabled error == bucket not found16 logging.error(e)17 return None18 # Return both the Owner and Grants keys19 # The Owner and Grants settings together form the Access Control Policy.20 # The Grants alone form the Access Control List.21 return {'Owner': response['Owner'], 'Grants': response['Grants']}22def main():23 """Exercise get_bucket_acl()"""24 # Assign this value before running the program25 test_bucket_name = 'BUCKET_NAME'26 # Set up logging27 logging.basicConfig(level=logging.DEBUG,28 format='%(levelname)s: %(asctime)s: %(message)s')29 # Retrieve the current bucket ACL30 acl = get_bucket_acl(test_bucket_name)31 if acl is None:32 exit(-1)33 # Output the bucket ACL grantees and permissions34 for grantee in acl['Grants']:35 # The grantee type determines the grantee_identifier36 grantee_type = grantee['Grantee']['Type']37 if grantee_type == 'CanonicalUser':38 grantee_identifier = grantee['Grantee']['DisplayName']39 elif grantee_type == 'AmazonCustomerByEmail':40 grantee_identifier = grantee['Grantee']['EmailAddress']41 elif grantee_type == 'Group':42 grantee_identifier = grantee['Grantee']['URI']43 else:44 grantee_identifier = 'Unknown'...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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!!