Best Python code snippet using localstack_python
test_s3_object_lock_x.py
Source:test_s3_object_lock_x.py
...549 key = 'file1'550 client.put_object(Bucket=bucket_name, Body='abc', Key=key)551 legal_hold = {'Status': 'ON'}552 client.put_object_legal_hold(Bucket=bucket_name, Key=key, LegalHold=legal_hold)553 response = client.get_object_legal_hold(Bucket=bucket_name, Key=key)554 self.eq(response['LegalHold'], legal_hold)555 legal_hold_off = {'Status': 'OFF'}556 client.put_object_legal_hold(Bucket=bucket_name, Key=key, LegalHold=legal_hold_off)557 response = client.get_object_legal_hold(Bucket=bucket_name, Key=key)558 self.eq(response['LegalHold'], legal_hold_off)559 def test_object_lock_get_legal_hold_invalid_bucket(self, s3cfg_global_unique):560 """561 (operation='Test get legal hold with invalid bucket')562 (assertion='fails')563 """564 client = get_client(s3cfg_global_unique)565 bucket_name = self.get_new_bucket_name(s3cfg_global_unique)566 client.create_bucket(Bucket=bucket_name)567 key = 'file1'568 client.put_object(Bucket=bucket_name, Body='abc', Key=key)569 e = assert_raises(ClientError, client.get_object_legal_hold, Bucket=bucket_name, Key=key)570 status, error_code = self.get_status_and_error_code(e.response)571 self.eq(status, 400)...
c_aws_resources.py
Source:c_aws_resources.py
1import boto32session = boto3.Session()3print("Available AWS Resources:")4for resource in session.get_available_resources():5 print("\t", resource)6"""7Resources8 1. Services Resources - SQS, S3, EC2, ...9 2. Individual Resources - sqs.Queue, s3.Bucket, ...10"""11s3_reource = boto3.resource("s3")12print(vars(s3_reource)) # {'meta': ResourceMeta('s3', identifiers=[])}13print(dir(s3_reource))14[15 "Bucket",16 "BucketAcl",17 "BucketCors",18 "BucketLifecycle",19 "BucketLifecycleConfiguration",20 "BucketLogging",21 "BucketNotification",22 "BucketPolicy",23 "BucketRequestPayment",24 "BucketTagging",25 "BucketVersioning",26 "BucketWebsite",27 "MultipartUpload",28 "MultipartUploadPart",29 "Object",30 "ObjectAcl",31 "ObjectSummary",32 "ObjectVersion",33 "buckets",34 "create_bucket",35 "get_available_subresources",36 "meta",37]38s3_client = boto3.client("s3")39print(dir(s3_client))40[41 "_PY_TO_OP_NAME",42 "_client_config",43 "_convert_to_request_dict",44 "_emit_api_params",45 "_endpoint",46 "_exceptions",47 "_exceptions_factory",48 "_get_waiter_config",49 "_load_exceptions",50 "_loader",51 "_make_api_call",52 "_make_request",53 "_register_handlers",54 "_request_signer",55 "_response_parser",56 "_serializer",57 "_service_model",58 "abort_multipart_upload",59 "can_paginate",60 "complete_multipart_upload",61 "copy",62 "copy_object",63 "create_bucket",64 "create_multipart_upload",65 "delete_bucket",66 "delete_bucket_analytics_configuration",67 "delete_bucket_cors",68 "delete_bucket_encryption",69 "delete_bucket_intelligent_tiering_configuration",70 "delete_bucket_inventory_configuration",71 "delete_bucket_lifecycle",72 "delete_bucket_metrics_configuration",73 "delete_bucket_ownership_controls",74 "delete_bucket_policy",75 "delete_bucket_replication",76 "delete_bucket_tagging",77 "delete_bucket_website",78 "delete_object",79 "delete_object_tagging",80 "delete_objects",81 "delete_public_access_block",82 "download_file",83 "download_fileobj",84 "exceptions",85 "generate_presigned_post",86 "generate_presigned_url",87 "get_bucket_accelerate_configuration",88 "get_bucket_acl",89 "get_bucket_analytics_configuration",90 "get_bucket_cors",91 "get_bucket_encryption",92 "get_bucket_intelligent_tiering_configuration",93 "get_bucket_inventory_configuration",94 "get_bucket_lifecycle",95 "get_bucket_lifecycle_configuration",96 "get_bucket_location",97 "get_bucket_logging",98 "get_bucket_metrics_configuration",99 "get_bucket_notification",100 "get_bucket_notification_configuration",101 "get_bucket_ownership_controls",102 "get_bucket_policy",103 "get_bucket_policy_status",104 "get_bucket_replication",105 "get_bucket_request_payment",106 "get_bucket_tagging",107 "get_bucket_versioning",108 "get_bucket_website",109 "get_object",110 "get_object_acl",111 "get_object_legal_hold",112 "get_object_lock_configuration",113 "get_object_retention",114 "get_object_tagging",115 "get_object_torrent",116 "get_paginator",117 "get_public_access_block",118 "get_waiter",119 "head_bucket",120 "head_object",121 "list_bucket_analytics_configurations",122 "list_bucket_intelligent_tiering_configurations",123 "list_bucket_inventory_configurations",124 "list_bucket_metrics_configurations",125 "list_buckets",126 "list_multipart_uploads",127 "list_object_versions",128 "list_objects",129 "list_objects_v2",130 "list_parts",131 "meta",132 "put_bucket_accelerate_configuration",133 "put_bucket_acl",134 "put_bucket_analytics_configuration",135 "put_bucket_cors",136 "put_bucket_encryption",137 "put_bucket_intelligent_tiering_configuration",138 "put_bucket_inventory_configuration",139 "put_bucket_lifecycle",140 "put_bucket_lifecycle_configuration",141 "put_bucket_logging",142 "put_bucket_metrics_configuration",143 "put_bucket_notification",144 "put_bucket_notification_configuration",145 "put_bucket_ownership_controls",146 "put_bucket_policy",147 "put_bucket_replication",148 "put_bucket_request_payment",149 "put_bucket_tagging",150 "put_bucket_versioning",151 "put_bucket_website",152 "put_object",153 "put_object_acl",154 "put_object_legal_hold",155 "put_object_lock_configuration",156 "put_object_retention",157 "put_object_tagging",158 "put_public_access_block",159 "restore_object",160 "select_object_content",161 "upload_file",162 "upload_fileobj",163 "upload_part",164 "upload_part_copy",165 "waiter_names",166 "write_get_object_response",...
s3.py
Source:s3.py
...14 return response15def get_bucket_versioning(s3_client, bucket):16 response = s3_client.get_bucket_versioning(Bucket=bucket)17 return response18def get_object_legal_hold(s3_client, bucket, key, version_id=None):19 if version_id:20 response = s3_client.get_object_legal_hold(Bucket=bucket, Key=key, VersionId=version_id)21 else:22 response = s3_client.get_object_legal_hold(Bucket=bucket, Key=key)23 return response24def get_object_lock_configuration(s3_client, bucket):25 response = s3_client.get_object_lock_configuration(Bucket=bucket)26 return response27def get_object_retention(s3_client, bucket, key, version_id=None):28 if version_id:29 response = s3_client.get_object_retention(Bucket=bucket, Key=key, VersionId=version_id)30 else:31 response = s3_client.get_object_retention(Bucket=bucket, Key=key)32 return response33test_json_bytes = bytes(json.dumps({"test": "json"}).encode('UTF-8'))34def put_object(s3_client, bucket, key, object_bytes=test_json_bytes):35 response = s3_client.put_object(Body=object_bytes, Bucket=bucket, Key=key)36 return response...
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!!